src/java/isac/browserdialog/MethodDialog.java
changeset 3881 72f0be16d83b
parent 3605 679eecfd43c7
child 3908 c30ead91986a
equal deleted inserted replaced
3880:0b0dc38b1106 3881:72f0be16d83b
    37  * This class is responsible for the interactions to the MethodBrowser, to the
    37  * This class is responsible for the interactions to the MethodBrowser, to the
    38  * active WSDialog, and also to other BrowserDialogs.
    38  * active WSDialog, and also to other BrowserDialogs.
    39  */
    39  */
    40 public class MethodDialog extends BrowserDialog {
    40 public class MethodDialog extends BrowserDialog {
    41 
    41 
    42 	/**
    42     /**
    43 	 * For serialization, see corresponding API Documentation; value generated
    43      * For serialization, see corresponding API Documentation; value generated
    44 	 * by eclipse to avoid a warning
    44      * by eclipse to avoid a warning
    45 	 */
    45      */
    46 	private static final long serialVersionUID = 6479711601158544388L;
    46     private static final long serialVersionUID = 6479711601158544388L;
    47 
    47 
    48 	/** true if the <To Worksheet> button is visible * */
    48     /** true if the <To Worksheet> button is visible * */
    49 	private boolean to_worksheet_visible_;
    49     private boolean to_worksheet_visible_;
    50 
    50 
    51 	/** true if the <Context On> button is visible* */
    51     /** true if the <Context On> button is visible* */
    52 	//private boolean context_on_visible_;
    52     // private boolean context_on_visible_;
    53 	
    53     /**
    54 	/** true if the calc head of the active worksheet is open
    54      * true if the calc head of the active worksheet is open this flag is
    55 	 *  this flag is updated in updateState()
    55      * updated in updateState()
    56 	 */
    56      */
    57 	private boolean calc_head_open_;
    57     private boolean calc_head_open_;
    58 
    58 
    59 	/**
    59     /**
    60 	 * The constructor of this class which is given the session the
    60      * The constructor of this class which is given the session the MethodDialog
    61 	 * MethodDialog is instanciated for. We need the session to get the correct
    61      * is instanciated for. We need the session to get the correct
    62 	 * WSDialogManager (and also the active WSDialog) for this BrowserDialog.
    62      * WSDialogManager (and also the active WSDialog) for this BrowserDialog.
    63 	 * 
    63      * 
    64 	 * @param session
    64      * @param session
    65 	 * @throws RemoteException
    65      * @throws RemoteException
    66 	 */
    66      */
    67 	public MethodDialog(Session session) throws RemoteException {
    67     public MethodDialog(Session session) throws RemoteException {
    68 		super(session);
    68         super(session);
    69 		context_type_ = ContextType.CONTEXT_METHODS;
    69         context_type_ = ContextType.CONTEXT_METHODS;
    70 		
    70 
    71 		hierarchy_ = loadHierarchy(context_type_);
    71         hierarchy_ = loadHierarchy(context_type_);
    72 		//System.out.println("Method hierarchy:");
    72         // System.out.println("Method hierarchy:");
    73 		//System.out.println(hierarchy_.toString());
    73         // System.out.println(hierarchy_.toString());
    74 		current_context_ = new ContextUnknown();
    74         current_context_ = new ContextUnknown();
    75 	}
    75     }
    76 
    76 
    77 	/**
    77     /**
    78 	 * Notify the MethodDialog about events or requests triggered by the user.
    78      * Notify the MethodDialog about events or requests triggered by the user.
    79 	 * The MethodBrowser calls this method over RMI.
    79      * The MethodBrowser calls this method over RMI.
    80 	 * 
    80      * 
    81 	 * @param action
    81      * @param action
    82 	 *            What's new from the UI
    82      *            What's new from the UI
    83 	 * @return true, if the event is being processed, false if processing is
    83      * @return true, if the event is being processed, false if processing is
    84 	 *         denied or impossible
    84      *         denied or impossible
    85 	 * @throws RemoteException
    85      * @throws RemoteException
    86 	 * @throws DialogProtocolException
    86      * @throws DialogProtocolException
    87 	 */
    87      */
    88 	public boolean notifyUserAction(IUserAction action)
    88     public boolean notifyUserAction(IUserAction action)
    89 			throws DialogProtocolException, RemoteException {
    89             throws DialogProtocolException, RemoteException {
    90 		System.out.println("MethodDialog::notifyUserAction() action="
    90         System.out.println("MethodDialog::notifyUserAction() action="
    91 				+ action.getActionID());
    91                 + action.getActionID());
    92 		
    92 
    93 		if( super.notifyUserAction( action ) )
    93         if (super.notifyUserAction(action))
    94 			return true;
    94             return true;
    95 		
    95 
    96 		switch (action.getActionID()) {
    96         user_logger_.logUserAction("met", action);
    97 		case UI_BROWSER_MATCH_ON: {
    97 
    98 			context_on_ = true;
    98         switch (action.getActionID()) {
    99 			drawButtons();
    99         case UI_BROWSER_MATCH_ON: {
   100 			sendInitContextToBrowser();
   100             context_on_ = true;
   101 			return true;
   101             drawButtons();
   102 		}
   102             sendInitContextToBrowser();
   103 		case UI_BROWSER_MATCH_OFF: {
   103             return true;
   104 			context_on_ = false;
   104         }
   105 			drawButtons();
   105         case UI_BROWSER_MATCH_OFF: {
   106 			ContextUnknown new_context= new ContextUnknown();
   106             context_on_ = false;
   107 			new_context.setHierarchyKey(current_context_.getHierarchyKey());
   107             drawButtons();
   108 			new_context.setKEStoreKey(current_context_.getKEStoreKey());
   108             ContextUnknown new_context = new ContextUnknown();
   109 			sendContextToBrowser(new_context);
   109             new_context.setHierarchyKey(current_context_.getHierarchyKey());
   110 			sendLinkToMiniBrowser(new_context,context_type_);
   110             new_context.setKEStoreKey(current_context_.getKEStoreKey());
   111 			return true;
   111             sendContextToBrowser(new_context);
   112 		}
   112             sendLinkToMiniBrowser(new_context, context_type_);
   113 		case UI_BROWSER_TO_WORKSHEET: {
   113             return true;
   114 			setCurrentContextToWorksheet();
   114         }
   115 			return true;
   115         case UI_BROWSER_TO_WORKSHEET: {
   116 		}
   116             setCurrentContextToWorksheet();
   117 		case UI_MINIBROWSER_LINK: {
   117             return true;
   118 			URL receivedLink = ((UserActionOnLink) action).getLink();
   118         }
   119 			try {
   119         case UI_MINIBROWSER_LINK: {
   120 				interpretLink(receivedLink);
   120             URL receivedLink = ((UserActionOnLink) action).getLink();
   121 				return true;
   121             try {
   122 			} catch (RemoteException e) {
   122                 interpretLink(receivedLink);
   123 				e.printStackTrace();
   123                 return true;
   124 				return false;
   124             } catch (RemoteException e) {
   125 			}
   125                 e.printStackTrace();
   126 		}
   126                 return false;
   127 		}
   127             }
   128 		return false;
   128         }
   129 	}
   129         }
   130 
   130         return false;
   131 	/**
   131     }
   132 	 * removes the button for To Worksheet. If the button does not
   132 
   133 	 * exist so far, nothing happens.
   133     /**
   134 	 */
   134      * removes the button for To Worksheet. If the button does not exist so far,
   135 	private void removeButtonToWorksheet() {
   135      * nothing happens.
   136 		if (!to_worksheet_visible_)
   136      */
   137 			return;
   137     private void removeButtonToWorksheet() {
   138 		try {
   138         if (!to_worksheet_visible_)
   139 			browser_frame_rmi_.removeUIElement(new UIAction(
   139             return;
   140 					EUIElement.UI_BROWSER_TO_WORKSHEET,
   140         try {
   141 					EUIContext.UI_CONTEXT_BROWSER, user_language_));
   141             browser_frame_rmi_.removeUIElement(new UIAction(
   142 		} catch (RemoteException e) {
   142                     EUIElement.UI_BROWSER_TO_WORKSHEET,
   143 			e.printStackTrace();
   143                     EUIContext.UI_CONTEXT_BROWSER, user_language_));
   144 		}
   144         } catch (RemoteException e) {
   145 		to_worksheet_visible_ = false;
   145             e.printStackTrace();
   146 	}
   146         }
   147 
   147         to_worksheet_visible_ = false;
   148 	/**
   148     }
   149 	 * generates the button for To Worksheet. If the button does 
   149 
   150 	 * already exist, nothing happens.
   150     /**
   151 	 */
   151      * generates the button for To Worksheet. If the button does already exist,
   152 	private void drawButtonToWorksheet() {
   152      * nothing happens.
   153 		if (to_worksheet_visible_)
   153      */
   154 			return;
   154     private void drawButtonToWorksheet() {
   155 		try {
   155         if (to_worksheet_visible_)
   156 			browser_frame_rmi_.addUIElement(new UIAction(
   156             return;
   157 					EUIElement.UI_BROWSER_TO_WORKSHEET,
   157         try {
   158 					EUIContext.UI_CONTEXT_BROWSER, user_language_));
   158             browser_frame_rmi_.addUIElement(new UIAction(
   159 		} catch (RemoteException e) {
   159                     EUIElement.UI_BROWSER_TO_WORKSHEET,
   160 			e.printStackTrace();
   160                     EUIContext.UI_CONTEXT_BROWSER, user_language_));
   161 		}
   161         } catch (RemoteException e) {
   162 		to_worksheet_visible_ = true;
   162             e.printStackTrace();
   163 	}
   163         }
   164 
   164         to_worksheet_visible_ = true;
   165 	/**
   165     }
   166 	 * This method overrides the method in the base class and
   166 
   167 	 * calls the method of the base class. This is done, as some
   167     /**
   168 	 * additional initialisations have to be done with the buttons
   168      * This method overrides the method in the base class and calls the method
   169 	 * and the context.
   169      * of the base class. This is done, as some additional initialisations have
   170 	 * 
   170      * to be done with the buttons and the context.
   171 	 * @param browser_frame
   171      * 
   172 	 *            the browser frame to register
   172      * @param browser_frame
   173 	 */
   173      *            the browser frame to register
   174 	public void registerBrowserFrame(IToGUI browser_frame)
   174      */
   175 			throws RemoteException {
   175     public void registerBrowserFrame(IToGUI browser_frame)
   176 		super.registerBrowserFrame(browser_frame);
   176             throws RemoteException {
   177 		initButtons();
   177         super.registerBrowserFrame(browser_frame);
   178 	}
   178         initButtons();
   179 	
   179     }
   180 	private void initButtons() {
   180 
   181 		context_on_visible_ = false;
   181     private void initButtons() {
   182 		to_worksheet_visible_ = false;
   182         context_on_visible_ = false;
   183 		context_on_ = true;
   183         to_worksheet_visible_ = false;
   184 		try {
   184         context_on_ = true;
   185 			browser_frame_rmi_.addUIElement(new UIAction(
   185         try {
   186 					EUIElement.UI_BROWSER_MATCH_OFF,
   186             browser_frame_rmi_.addUIElement(new UIAction(
   187 					EUIContext.UI_CONTEXT_BROWSER, user_language_));
   187                     EUIElement.UI_BROWSER_MATCH_OFF,
   188 		} catch (RemoteException e) {
   188                     EUIContext.UI_CONTEXT_BROWSER, user_language_));
   189 			e.printStackTrace();
   189         } catch (RemoteException e) {
   190 		}
   190             e.printStackTrace();
   191 	}
   191         }
   192 
   192     }
   193 	/**
   193 
   194 	 * This method draws the buttons of the browser. Which buttons need
   194     /**
   195 	 * to be shown depends on three flags:
   195      * This method draws the buttons of the browser. Which buttons need to be
   196 	 * context_on_   calc_head_open_  | Buttons to show:
   196      * shown depends on three flags: context_on_ calc_head_open_ | Buttons to
   197 	 * -----------------------------------------------------------------
   197      * show: ----------------------------------------------------------------- F
   198 	 *    F               X          | <Context Off>		
   198      * X | <Context Off> T F | <Context On> T T | <Context On> <ToWorksheet>
   199 	 *    T               F          | <Context On>	
   199      * 
   200 	 *    T               T          | <Context On> <ToWorksheet>			  
   200      */
   201 	 *    
   201 
   202 	 */
   202     protected void drawButtons() {
   203 
   203         if (!context_on_) {
   204 	protected void drawButtons() {
   204             drawButtonContextOn();
   205 		if (!context_on_) {
   205             removeButtonToWorksheet();
   206 			drawButtonContextOn();
   206         } else {
   207 			removeButtonToWorksheet();
   207             if (!calc_head_open_) {
   208 		} else {
   208                 drawButtonContextOff();
   209 			if (!calc_head_open_) {
   209                 removeButtonToWorksheet();
   210 				drawButtonContextOff();
   210             } else {
   211 				removeButtonToWorksheet();
   211                 drawButtonContextOff();
   212 			}
   212                 drawButtonToWorksheet();
   213 			else  {
   213             }
   214 				drawButtonContextOff();
   214         }
   215 				drawButtonToWorksheet();
   215     }
   216 			}
   216 
   217 		}
   217     /**
   218 	}
   218      * This method does the update for the two variables: worksheet_open_ and
   219 	/**
   219      * calc_head_open_. An interface to the active worksheet is fetched from the
   220 	 * This method does the update for the two variables:
   220      * session. If no active worksheet exists (and null is returned) there is no
   221 	 * worksheet_open_ and calc_head_open_. An interface to the
   221      * open worksheet. The interface returns a WorksheetState which is able to
   222 	 * active worksheet is fetched from the session. If no active
   222      * tell us, if the CalcHead is open.
   223 	 * worksheet exists (and null is returned) there is no open
   223      */
   224 	 * worksheet. The interface returns a WorksheetState which is
   224     public void updateState() {
   225 	 * able to tell us, if the CalcHead is open.
   225         try {
   226 	 */
   226             IContextProvider context_provider = session_.getContextProvider();
   227 	public void updateState() {
   227             if (context_provider == null) {
   228 		 try {
   228                 calc_head_open_ = false;
   229 		 IContextProvider context_provider = session_.getContextProvider();
   229                 return;
   230 		 if(context_provider == null) {
   230             }
   231 		 calc_head_open_ = false;
   231             WorksheetState state = context_provider.getWorksheetState();
   232 		 return;
   232             calc_head_open_ = state.isCalcHeadOpen();
   233 		 }
   233         } catch (RemoteException e) {
   234 		 WorksheetState state = context_provider.getWorksheetState();
   234             e.printStackTrace();
   235 		 calc_head_open_ = state.isCalcHeadOpen();
   235         }
   236 		 }catch(RemoteException e) {
   236     }
   237 		 e.printStackTrace();
       
   238 		 }
       
   239 	}
       
   240 }
   237 }