4 import isac.browserdialog.ExampleDialog;
5 import isac.browserdialog.IContextPresenter;
6 import isac.browserdialog.MethodDialog;
7 import isac.browserdialog.ProblemDialog;
8 import isac.browserdialog.TheoryDialog;
9 import isac.interfaces.*;
10 import isac.useractions.EUIContext;
11 import isac.useractions.EUIElement;
12 import isac.useractions.IUIAction;
13 import isac.useractions.IUserAction;
14 import isac.useractions.UIAction;
15 import isac.useractions.UIActionOnCalcElement;
16 import isac.useractions.UserActionOnCalcElement;
17 import isac.useractions.UserActionOnPosition;
18 import isac.users.IUserSettings;
19 import isac.users.UserLogger;
20 import isac.users.User;
21 import isac.users.UserLanguage;
22 import isac.users.UserSettings;
24 import isac.util.formulae.*;
25 import isac.util.tactics.*;
26 import isac.session.Session;
27 import isac.session.SessionManager;
28 import isac.session.ISessionManager;
29 import isac.users.UserManager;
31 import java.io.Serializable;
32 import java.net.MalformedURLException;
34 import java.rmi.registry.LocateRegistry;
35 import java.rmi.server.UnicastRemoteObject;
36 import java.util.Iterator;
37 import java.util.Vector;
39 import org.apache.log4j.Logger;
42 * The WorksheetDialog moderates the communication between two instances working
43 * on the same CalcTree object. One of these instances is the user, the other a
44 * math engine. Most probably, the user's GUI, the WorksheetDialog and the math
45 * engine reside on different machines and communicate with each other by means
48 * @author Alan Krempler 2003
49 * @author Manuel Koschuch 2005
51 public class WorksheetDialog extends UnicastRemoteObject implements
52 IWorksheetDialog, IToUser, Serializable, IContextProvider {
54 static final long serialVersionUID = 4952921581668118572L;
56 private static final Logger logger = Logger.getLogger(WorksheetDialog.class
59 protected MathEngine math_engine_;
61 protected CalcTree calc_tree_;
64 * The active formula in the mathematic engine
66 protected ICalcIterator active_formula_;
69 * Represents the formula on which the context depends. It is the last
70 * selected formula in the worksheet or the active formula from the
74 protected ICalcIterator context_formula_;
76 protected Session session_;
79 * determines if the calculation on the worksheet is ready
81 protected boolean worksheet_ready_;
86 * A calculation is finished successfully if a result (this is a specific
87 * position on the Worksheet) has been obtained. This variable is set once;
88 * i.e. trials on the calculation after the first result are <em>not</em>
91 private boolean calculation_finished_successfully_ = false;
93 private Vector<IToUser> datachange_listeners_;
95 private IToGUI ui_control_listener_;
97 protected String worksheet_id_;
99 protected UserSettings user_settings_;// hold whole hashmap locally
101 protected ISessionManager session_manager_;
103 protected UserLanguage user_language_;
105 protected UserLogger user_logger_;
109 * URL of the math engine to be used
111 * path(without URL) to UserSettings, UserModel
112 * @param session_dialog
114 * which create the WorksheetDialog and Worksheet
115 * @throws RemoteException
117 public WorksheetDialog(String ME_path, Session session,
118 String worksheet_id, Formalization f) throws RemoteException {
119 initialise(ME_path, session, worksheet_id, f);
122 public WorksheetDialog(String ME_path, Session session, String worksheet_id)
123 throws RemoteException {
124 initialise(ME_path, session, worksheet_id, new Formalization());
127 void initialise(String ME_path, Session session, String worksheet_id,
128 Formalization f) throws RemoteException {
130 datachange_listeners_ = new Vector<IToUser>();
132 MathEngine.init(ME_path);
133 math_engine_ = MathEngine.getMathEngine();
135 phase_ = DIALOGPHASE_IDLE;
141 user = UserManager.getInstance().getUser(session.getId());
143 user_settings_ = user.getUserSettings();
144 user_language_ = user.getLanguage();
146 worksheet_id_ = worksheet_id;
148 session_manager_ = SessionManager.getInstance();
150 user_logger_ = session_.getUserLogger();
155 public String getWorksheetID() {
156 return worksheet_id_;
159 public CalcTree getCalcTree() {
164 * start a calculation
166 public void getCalcTree(Formalization f) {
167 // do administrative stuff
168 calc_tree_ = math_engine_.getCalcTree(f);
169 calc_tree_.addDataChangeListener(this);
171 switch (user_settings_.getValue(IUserSettings.KEY1_START_SPECIFY)) {
172 case IUserSettings.VAL1_SKIP_SPECIFY_TO_START_SOLVE:
173 phase_ = DIALOGPHASE_SOLVE;
175 case IUserSettings.VAL1_POP_CALCHEAD_WITH_DESCRIPTIONS:
176 phase_ = DIALOGPHASE_SPECIFY;
184 * enter the specifying-phase; 2 cases: (1) at the beginning of a
185 * calculation as well as of a subproblem; sets the Descriptions in the
186 * Model (to support user-input) and in CAS-commands completes the Model.
187 * (2) for inspection of a "correct" CalcHead somewhere above the
188 * activeFormula; in this case the CalcHead is not updated, it is just the
189 * starting point into the math-knowledge.
191 * @return CalcHead eg. for providing CalcHead#VIEWSTYLE_*
193 * @see isac.wsdialog.IWorksheetDialog#startSpecifying()
195 private void startSpecifying(CalcHead calc_head) {
196 phase_ = DIALOGPHASE_SPECIFY;
198 // remove solving buttons
199 removeNextAndAutoButtonForWorksheet();
200 if (calc_head.getStatusString().equals("incorrect")) {
202 // -----------------------------------------------------------
203 // if you think, modelProblem should only set the descriptions
204 // in the Model (and NOT complete it for CAS-commands)
205 // search the sml-code for WN060225-modelProblem
206 calc_head = calc_tree_.modelProblem();
207 // -----------------------------------------------------------
208 doUIAction(new UIActionOnCalcElement(
209 EUIElement.UI_SPECIFY_OPEN_CALCHEAD,
210 EUIContext.UI_CONTEXT_SWITCH_PHASES, user_language_,
212 addCalcHeadPanelButtons();
213 addNextAndAutoButtonsForCalchead();
217 doUIAction(new UIActionOnCalcElement(
218 EUIElement.UI_SPECIFY_OPEN_CALCHEAD,
219 EUIContext.UI_CONTEXT_SWITCH_PHASES, user_language_,
221 ui_control_listener_.addUIElement(new UIAction(
222 EUIElement.UI_SPECIFY_CLOSE_CALCHEAD,
223 EUIContext.UI_CONTEXT_CALCHEAD, user_language_));
224 addNextAndAutoButtonForWorksheet();
227 } catch (RemoteException e) {
234 * @see isac.wsdialog.IWorksheetDialog#startCalculate()
236 public void startCalculate() {
237 calc_tree_.startCalculate();
241 * dismiss the CalcHeadPanel and start WorksheetDialog#DIALOGPHASE_SOLVE
243 * @see isac.interfaces.IToCalc#startSolving()
245 private void startSolving() {
247 removeCalcHeadPanelButtons();
248 removeNextAndAutoButtonsForCalchead();
249 addNextAndAutoButtonForWorksheet();
251 } catch (RemoteException e) {
254 phase_ = DIALOGPHASE_SOLVE;
257 private void buildUIElementsContextCalcElements() {
259 // ui_control_listener_.addUIElement(new UIAction(
260 // UI_SOLVE_GET_APPLICABLE_TACTICS,
261 // EUIContext.UI_CONTEXT_CALCELEMENTS));
262 ui_control_listener_.addUIElement(new UIAction(
263 EUIElement.UI_SOLVE_SHOW_ASSUMPTIONS,
264 EUIContext.UI_CONTEXT_CALCELEMENTS, user_language_));
265 ui_control_listener_.addUIElement(new UIAction(
266 EUIElement.UI_SOLVE_TACTIC_APPLIED,
267 EUIContext.UI_CONTEXT_CALCELEMENTS, user_language_));
268 ui_control_listener_.addUIElement(new UIAction(
269 EUIElement.UI_SOLVE_SHOW_INTERMEDIATE_STEPS,
270 EUIContext.UI_CONTEXT_CALCELEMENTS, user_language_));
271 } catch (RemoteException e) {
276 private void addNextAndAutoButtonForWorksheet() throws RemoteException {
278 ui_control_listener_.addUIElement(new UIAction(
279 EUIElement.UI_SOLVE_CALCULATE_1,
280 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
282 ui_control_listener_.addUIElement(new UIAction(
283 EUIElement.UI_SOLVE_CALCULATE_ALL,
284 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
287 private void removeNextAndAutoButtonForWorksheet() throws RemoteException {
289 ui_control_listener_.removeUIElement(new UIAction(
290 EUIElement.UI_SOLVE_CALCULATE_1,
291 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
293 ui_control_listener_.removeUIElement(new UIAction(
294 EUIElement.UI_SOLVE_CALCULATE_ALL,
295 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
299 private void addCalcHeadPanelButtons() throws RemoteException {
301 ui_control_listener_.addUIElement(new UIAction(
302 EUIElement.UI_SPECIFY_COMPLETE_CALCHEAD,
303 EUIContext.UI_CONTEXT_CALCHEAD, user_language_));
305 // ui_control_listener_.addUIElement(new UIAction(
306 // UI_SPECIFY_CHECK_CALCHEAD, EUIContext.UI_CONTEXT_CALCHEAD));
308 ui_control_listener_.addUIElement(new UIAction(
309 EUIElement.UI_SPECIFY_RESET, EUIContext.UI_CONTEXT_CALCHEAD,
311 // Button Start Solving
312 ui_control_listener_.addUIElement(new UIAction(
313 EUIElement.UI_SPECIFY_TO_SOLVE, EUIContext.UI_CONTEXT_CALCHEAD,
318 private void removeCalcHeadPanelButtons() throws RemoteException {
320 ui_control_listener_.removeUIElement(new UIAction(
321 EUIElement.UI_SPECIFY_COMPLETE_CALCHEAD,
322 EUIContext.UI_CONTEXT_CALCHEAD, user_language_));
323 // Button Start Solving
324 ui_control_listener_.removeUIElement(new UIAction(
325 EUIElement.UI_SPECIFY_TO_SOLVE, EUIContext.UI_CONTEXT_CALCHEAD,
328 // ui_control_listener_.removeUIElement(new UIAction(
329 // UI_SPECIFY_CHECK_CALCHEAD, EUIContext.UI_CONTEXT_CALCHEAD));
331 ui_control_listener_.removeUIElement(new UIAction(
332 EUIElement.UI_SPECIFY_RESET, EUIContext.UI_CONTEXT_CALCHEAD,
337 * add next and auto Button to WindowApplication
339 // Context Calculation is used instead of context calchead,
340 // because buttons have to be added to windowapplication and not to
342 private void addNextAndAutoButtonsForCalchead() {
345 ui_control_listener_.addUIElement(new UIAction(
346 EUIElement.UI_SPECIFY_COMPLETE_STEPWISE,
347 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
349 ui_control_listener_.addUIElement(new UIAction(
350 EUIElement.UI_SPECIFY_CALCULATE_ALL,
351 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
352 } catch (RemoteException e) {
360 private void removeNextAndAutoButtonsForCalchead() {
362 // Context Calculation is used instead of context calchead,
363 // because buttons have to be added to windowapplication and not to
367 ui_control_listener_.removeUIElement(new UIAction(
368 EUIElement.UI_SPECIFY_COMPLETE_STEPWISE,
369 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
371 ui_control_listener_.removeUIElement(new UIAction(
372 EUIElement.UI_SPECIFY_CALCULATE_ALL,
373 EUIContext.UI_CONTEXT_CALCULATION, user_language_));
374 } catch (RemoteException e) {
380 * accept the response of the bridge on an operation on a calculation; this
381 * can be a <code>CalcChanged</code>-information or a
382 * <code>CalcMessage</code>; pass them to the Worksheet (on different
383 * ways: the <code>CalcMessage</code> is passed as a <code>UIAction</code>
386 * @see isac.wsdialog.IToUser#calcResponse(isac.wsdialog.CalcChanged)
388 public void calcResponse(CalcEvent event) throws RemoteException {
389 if (event instanceof CalcChanged) {
390 CalcChanged ccevent = (CalcChanged) event;
391 worksheet_ready_ = false;
392 if (logger.isInfoEnabled())
393 logger.info(" WS<-. . : calcChanged (unc="
394 + ccevent.getLastUnchangedFormula().toSMLString()
396 + ccevent.getLastDeletedFormula().toSMLString()
398 + ccevent.getLastGeneratedFormula().toSMLString());
400 for (int i = 0; i < datachange_listeners_.size(); i++) {
401 CalcChanged wrappedEvent = new CalcChanged(event
402 .getTransactionId(), ccevent.isCompleted(),
403 new DialogIterator((CalcIterator) ccevent
404 .getLastUnchangedFormula(), this),
405 new DialogIterator((CalcIterator) ccevent
406 .getLastDeletedFormula(), this),
407 new DialogIterator((CalcIterator) ccevent
408 .getLastGeneratedFormula(), this));
409 ((IToUser) datachange_listeners_.elementAt(i))
410 .calcResponse(wrappedEvent);
412 } catch (Exception e) {
415 addUIElementsContextOneElement(ccevent);
417 active_formula_ = ccevent.getLastGeneratedFormula();
418 if (!ccevent.getLastGeneratedFormula().onCalcHead()
419 // ..a calculation cannot finish with a CalcHead
420 && !calculation_finished_successfully_)
421 // ..calculation_finished_successfully_ = true: only once
422 calculation_finished_successfully_ = ((CalcFormula) (active_formula_
423 .getElement())).getPosition().onEndOfCalculation();
425 context_formula_ = (ICalcIterator) ccevent
426 .getLastGeneratedFormula().cloneIterator();
428 user_logger_.logCalcChanged(worksheet_id_, ccevent);
430 updateContextFormulaOnWorksheet(context_formula_);
432 notifyContextPresenter();
434 if (active_formula_.onCalcHead()) {
435 switch (user_settings_.getValue("KEY1_START_SPECIFY")) {
436 case IUserSettings.VAL1_SKIP_SPECIFY_TO_START_SOLVE:
439 // calc_tree_.autoCalculate(IToCalc.SCOPE_CALCULATION,
441 // ...NEW Model_Problem (inserting Descriptions into the
443 // without causing CalcChanged (would loop in
447 case IUserSettings.VAL1_POP_CALCHEAD_WITH_DESCRIPTIONS:
448 startSpecifying((CalcHead) active_formula_.getElement());
453 "WorksheetDialog#calcChanged:switch"
454 + " (user_settings_.getValue(KEY1_START_SPECIFY)");
455 } catch (Exception e1) {
456 e1.printStackTrace();
460 } else {// CalcMessage
461 // TODO.WN0710 pass on to gui via UIAction
462 user_logger_.logCalcMessage(worksheet_id_, active_formula_
463 .toSMLString(), ((CalcMessage) event).getText());
468 * construct the context-menu on one specific calcelement (e.g. with
469 * 'Calchead' and without)
472 private void addUIElementsContextOneElement(CalcChanged event) {
473 ICalcIterator from = event.getLastUnchangedFormula();
474 ICalcIterator to = event.getLastGeneratedFormula();
476 Vector calc_formulae = null;
479 calc_formulae = from.getFormulaeFromTo(to, new Integer(0), false);
480 } catch (RemoteException e1) {
481 e1.printStackTrace();
484 if (calc_formulae == null)
487 Iterator vector_it = calc_formulae.iterator();
489 while (vector_it.hasNext()) {
490 CalcFormula cf = (CalcFormula) vector_it.next();
492 if (cf.getPosition().getKind().equals("Pbl")
493 || cf.getPosition().getKind().equals("Met")) {
495 ui_control_listener_.addUIElement(new UIAction(
496 EUIElement.UI_SOLVE_SHOW_CALCHEAD,
497 EUIContext.UI_CONTEXT_ONEELEMENT, cf.getPosition(),
499 } catch (RemoteException e) {
506 /***************************************************************************
507 * This method sends the applicable tactics to the specific item in the
508 * worksheet determined by the Position of the iterator
512 private void sendApplicableTacticsToWorksheet(ICalcIterator it) {
514 Vector tactics = it.getApplicableTactics(ICalcIterator.TACTICS_ALL);
516 if (tactics != null) {
517 for (int i = 0; i < tactics.size(); i++)
519 .addUIElement(new UIActionOnCalcElement(
520 EUIElement.UI_SOLVE_SET_NEXT_TACTIC,
521 EUIContext.UI_CONTEXT_APPLICABLE_TACTIC,
522 user_language_, it.getPosition(),
523 (Tactic) tactics.get(i)));
525 } catch (RemoteException e) {
530 private void updateContextFormulaOnWorksheet(ICalcIterator it) {
531 if (ui_control_listener_ != null)
533 ui_control_listener_.doUIAction(new UIAction(
534 EUIElement.UI_SOLVE_CHANGE_CONTEXT_FORMULA,
535 EUIContext.UI_CONTEXT_ONEELEMENT, it.getPosition(),
537 } catch (RemoteException e) {
543 * @see isac.wsdialog.IWorksheetDialog#iterator(CalcIterator,
545 * @see isac.interfaces.IToCalc#iterator()
547 public ICalcIterator iterator(CalcIterator it, IWorksheetDialog dg) {
549 return new DialogIterator(it, dg);
550 } catch (RemoteException e) {
557 * @see isac.wsdialog.IToCalc#addListener(isac.wsdialog.IToUser)
559 public boolean addDataChangeListener(IToUser listener)
560 throws RemoteException {
561 if (datachange_listeners_.contains(listener)) {
564 datachange_listeners_.add(listener);
569 public boolean registerUIControlListener(IToGUI listener)
570 throws RemoteException {
571 ui_control_listener_ = listener;
572 buildUIElementsContextCalcElements();
577 * Notify the Dialog Guide about interaction from the User DO NOT MODIFY THE
578 * SEQUENCE OF THE CASE BLOCKS IN THE SWITCH STATEMENTS!!
581 * @return true, if the action has been processed, false if the processing
582 * the action has been denied
583 * @throws RemoteException
586 public boolean notifyUserAction(IUserAction action)
587 throws DialogProtocolException, RemoteException {
588 EUIElement request = action.getActionID();
589 CalcHead calc_head = new CalcHead();
590 CalcHead ch_to_check = new CalcHead();
592 if (logger.isInfoEnabled())
593 logger.info(" WS->DG: notifyUserAction request= " + request);
594 System.out.println(" WS->DG: notifyUserAction request= " + request);
596 if (request == EUIElement.UI_CLOSE_WORKSHEET)
597 user_logger_.logCloseWorksheet(worksheet_id_,
598 calculation_finished_successfully_);
600 user_logger_.logUserAction("worksheet", action);
602 // / the requests that do not depend on the phase
604 case UI_CLOSE_WORKSHEET:
605 calc_tree_.destruct();
606 session_.getWSDialogManager().closeWSDialog(worksheet_id_);
607 if (session_.getWSDialogManager().numberOpenedWSDialoges() == 0)
608 removeNextAndAutoButtonForWorksheet();
609 IContextPresenter bdg = session_.getContextPresenter();
610 ContextUnknown context_unknown = new ContextUnknown();
611 bdg.presentContext(context_unknown);
613 case UI_ACTIVE_WORKSHEET:
614 session_.getWSDialogManager().setActiveWSDialog(worksheet_id_);
615 notifyContextPresenter();
620 case DIALOGPHASE_IDLE:
621 throw new DialogProtocolException(request, phase_);
622 case DIALOGPHASE_SPECIFY:
623 if (request.ordinal() < EUIElement.UI_DUMMY_FIRST_SPECIFY.ordinal()
624 || request.ordinal() > EUIElement.UI_DUMMY_LAST_SPECIFY
626 throw new DialogProtocolException(request, phase_);
628 case DIALOGPHASE_SOLVE:
629 if (request.ordinal() < EUIElement.UI_DUMMY_FIRST_SOLVE.ordinal()
630 || request.ordinal() > EUIElement.UI_DUMMY_LAST_SOLVE
632 throw new DialogProtocolException(request, phase_);
636 // *********** handle IUserAction's **********************
639 // in solve-phase request open a CalcHead by context-menu
640 case UI_SOLVE_SHOW_CALCHEAD:
641 calc_head = (CalcHead) context_formula_.getElement();
642 // calc_head = (CalcHead) ((UserActionOnIterator) action)
643 // .getPosition().getElement();
644 startSpecifying(calc_head);
645 // FIXXME RK 060712 here was:
646 // problem_browser_dialog_.setContext(worksheet_id_);
649 // Enter pressed after typing formula
650 case UI_SPECIFY_EDIT_ACTIVE_FORMULA_COMPLETE:
651 ch_to_check = (CalcHead) ((UserActionOnCalcElement) action)
653 calc_head = calc_tree_.checkCalcHead(ch_to_check);
654 doUIAction(new UIActionOnCalcElement(
655 EUIElement.UI_SPECIFY_CHECK_CALCHEAD,
656 EUIContext.UI_CONTEXT_CALCHEAD, user_language_, calc_head));
660 case UI_SPECIFY_COMPLETE_CALCHEAD:
661 if (!calc_head.isComplete()) {
662 calc_head = calc_tree_.completeCalcHead();
663 doUIAction(new UIActionOnCalcElement(
664 EUIElement.UI_SPECIFY_COMPLETE_CALCHEAD,
665 EUIContext.UI_CONTEXT_CALCHEAD, user_language_,
669 // Radiobutton for Method/Problem clicked
670 // case UI_SPECIFY_TOGGLE_METHOD_PROBLEM:
671 // System.out.println("toggle");
672 // // WN050830 use UI_SPECIFY_SWITCH_TO_GUARD and
673 // // UI_SPECIFY_SWITCH_TO_MODEL instead,
674 // // and use some of this code ...
675 // // ICalcIterator ci = calc_tree_.getActiveFormula();
676 // // ci.switchToGuard();
677 // // CalcHead ch = (CalcHead) ci.getElement();
679 // // TODO MK add code here to get new CalcHead with either Met or Pbl
682 // // ch_to_check = (CalcHead) ((UserActionOnCalcElement) action)
683 // // .getCalcElement();
684 // // calc_head = calc_tree_.checkCalcHead(ch_to_check);
686 // UIActionOnCalcElement(EUIElement.UI_SPECIFY_CHECK_CALCHEAD,
687 // // EUIContext.UI_CONTEXT_CALCHEAD, user_language_, user_language_,
691 case UI_SPECIFY_METHOD:
692 case UI_SPECIFY_THEORY:
693 case UI_SPECIFY_PROBLEM:
694 case UI_SPECIFY_COMPLETE_GIVEN:
695 case UI_SPECIFY_COMPLETE_FIND:
696 case UI_SPECIFY_COMPLETE_RELATE:
697 throw new DialogNotImplementedException(request, phase_);
700 case UI_SPECIFY_CHECK_CALCHEAD:
701 ch_to_check = (CalcHead) ((UserActionOnCalcElement) action)
703 calc_head = calc_tree_.checkCalcHead(ch_to_check);
704 doUIAction(new UIActionOnCalcElement(
705 EUIElement.UI_SPECIFY_CHECK_CALCHEAD,
706 EUIContext.UI_CONTEXT_CALCHEAD, user_language_, calc_head));
710 case UI_SPECIFY_COMPLETE_STEPWISE:
711 if (!calc_head.isComplete()) {
712 calc_head = calc_tree_.nextSpecify();
713 doUIAction(new UIActionOnCalcElement(
714 EUIElement.UI_SPECIFY_COMPLETE_STEPWISE,
715 EUIContext.UI_CONTEXT_CALCHEAD, user_language_,
721 case UI_SPECIFY_CLOSE_CALCHEAD:
722 // this action is enabled _ONLY_ if the Panel was opened read-only
723 // on a complete CalcHead just for inspection
724 doUIAction(new UIAction(EUIElement.UI_SPECIFY_CLOSE_CALCHEAD,
725 EUIContext.UI_CONTEXT_SWITCH_PHASES, user_language_));
726 phase_ = DIALOGPHASE_SOLVE;
727 // FIXXME RK 060712 here was:
728 // problem_browser_dialog_.setContext("");
732 case UI_SPECIFY_RESET:
733 calc_tree_.resetCalcHead();
734 calc_head = calc_tree_.modelProblem();
735 doUIAction(new UIActionOnCalcElement(EUIElement.UI_SPECIFY_RESET,
736 EUIContext.UI_CONTEXT_CALCHEAD, user_language_, calc_head));
739 // start solving pressed
740 case UI_SPECIFY_TO_SOLVE:
741 // FIXXME RK 060712 here was: problem_browser_dialog_.setContext("");
743 // ch_to_check = (CalcHead) ((UserActionOnCalcElement) action)
744 // .getCalcElement();
745 // calc_head = calc_tree_.checkCalcHead(ch_to_check);
746 // if (!calc_head.isComplete()) {
747 // calc_head = calc_tree_.completeCalcHead();
749 // UIActionOnCalcElement(EUIElement.UI_SPECIFY_CHECK_CALCHEAD,
750 // EUIContext.UI_CONTEXT_CALCHEAD, user_language_, user_language_,
756 case UI_SPECIFY_CALCULATE_ALL:
757 if (!calc_head.isComplete()) {
758 calc_head = calc_tree_.completeCalcHead();
759 if (!calc_head.isComplete()) {
760 calc_tree_.resetCalcHead();
761 calc_head = calc_tree_.completeCalcHead();
765 doUIAction(new UIActionOnCalcElement(
766 EUIElement.UI_SPECIFY_CALCULATE_ALL,
767 EUIContext.UI_CONTEXT_CALCHEAD, user_language_, calc_head));
768 doUIAction(new UIAction(EUIElement.UI_SPECIFY_CLOSE_CALCHEAD,
769 EUIContext.UI_CONTEXT_SWITCH_PHASES, user_language_));
772 // --------------solving phase------------------------------------
773 case UI_SOLVE_CALCULATE_1:
774 // handle the CalcHead such that its HeadLine can be
775 // presented like a CalcFormula
776 if (active_formula_.onCalcHead()) {
777 calc_tree_.completeCalcHead();
779 calc_tree_.startSolving();
780 } catch (AutoCalculateException e1) {
781 e1.printStackTrace();
784 calc_tree_.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
788 case UI_SOLVE_CALCULATE_ALL:
790 case UI_SPECIFY_CALCULATE_ALL:
791 case UI_SOLVE_CALCULATE_ALL:
792 calc_tree_.autoCalculate(IToCalc.SCOPE_CALCULATION, 0);
794 case UI_SPECIFY_TO_SOLVE:
799 case UI_SOLVE_CALCULATE_SUBPROBLEM:
800 calc_tree_.autoCalculate(IToCalc.SCOPE_SUBPROBLEM, 0);
803 case UI_SOLVE_EDIT_ACTIVE_FORMULA:
804 ui_control_listener_.doUIAction(new UIAction(
805 EUIElement.UI_DO_EDIT_FORMULA,
806 EUIContext.UI_CONTEXT_ONEELEMENT, user_language_));
809 case UI_SOLVE_EDIT_ACTIVE_FORMULA_COMPLETE:
810 System.out.println("**********XXX****************");
811 CalcFormula formula = (CalcFormula) ((UserActionOnCalcElement) action)
813 // if the position is null, the formula did not exist, so we try to
814 // append a new formula
815 if (formula.getPosition() == null) {
816 calc_tree_.appendFormula(formula);
818 active_formula_ = new CalcIterator(calc_tree_, formula
820 calc_tree_.replaceFormula(formula);
824 case UI_SOLVE_APPEND_USER_FORMULA:
825 ui_control_listener_.doUIAction(new UIAction(
826 EUIElement.UI_DO_APPEND_FORMULA,
827 EUIContext.UI_CONTEXT_ONEELEMENT, user_language_));
830 case UI_SOLVE_MOVE_ACTIVE_FORMULA: {
831 UserActionOnPosition uaop = (UserActionOnPosition) action;
832 Position activePosition = uaop.getPosition();
833 ICalcIterator iterator = new CalcIterator(calc_tree_,
835 calc_tree_.moveActiveFormula(iterator);
839 case UI_SOLVE_CHANGE_CONTEXT_FORMULA: {
840 UserActionOnPosition uaop = (UserActionOnPosition) action;
841 Position activePosition = uaop.getPosition();
842 if (activePosition != null) {
843 context_formula_ = new CalcIterator(calc_tree_, activePosition);
844 notifyContextPresenter();
849 case UI_SOLVE_GET_PROPOSED_TACTIC:
850 throw new DialogNotImplementedException(request, phase_);
852 case UI_SOLVE_GET_APPLICABLE_TACTICS:
853 sendApplicableTacticsToWorksheet(context_formula_);
854 doUIAction(new UIAction(
855 EUIElement.UI_SOLVE_SHOW_APPLICABLE_TACTICS,
856 EUIContext.UI_CONTEXT_ONEELEMENT, user_language_));
859 case UI_SOLVE_SET_NEXT_TACTIC:
860 UserActionOnCalcElement uaoce = (UserActionOnCalcElement) action;
862 calc_tree_.moveActiveFormula(new CalcIterator(calc_tree_, uaoce
864 calc_tree_.setNextTactic((Tactic) uaoce.getCalcElement());
865 calc_tree_.autoCalculate(IToCalc.SCOPE_CALCULATION, 1);
868 case UI_SOLVE_HELP_ENTERING_FORMULA:
869 throw new DialogNotImplementedException(request, phase_);
871 case UI_SOLVE_SHOW_ASSUMPTIONS: {
872 Assumptions asm = context_formula_.getAssumptions();
873 System.out.println("in WSDialog: asm = " + asm.toSMLString());
874 doUIAction(new UIActionOnCalcElement(
875 EUIElement.UI_SOLVE_SHOW_ASSUMPTIONS,
876 EUIContext.UI_CONTEXT_CALCELEMENTS, user_language_, asm));
880 case UI_SOLVE_SHOW_INTERMEDIATE_STEPS: {
881 calc_tree_.intermediateSteps(context_formula_);
885 case UI_SOLVE_TACTIC_APPLIED: {
886 Tactic ta = context_formula_.getTactic();
887 doUIAction(new UIActionOnCalcElement(
888 EUIElement.UI_SOLVE_TACTIC_APPLIED,
889 EUIContext.UI_CONTEXT_CALCELEMENTS, user_language_, ta));
893 case UI_SPECIFY_OPEN_CALCHEAD:
894 System.out.println("Pressed!");
898 throw new DialogUnknownActionException(request, phase_);
903 private void rmiBind() {
904 if (System.getSecurityManager() == null) {
905 System.setSecurityManager(new RMISecurityManager());
910 .createRegistry(ObjectManagerPaths.OBJECT_MANAGER_PORT);
911 } catch (java.rmi.RemoteException exc2) {
912 System.err.println("can not create registry: " + exc2.getMessage());
916 // //localhost/isac-WorksheetDialog...Naming.rebind(name, this);
917 String name = ObjectManagerPaths.WORKSHEET_DIALOG_PATH; // "//localhost/isac-WorksheetDialog";
919 System.out.println("try to bind as " + name);
920 Naming.rebind(name, this);
921 System.out.println("Dialog Guide bound to " + name);
922 // WN040906 was Object Manager ...
923 } catch (java.rmi.ConnectException e) {
924 System.err.println("failed to contact as " + name
925 + " (creating RMI-Server on localhost: 1099)");
926 } catch (RemoteException e) {
928 } catch (MalformedURLException e) {
934 * @see isac.wsdialog.IWorksheetDialog#notifyGUIReady()
936 public void notifyGUIReady() throws RemoteException {
937 worksheet_ready_ = true;
941 * @see isac.interfaces.IToGUI#doUIAction(isac.wsdialog.EUIContext) LK
942 * introduced worksheet_ready_ which required new Runnable
944 public synchronized void doUIAction(final IUIAction action)
945 throws RemoteException {
946 Thread t = new Thread(new Runnable() {
950 while (worksheet_ready_ == false) {
953 } catch (InterruptedException e1) {
954 e1.printStackTrace();
957 ui_control_listener_.doUIAction(action);
958 } catch (RemoteException e) {
967 * request the gui to add an interactive element
969 * @see isac.interfaces.IToGUI#addUIElement(isac.wsdialog.IUIAction)
971 public synchronized void addUIElement(final IUIAction action)
972 throws RemoteException {
973 Thread t = new Thread(new Runnable() {
977 while (worksheet_ready_ == false) {
980 } catch (InterruptedException e1) {
981 e1.printStackTrace();
984 ui_control_listener_.addUIElement(action);
985 } catch (RemoteException e) {
994 * request the gui to remove an interactive element
996 * @see isac.interfaces.IToGUI#removeUIElement(isac.wsdialog.IUIAction)
998 public synchronized void removeUIElement(final IUIAction action)
999 throws RemoteException {
1000 Thread t = new Thread(new Runnable() {
1004 while (worksheet_ready_ == false) {
1007 } catch (InterruptedException e1) {
1008 e1.printStackTrace();
1011 ui_control_listener_.removeUIElement(action);
1012 // ???worksheet_ready_ = false;
1013 } catch (RemoteException e) {
1014 e.printStackTrace();
1021 /***************************************************************************
1022 * TODO: notify the active context presenter that something happened
1024 private void notifyContextPresenter() {
1025 System.out.println("In WorksheetDialog::notifyContextPresenter !!");
1027 Context current_context = new ContextUnknown();
1028 IContextPresenter bdg = session_.getContextPresenter();
1031 System.out.println("No dialog");
1035 if (bdg instanceof ExampleDialog) {
1036 System.out.println("Example dialog");
1037 current_context = initContext(ContextType.CONTEXT_EXAMPLES);
1038 } else if (bdg instanceof ProblemDialog) {
1039 System.out.println("Problem dialog");
1040 current_context = initContext(ContextType.CONTEXT_PROBLEMS);
1041 } else if (bdg instanceof MethodDialog) {
1042 System.out.println("Method dialog");
1043 current_context = initContext(ContextType.CONTEXT_METHODS);
1044 } else if (bdg instanceof TheoryDialog) {
1045 System.out.println("Theory dialog");
1046 current_context = initContext(ContextType.CONTEXT_THEORIES);
1049 bdg.presentContext(current_context);
1053 * @see isac.wsdialog.IContextProvider#initContext(ContextMethod)
1055 * @throws RemoteException
1058 public Context initContext(ContextType type) {
1059 System.out.println("In WorksheetDialog::initContext() : type is "
1062 Context current_context = new ContextUnknown();
1065 case CONTEXT_EXAMPLES:
1066 current_context = new ContextExample();
1067 current_context.setKEStoreKey(session_
1068 .getExampleOfWorksheet(worksheet_id_));
1070 case CONTEXT_METHODS:
1071 case CONTEXT_PROBLEMS:
1072 case CONTEXT_THEORIES:
1074 current_context = context_formula_.initContext(type);
1075 } catch (RemoteException e) {
1076 e.printStackTrace();
1081 System.out.println("current context:" + current_context);
1083 if (current_context == null)
1084 return new ContextUnknown();
1086 return current_context;
1092 * @see isac.wsdialog.IContextProvider#refineContext(isac.util.formulae.Context)
1094 public Context refineContext(Context context) {
1096 Context current_context = null;
1099 current_context = context_formula_.refineProblem(context);
1100 } catch (RemoteException e) {
1101 e.printStackTrace();
1104 if (current_context == null)
1105 return new ContextUnknown();
1107 return current_context;
1110 public void setContext(Context context) {
1114 if (context instanceof ContextTheory) {
1115 System.out.println("In WSDialog::setContext() : Theory");
1116 context_formula_.setContext((ContextTheory) context);
1118 } else if (context instanceof ContextMethod) {
1119 System.out.println("In WSDialog::setContext() : Method");
1120 ch = context_formula_.setContext((ContextMethod) context);
1121 } else if (context instanceof ContextProblem) {
1122 System.out.println("In WSDialog::setContext() : Problem");
1123 ch = context_formula_.setContext((ContextProblem) context);
1126 .println("Can not set this context (Basis class, ContextExample or ContextUnknown)");
1131 doUIAction(new UIActionOnCalcElement(
1132 EUIElement.UI_SPECIFY_CHECK_CALCHEAD,
1133 EUIContext.UI_CONTEXT_CALCHEAD, user_language_, ch));
1136 } catch (RemoteException e) {
1137 e.printStackTrace();
1146 * @see isac.wsdialog.IContextProvider#checkContext(isac.util.formulae.Context)
1148 public Context checkContext(Context context) {
1149 Context current_context = null;
1152 current_context = context_formula_.checkContext(context);
1153 } catch (RemoteException e) {
1154 e.printStackTrace();
1157 if (current_context == null)
1158 return new ContextUnknown();
1160 return current_context;
1164 * @see isac.wsdialog.IContextProvider#getWorksheetState()
1166 public WorksheetState getWorksheetState() {
1168 // WorksheetState wsstate = new WorksheetState(
1169 // context_formula_.onCalcHead() );
1171 // } catch (RemoteException e) {
1172 // e.printStackTrace();
1175 return new WorksheetState(phase_ == DIALOGPHASE_SPECIFY);