gkompach@3311
|
1 |
/*
|
gkompach@3311
|
2 |
* @author Georg Kompacher, member of the ISAC-team,
|
gkompach@3311
|
3 |
* Copyright (c) 2006 by Georg Kompacher
|
gkompach@3311
|
4 |
* created Jul 10, 2006 04:18:01 PM
|
gkompach@3311
|
5 |
* Institute for Softwaretechnology, Graz University of Technology, Austria.
|
gkompach@3311
|
6 |
*
|
gkompach@3311
|
7 |
* Use is subject to PGPL license terms.
|
gkompach@3311
|
8 |
*/
|
gkompach@3311
|
9 |
package isac.browserdialog;
|
gkompach@3311
|
10 |
|
rkoenig@3438
|
11 |
import isac.gui.util.HierarchyNode;
|
rkoenig@3438
|
12 |
import isac.interfaces.IToGUI;
|
gkompach@3312
|
13 |
import isac.session.Session;
|
gkompach@3375
|
14 |
import isac.useractions.EUIContext;
|
gkompach@3375
|
15 |
import isac.useractions.EUIElement;
|
gkompach@3311
|
16 |
import isac.useractions.IUserAction;
|
gkompach@3375
|
17 |
import isac.useractions.UIAction;
|
rkoenig@3461
|
18 |
import isac.useractions.UserActionOnLink;
|
rkoenig@3438
|
19 |
import isac.useractions.UserActionOnMathContext;
|
rkoenig@3438
|
20 |
import isac.util.formulae.Context;
|
rkoenig@3459
|
21 |
import isac.util.formulae.ContextUnknown;
|
rkoenig@3438
|
22 |
import isac.util.formulae.HierarchyKey;
|
gkompach@3311
|
23 |
import isac.wsdialog.DialogProtocolException;
|
rkoenig@3459
|
24 |
import isac.wsdialog.IContextProvider;
|
rkoenig@3459
|
25 |
import isac.wsdialog.WorksheetState;
|
nsimic@3467
|
26 |
import isac.wsdialog.IContextProvider.ContextType;
|
gkompach@3311
|
27 |
|
rkoenig@3461
|
28 |
import java.net.URL;
|
gkompach@3311
|
29 |
import java.rmi.RemoteException;
|
rkoenig@3459
|
30 |
import java.util.Random;
|
gkompach@3311
|
31 |
|
rkoenig@3438
|
32 |
import javax.swing.tree.TreePath;
|
rkoenig@3438
|
33 |
|
gkompach@3321
|
34 |
/**
|
gkompach@3321
|
35 |
* @author Georg Kompacher
|
gkompach@3321
|
36 |
*
|
gkompach@3321
|
37 |
* This class is responsible for the interactions to the ProblemBrowser, to the
|
gkompach@3321
|
38 |
* active WSDialog, and also to other BrowserDialogs.
|
gkompach@3321
|
39 |
*/
|
gkompach@3311
|
40 |
public class ProblemDialog extends BrowserDialog {
|
gkompach@3311
|
41 |
|
wneuper@3881
|
42 |
/**
|
wneuper@3881
|
43 |
* For serialization, see corresponding API Documentation; value generated
|
wneuper@3881
|
44 |
* by eclipse to avoid a warning
|
wneuper@3881
|
45 |
*/
|
wneuper@3881
|
46 |
private static final long serialVersionUID = 6479711601158544388L;
|
gkompach@3311
|
47 |
|
wneuper@3881
|
48 |
/** true if the refine button is visible * */
|
wneuper@3881
|
49 |
private boolean refine_visible_;
|
rkoenig@3459
|
50 |
|
wneuper@3881
|
51 |
/** true if the to worksheet button is visible * */
|
wneuper@3881
|
52 |
private boolean to_worksheet_visible_;
|
rkoenig@3459
|
53 |
|
wneuper@3881
|
54 |
/** true if the Context On button is visible* */
|
wneuper@3881
|
55 |
// private boolean context_on_visible_;
|
wneuper@3881
|
56 |
/**
|
wneuper@3881
|
57 |
* true if a worksheet is open this flag is updated in updateState()
|
wneuper@3881
|
58 |
*/
|
wneuper@3881
|
59 |
private boolean worksheet_open_;
|
rkoenig@3459
|
60 |
|
wneuper@3881
|
61 |
/**
|
wneuper@3881
|
62 |
* true if the calc head of the active worksheet is open this flag is
|
wneuper@3881
|
63 |
* updated in updateState()
|
wneuper@3881
|
64 |
*/
|
wneuper@3881
|
65 |
private boolean calc_head_open_;
|
rkoenig@3459
|
66 |
|
wneuper@3881
|
67 |
/** true if the context updating is on * */
|
wneuper@3881
|
68 |
// private boolean context_on_;
|
wneuper@3881
|
69 |
/**
|
wneuper@3881
|
70 |
* The constructor of this class which is given the session the
|
wneuper@3881
|
71 |
* ProblemDialog is instanciated for. We need the session to get the correct
|
wneuper@3881
|
72 |
* WSDialogManager (and also the active WSDialog) for this BrowserDialog.
|
wneuper@3881
|
73 |
*
|
wneuper@3881
|
74 |
* @param session
|
wneuper@3881
|
75 |
* @throws RemoteException
|
wneuper@3881
|
76 |
*/
|
wneuper@3881
|
77 |
public ProblemDialog(Session session) throws RemoteException {
|
wneuper@3881
|
78 |
super(session);
|
wneuper@3881
|
79 |
context_type_ = ContextType.CONTEXT_PROBLEMS;
|
rkoenig@3459
|
80 |
|
wneuper@3881
|
81 |
hierarchy_ = loadHierarchy(context_type_);
|
wneuper@3881
|
82 |
current_context_ = new ContextUnknown();
|
wneuper@3881
|
83 |
}
|
gkompach@3311
|
84 |
|
wneuper@3881
|
85 |
/**
|
wneuper@3881
|
86 |
* Notify the ProblemDialog about events or requests triggered by the user.
|
wneuper@3881
|
87 |
* The ProblemBrowser calls this method over RMI.
|
wneuper@3881
|
88 |
*
|
wneuper@3881
|
89 |
* @param action
|
wneuper@3881
|
90 |
* What's new from the UI
|
wneuper@3881
|
91 |
* @return true, if the event is being processed, false if processing is
|
wneuper@3881
|
92 |
* denied or impossible
|
wneuper@3881
|
93 |
* @throws RemoteException
|
wneuper@3881
|
94 |
* @throws DialogProtocolException
|
wneuper@3881
|
95 |
*/
|
wneuper@3881
|
96 |
public boolean notifyUserAction(IUserAction action)
|
wneuper@3881
|
97 |
throws DialogProtocolException, RemoteException {
|
wneuper@3881
|
98 |
System.out.println("ProblemDialog::notifyUserAction() action="
|
wneuper@3881
|
99 |
+ action.getActionID());
|
rkoenig@3459
|
100 |
|
wneuper@3881
|
101 |
if (super.notifyUserAction(action))
|
wneuper@3881
|
102 |
return true;
|
rkoenig@3459
|
103 |
|
wneuper@3881
|
104 |
user_logger_.logUserAction("pbl", action);
|
rkoenig@3459
|
105 |
|
wneuper@3881
|
106 |
switch (action.getActionID()) {
|
wneuper@3881
|
107 |
case UI_BROWSER_MATCH_ON: {
|
wneuper@3881
|
108 |
context_on_ = true;
|
wneuper@3881
|
109 |
drawButtons();
|
wneuper@3881
|
110 |
sendInitContextToBrowser();
|
wneuper@3881
|
111 |
return true;
|
wneuper@3881
|
112 |
}
|
wneuper@3881
|
113 |
case UI_BROWSER_MATCH_OFF: {
|
wneuper@3881
|
114 |
context_on_ = false;
|
wneuper@3881
|
115 |
drawButtons();
|
wneuper@3881
|
116 |
ContextUnknown new_context = new ContextUnknown();
|
wneuper@3881
|
117 |
new_context.setHierarchyKey(current_context_.getHierarchyKey());
|
wneuper@3881
|
118 |
new_context.setKEStoreKey(current_context_.getKEStoreKey());
|
wneuper@3881
|
119 |
sendContextToBrowser(new_context);
|
wneuper@3908
|
120 |
sendLinkToMiniBrowser(new_context, context_type_, "");
|
wneuper@3881
|
121 |
return true;
|
wneuper@3881
|
122 |
}
|
wneuper@3881
|
123 |
case UI_PROBLEMBROWSER_REFINE: {
|
wneuper@3881
|
124 |
sendRefinedCurrentContext();
|
wneuper@3881
|
125 |
return true;
|
wneuper@3881
|
126 |
}
|
wneuper@3881
|
127 |
case UI_BROWSER_TO_WORKSHEET: {
|
wneuper@3881
|
128 |
setCurrentContextToWorksheet();
|
wneuper@3881
|
129 |
return true;
|
wneuper@3881
|
130 |
}
|
wneuper@3881
|
131 |
case UI_MINIBROWSER_LINK: {
|
wneuper@3881
|
132 |
URL receivedLink = ((UserActionOnLink) action).getLink();
|
wneuper@3881
|
133 |
try {
|
wneuper@3881
|
134 |
interpretLink(receivedLink);
|
wneuper@3881
|
135 |
return true;
|
wneuper@3881
|
136 |
} catch (RemoteException e) {
|
wneuper@3881
|
137 |
e.printStackTrace();
|
wneuper@3881
|
138 |
return false;
|
wneuper@3881
|
139 |
}
|
wneuper@3881
|
140 |
}
|
wneuper@3881
|
141 |
}
|
wneuper@3881
|
142 |
return false;
|
wneuper@3881
|
143 |
}
|
rkoenig@3459
|
144 |
|
wneuper@3881
|
145 |
/**
|
wneuper@3881
|
146 |
* removes the button for Refine. If the button does not exist so far,
|
wneuper@3881
|
147 |
* nothing happens.
|
wneuper@3881
|
148 |
*/
|
wneuper@3881
|
149 |
private void removeButtonRefine() {
|
wneuper@3881
|
150 |
if (!refine_visible_)
|
wneuper@3881
|
151 |
return;
|
wneuper@3881
|
152 |
try {
|
wneuper@3881
|
153 |
browser_frame_rmi_.removeUIElement(new UIAction(
|
wneuper@3881
|
154 |
EUIElement.UI_PROBLEMBROWSER_REFINE,
|
wneuper@3881
|
155 |
EUIContext.UI_CONTEXT_BROWSER, user_language_));
|
wneuper@3881
|
156 |
} catch (RemoteException e) {
|
wneuper@3881
|
157 |
e.printStackTrace();
|
wneuper@3881
|
158 |
}
|
wneuper@3881
|
159 |
refine_visible_ = false;
|
wneuper@3881
|
160 |
}
|
rkoenig@3459
|
161 |
|
wneuper@3881
|
162 |
/**
|
wneuper@3881
|
163 |
* creates the button for Refine. If the button does already exist, nothing
|
wneuper@3881
|
164 |
* happens.
|
wneuper@3881
|
165 |
*/
|
wneuper@3881
|
166 |
private void drawButtonRefine() {
|
wneuper@3881
|
167 |
if (refine_visible_)
|
wneuper@3881
|
168 |
return;
|
wneuper@3881
|
169 |
try {
|
wneuper@3881
|
170 |
browser_frame_rmi_.addUIElement(new UIAction(
|
wneuper@3881
|
171 |
EUIElement.UI_PROBLEMBROWSER_REFINE,
|
wneuper@3881
|
172 |
EUIContext.UI_CONTEXT_BROWSER, user_language_));
|
wneuper@3881
|
173 |
} catch (RemoteException e) {
|
wneuper@3881
|
174 |
e.printStackTrace();
|
wneuper@3881
|
175 |
}
|
wneuper@3881
|
176 |
refine_visible_ = true;
|
wneuper@3881
|
177 |
}
|
rkoenig@3459
|
178 |
|
wneuper@3881
|
179 |
/**
|
wneuper@3881
|
180 |
* removes the button for To Worksheet. If the button does not exist so far,
|
wneuper@3881
|
181 |
* nothing happens.
|
wneuper@3881
|
182 |
*/
|
wneuper@3881
|
183 |
private void removeButtonToWorksheet() {
|
wneuper@3881
|
184 |
if (!to_worksheet_visible_)
|
wneuper@3881
|
185 |
return;
|
wneuper@3881
|
186 |
try {
|
wneuper@3881
|
187 |
browser_frame_rmi_.removeUIElement(new UIAction(
|
wneuper@3881
|
188 |
EUIElement.UI_BROWSER_TO_WORKSHEET,
|
wneuper@3881
|
189 |
EUIContext.UI_CONTEXT_BROWSER, user_language_));
|
wneuper@3881
|
190 |
} catch (RemoteException e) {
|
wneuper@3881
|
191 |
e.printStackTrace();
|
wneuper@3881
|
192 |
}
|
wneuper@3881
|
193 |
to_worksheet_visible_ = false;
|
wneuper@3881
|
194 |
}
|
rkoenig@3459
|
195 |
|
wneuper@3881
|
196 |
/**
|
wneuper@3881
|
197 |
* generates the button for To Worksheet. If the button does already exist,
|
wneuper@3881
|
198 |
* nothing happens.
|
wneuper@3881
|
199 |
*/
|
wneuper@3881
|
200 |
private void drawButtonToWorksheet() {
|
wneuper@3881
|
201 |
if (to_worksheet_visible_)
|
wneuper@3881
|
202 |
return;
|
wneuper@3881
|
203 |
try {
|
wneuper@3881
|
204 |
browser_frame_rmi_.addUIElement(new UIAction(
|
wneuper@3881
|
205 |
EUIElement.UI_BROWSER_TO_WORKSHEET,
|
wneuper@3881
|
206 |
EUIContext.UI_CONTEXT_BROWSER, user_language_));
|
wneuper@3881
|
207 |
} catch (RemoteException e) {
|
wneuper@3881
|
208 |
e.printStackTrace();
|
wneuper@3881
|
209 |
}
|
wneuper@3881
|
210 |
to_worksheet_visible_ = true;
|
wneuper@3881
|
211 |
}
|
rkoenig@3459
|
212 |
|
wneuper@3881
|
213 |
/**
|
wneuper@3881
|
214 |
* This method overrides the method in the base class and calls the method
|
wneuper@3881
|
215 |
* of the base class. This is done, as some additional initialisations have
|
wneuper@3881
|
216 |
* to be done with the buttons and the context.
|
wneuper@3881
|
217 |
*
|
wneuper@3881
|
218 |
* @param browser_frame
|
wneuper@3881
|
219 |
* the browser frame to register
|
wneuper@3881
|
220 |
*/
|
wneuper@3881
|
221 |
public void registerBrowserFrame(IToGUI browser_frame)
|
wneuper@3881
|
222 |
throws RemoteException {
|
wneuper@3881
|
223 |
super.registerBrowserFrame(browser_frame);
|
wneuper@3881
|
224 |
initButtons();
|
wneuper@3881
|
225 |
}
|
rkoenig@3462
|
226 |
|
wneuper@3881
|
227 |
private void initButtons() {
|
wneuper@3881
|
228 |
context_on_visible_ = false;
|
wneuper@3881
|
229 |
to_worksheet_visible_ = false;
|
wneuper@3881
|
230 |
refine_visible_ = false;
|
wneuper@3881
|
231 |
context_on_ = true;
|
wneuper@3881
|
232 |
try {
|
wneuper@3881
|
233 |
browser_frame_rmi_.addUIElement(new UIAction(
|
wneuper@3881
|
234 |
EUIElement.UI_BROWSER_MATCH_OFF,
|
wneuper@3881
|
235 |
EUIContext.UI_CONTEXT_BROWSER, user_language_));
|
wneuper@3881
|
236 |
} catch (RemoteException e) {
|
wneuper@3881
|
237 |
e.printStackTrace();
|
wneuper@3881
|
238 |
}
|
wneuper@3881
|
239 |
}
|
rkoenig@3459
|
240 |
|
wneuper@3881
|
241 |
/**
|
wneuper@3881
|
242 |
* This method draws the buttons of the browser. Which buttons need to be
|
wneuper@3881
|
243 |
* shown depends on three flags: context_on_ worksheet_open_ calc_head_open_ |
|
wneuper@3881
|
244 |
* Buttons to show:
|
wneuper@3881
|
245 |
* ----------------------------------------------------------------- F X X |
|
wneuper@3881
|
246 |
* <Context On> T F F | <Context Off> T F T | impossible T T F | <Context
|
wneuper@3881
|
247 |
* Off> <Refine> T T T | <Context Off> <Refine> <ToWorksheet>
|
wneuper@3881
|
248 |
*
|
wneuper@3881
|
249 |
*/
|
rkoenig@3459
|
250 |
|
wneuper@3881
|
251 |
protected void drawButtons() {
|
wneuper@3881
|
252 |
if (!context_on_) {
|
wneuper@3881
|
253 |
drawButtonContextOn();
|
wneuper@3881
|
254 |
removeButtonRefine();
|
wneuper@3881
|
255 |
removeButtonToWorksheet();
|
wneuper@3881
|
256 |
} else {
|
wneuper@3881
|
257 |
if (!worksheet_open_ && !calc_head_open_) {
|
wneuper@3881
|
258 |
drawButtonContextOff();
|
wneuper@3881
|
259 |
removeButtonRefine();
|
wneuper@3881
|
260 |
removeButtonToWorksheet();
|
wneuper@3881
|
261 |
}
|
wneuper@3881
|
262 |
if (worksheet_open_ && !calc_head_open_) {
|
wneuper@3881
|
263 |
drawButtonContextOff();
|
wneuper@3881
|
264 |
drawButtonRefine();
|
wneuper@3881
|
265 |
removeButtonToWorksheet();
|
wneuper@3881
|
266 |
}
|
wneuper@3881
|
267 |
if (worksheet_open_ && calc_head_open_) {
|
wneuper@3881
|
268 |
drawButtonContextOff();
|
wneuper@3881
|
269 |
drawButtonRefine();
|
wneuper@3881
|
270 |
drawButtonToWorksheet();
|
wneuper@3881
|
271 |
}
|
wneuper@3881
|
272 |
}
|
wneuper@3881
|
273 |
}
|
rkoenig@3459
|
274 |
|
wneuper@3881
|
275 |
/**
|
wneuper@3881
|
276 |
* This method does the update for the two variables: worksheet_open_ and
|
wneuper@3881
|
277 |
* calc_head_open_. An interface to the active worksheet is fetched from the
|
wneuper@3881
|
278 |
* session. If no active worksheet exists (and null is returned) there is no
|
wneuper@3881
|
279 |
* open worksheet. The interface returns a WorksheetState which is able to
|
wneuper@3881
|
280 |
* tell us, if the CalcHead is open.
|
wneuper@3881
|
281 |
*/
|
wneuper@3881
|
282 |
public void updateState() {
|
rkoenig@3459
|
283 |
|
wneuper@3881
|
284 |
try {
|
wneuper@3881
|
285 |
IContextProvider context_provider = session_.getContextProvider();
|
wneuper@3881
|
286 |
if (context_provider == null) {
|
wneuper@3881
|
287 |
worksheet_open_ = false;
|
wneuper@3881
|
288 |
calc_head_open_ = false;
|
wneuper@3881
|
289 |
return;
|
wneuper@3881
|
290 |
}
|
wneuper@3881
|
291 |
worksheet_open_ = true;
|
wneuper@3881
|
292 |
WorksheetState state = context_provider.getWorksheetState();
|
wneuper@3881
|
293 |
calc_head_open_ = state.isCalcHeadOpen();
|
wneuper@3881
|
294 |
} catch (RemoteException e) {
|
wneuper@3881
|
295 |
e.printStackTrace();
|
wneuper@3881
|
296 |
}
|
wneuper@3881
|
297 |
}
|
rkoenig@3459
|
298 |
|
wneuper@3881
|
299 |
/**
|
wneuper@3881
|
300 |
* This method takes the current context and asks the active Worksheet to
|
wneuper@3881
|
301 |
* refine it. This is done over the IContextProvider interface. The active
|
wneuper@3881
|
302 |
* Worksheet returns a refined context, which is then shown in the browser.
|
wneuper@3881
|
303 |
* There must be a ContextProvider when this method is called. If there
|
wneuper@3881
|
304 |
* would not be any active worksheet, the button <Refine> would not be
|
wneuper@3881
|
305 |
* available.
|
wneuper@3881
|
306 |
*/
|
wneuper@3881
|
307 |
private void sendRefinedCurrentContext() {
|
wneuper@3881
|
308 |
// real implementation:
|
wneuper@3881
|
309 |
|
wneuper@3881
|
310 |
Context refined_context = current_context_;
|
wneuper@3881
|
311 |
try {
|
wneuper@3881
|
312 |
IContextProvider context_provider = session_.getContextProvider();
|
wneuper@3881
|
313 |
if (context_provider == null)
|
wneuper@3881
|
314 |
return;
|
wneuper@3881
|
315 |
refined_context = context_provider.refineContext(current_context_);
|
wneuper@3881
|
316 |
sendContextToBrowser(refined_context);
|
wneuper@3908
|
317 |
sendLinkToMiniBrowser(refined_context, context_type_, "");
|
wneuper@3881
|
318 |
} catch (RemoteException e) {
|
wneuper@3881
|
319 |
e.printStackTrace();
|
wneuper@3881
|
320 |
}
|
wneuper@3881
|
321 |
|
wneuper@3881
|
322 |
// dummy implementation for test purposes while initContext() is not
|
wneuper@3881
|
323 |
// implemented in WorksheetDialog:
|
wneuper@3881
|
324 |
/*
|
wneuper@3881
|
325 |
* HierarchyKey item_to_select = new HierarchyKey();
|
wneuper@3881
|
326 |
*
|
wneuper@3881
|
327 |
* item_to_select.addString("rat"); item_to_select.addString("sq");
|
wneuper@3881
|
328 |
* item_to_select.addString("root");
|
wneuper@3881
|
329 |
* item_to_select.addString("univariate");
|
wneuper@3881
|
330 |
* item_to_select.addString("equation");
|
wneuper@3881
|
331 |
*
|
wneuper@3881
|
332 |
* TreePath tree_path = hierarchy_.getPath(item_to_select.getID());
|
wneuper@3881
|
333 |
* HierarchyNode node_to_select = (HierarchyNode) tree_path
|
wneuper@3881
|
334 |
* .getLastPathComponent(); Random a = new Random(); Context context =
|
wneuper@3881
|
335 |
* null; int rand = a.nextInt(5); if (rand > 2) { context =
|
wneuper@3881
|
336 |
* current_context_; } else { context = new Context();
|
wneuper@3881
|
337 |
* context.setHierarchyKey(item_to_select);
|
wneuper@3881
|
338 |
* context.setHierarchyNode(node_to_select); }
|
wneuper@3881
|
339 |
* sendContextToBrowser(context);
|
wneuper@3881
|
340 |
* sendLinkToMiniBrowser(context,context_type_);
|
wneuper@3881
|
341 |
*/
|
wneuper@3881
|
342 |
// end Experimantation:
|
wneuper@3881
|
343 |
}
|
nsimic@3487
|
344 |
|
gkompach@3311
|
345 |
}
|