src/java/isac/wsdialog/DialogGuide.java
author wneuper
Fri, 10 Dec 2004 14:22:29 +0100
changeset 1994 7660ebbc276f
parent 1993 bd1ffe6f3ee7
child 1998 4f354c13abd4
permissions -rw-r--r--
new 'chalcChanged' with 3 Iterators;
little code tidying
akremp@861
     1
package isac.wsdialog;
akremp@861
     2
mhochrei@1163
     3
import isac.bridge.*;
mhochrei@1163
     4
import isac.util.*;
rgradisc@1313
     5
import isac.util.formulae.*;
rgradisc@1313
     6
import isac.util.interfaces.*;
rgradisc@1313
     7
import isac.util.tactics.*;
mhochrei@939
     8
akremp@945
     9
import java.io.Serializable;
mhochrei@954
    10
import java.net.MalformedURLException;
mhochrei@1163
    11
import java.rmi.*;
mhochrei@954
    12
import java.rmi.registry.LocateRegistry;
mhochrei@952
    13
import java.rmi.server.UnicastRemoteObject;
akremp@1022
    14
import java.util.Vector;
akremp@867
    15
wneuper@1978
    16
import org.apache.log4j.Logger;
wneuper@1978
    17
akremp@1703
    18
/* TODO:
akremp@1703
    19
 * 
akremp@1703
    20
 * * recognize CalcHead in Changed Formula -> switch to DILAOGPAHSE_SPECIFY_SUBPROBLEM
akremp@1703
    21
 * * differentiate CalcHeads 
akremp@1703
    22
 * 
akremp@1703
    23
 *
wneuper@1815
    24
 */
akremp@1703
    25
akremp@861
    26
/**
wneuper@1815
    27
 * The DialogGuide moderates the communication between two instances working on
wneuper@1815
    28
 * the same CalcTree object. One of these instances is the user, the other a
wneuper@1815
    29
 * math engine. Most probably, the user's GUI, the DialogGuide and the math
wneuper@1815
    30
 * engine reside on different machines and communicate with each other by means
wneuper@1815
    31
 * of RMI.
akremp@1340
    32
 * 
akremp@945
    33
 * @author Alan Krempler
akremp@867
    34
 */
wneuper@1815
    35
public class DialogGuide extends UnicastRemoteObject implements DGuide,
wneuper@1815
    36
		IToUser, Serializable {
rgradisc@1586
    37
wneuper@1978
    38
	static Logger logger_ = Logger.getLogger(BridgeRMI.class.getName());
wneuper@1978
    39
wneuper@1815
    40
	protected CalcTree calc_tree_;
akirchst@1881
    41
  
akirchst@1881
    42
	//protected CalcHead calc_head_;
rgradisc@1618
    43
wneuper@1815
    44
	protected CalcHead calc_head_sub_;
mhochrei@974
    45
wneuper@1815
    46
	protected MathEngine math_engine_;
rgradisc@1618
    47
wneuper@1815
    48
	protected int phase_;
akremp@861
    49
akirchst@1881
    50
	private Vector datachange_listeners_;
akremp@1597
    51
wneuper@1815
    52
	private IToWorksheet ui_control_listener_;
rgradisc@1618
    53
wneuper@1815
    54
	/**
wneuper@1815
    55
	 * @param ME_path
wneuper@1815
    56
	 *            URL of the math engine to be used
wneuper@1815
    57
	 * @throws RemoteException
wneuper@1815
    58
	 */
wneuper@1815
    59
	public DialogGuide(String ME_path) throws RemoteException {
wneuper@1815
    60
		super();
wneuper@1815
    61
		this.rmiBind();
wneuper@1815
    62
		datachange_listeners_ = new Vector();
wneuper@1815
    63
		MathEngine.init(ME_path);
wneuper@1815
    64
		math_engine_ = MathEngine.getMathEngine();
wneuper@1815
    65
		phase_ = DIALOGPHASE_IDLE;
wneuper@1815
    66
	}
rgradisc@1618
    67
wneuper@1815
    68
	/**
wneuper@1815
    69
	 * at the beginning of a calculation as well as of a subproblem
wneuper@1815
    70
	 * 
wneuper@1815
    71
	 * @param calc_head
wneuper@1815
    72
	 *            empty (formalization stored invisibly in the calcTree)
wneuper@1815
    73
	 * @return calc_head with viestyle set
wneuper@1815
    74
	 */
wneuper@1815
    75
	// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
wneuper@1815
    76
	// and like trymatch etc. see below
wneuper@1815
    77
	CalcHead startSpecifying(CalcHead calc_head) {
rgradisc@1618
    78
wneuper@1815
    79
		//  WN040825 if (start_from == STARTFROM_EXAMPLE) { <---startSpecifying ?
rgradisc@1618
    80
wneuper@1815
    81
		int calchead_view = CalcHead.VIEWSTYLE_SINGLELINE;
wneuper@1815
    82
		//WN040824 VIEWSTYLE_IN_CALC depends on UserModel
wneuper@1815
    83
		//WN040824 VIEWSTYLE_IN_CALC is appropriate for equations, not for
wneuper@1815
    84
		// maximumexpl
wneuper@1815
    85
		//WN040825 appropriate for pbl-class [univatiate,equation]
wneuper@1815
    86
		//WN040825 NOT -"- for maximum-expl
wneuper@1815
    87
		calc_head.setCalcHeadStatus(calchead_view);
akirchst@1881
    88
		calc_tree_.completeCalcHead();
rgradisc@1618
    89
wneuper@1815
    90
		phase_ = DIALOGPHASE_SPECIFY;
wneuper@1815
    91
		return calc_head; //WN040906 this is NOT completed !!!
wneuper@1815
    92
		// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
wneuper@1815
    93
	}
wneuper@1815
    94
wneuper@1815
    95
	// FIXME.WN040906 do NOT return calc_head, like Formula in solve-phase
akirchst@1890
    96
	public CalcTree startCalculation(int user_id, Formalization f,
wneuper@1815
    97
			int start_from, int requested_calchead_view) {
wneuper@1815
    98
akirchst@1881
    99
    calc_tree_ = math_engine_.startCalculation(f);
akirchst@1890
   100
    calc_tree_.completeCalcHead();
wneuper@1815
   101
wneuper@1815
   102
		// for the moment, all requests for a view are honored
wneuper@1815
   103
		//  WN040825 calc_head_.setViewStyle(requested_calchead_view);
wneuper@1815
   104
		// --->startSpecifying
wneuper@1815
   105
wneuper@1815
   106
		// for testing purposes: if starting an example from the collection,
wneuper@1815
   107
		// have everything filled in by the KI
wneuper@1815
   108
		//  WN040825 if (start_from == STARTFROM_EXAMPLE) { --->startSpecifying ?
wneuper@1815
   109
wneuper@1815
   110
		// old-style filling the fields of the calc-head by setting
wneuper@1815
   111
		// the HELP_ME flag
wneuper@1815
   112
		// calc_head_.setCalcHeadStatus(CalcHead.CALCHEAD_HELP_ME);
wneuper@1815
   113
		// }
wneuper@1815
   114
wneuper@1815
   115
		// test code; this protocol is now controlled by the presentation layer
wneuper@1815
   116
		// do {
wneuper@1815
   117
		// checkCalcHead()
wneuper@1815
   118
		// } while (false); // status != ok
wneuper@1815
   119
		// newCalculation(calc_head_);
akirchst@1881
   120
		phase_ = DIALOGPHASE_SPECIFY;
wneuper@1815
   121
		//WN040825 return calc_head_;
akirchst@1890
   122
    return calc_tree_;
wneuper@1815
   123
	}
wneuper@1815
   124
wneuper@1815
   125
	public void newCalculation(CalcHead calcHead) {
wneuper@1815
   126
		try {
akirchst@1881
   127
			calc_tree_.startSolving();
wneuper@1815
   128
		} catch (Exception e) {
wneuper@1815
   129
			// TODO Auto-generated catch block
wneuper@1815
   130
			e.printStackTrace();
wneuper@1815
   131
		}
wneuper@1815
   132
		// calc_tree_ = MathEngine.getMathEngine().startSolving(calcHead);
wneuper@1815
   133
		calc_tree_.addDataChangeListener(this);
wneuper@1978
   134
		phase_ = DIALOGPHASE_SOLVE;//WN041122 nein ???!!!???
wneuper@1815
   135
	}
rgradisc@1618
   136
wneuper@1815
   137
	/*
wneuper@1815
   138
	 * (non-Javadoc)
wneuper@1815
   139
	 * 
wneuper@1815
   140
	 * @see isac.wsdialog.IToUser#calcChanged(isac.wsdialog.CalcChangedEvent)
wneuper@1815
   141
	 */
akirchst@1993
   142
	public void calcChanged(CalcChangedEvent event) throws RemoteException {
wneuper@1994
   143
		logger_.fatal("WS<-DG: calcChanged (unc="
wneuper@1994
   144
				+ event.getLastUnchangedFormula().toSMLString() + ", del="
wneuper@1994
   145
				+ event.getLastDeletedFormula().toSMLString() + ", gen="
wneuper@1994
   146
				+ event.getLastGeneratedFormula().toSMLString());
wneuper@1815
   147
		ICalcElement calc_elem;
wneuper@1815
   148
akirchst@1993
   149
    try {
wneuper@1815
   150
		for (int i = 0; i < datachange_listeners_.size(); i++) {
wneuper@1815
   151
			((IToUser) datachange_listeners_.elementAt(i)).calcChanged(event);
wneuper@1815
   152
		}
wneuper@1815
   153
		ICalcIterator last_formula = event.getFirstChangedFormula();
wneuper@1815
   154
		// while searching for last formula, mark intermediate CalcHeads as not
wneuper@1815
   155
		// to be edited
akirchst@1993
   156
    // try {
wneuper@1815
   157
		while (!last_formula.isLast()) {
wneuper@1815
   158
			if (last_formula.getElement().getType() == ICalcElement.CALCEL_CALCHEAD) {
wneuper@1815
   159
				last_formula.getElement().setViewStyle(
wneuper@1815
   160
						CalcHead.VIEWSTYLE_IN_CALC);
akremp@1706
   161
			}
wneuper@1815
   162
			last_formula.moveDown();
wneuper@1815
   163
			//TODO last_formula.moveDown.. WN040824 DG may limit the level down
wneuper@1815
   164
		}
akirchst@1871
   165
wneuper@1815
   166
		// for now, do not specify the CalcHead, just display it.
wneuper@1815
   167
		calc_elem = last_formula.getElement();
akremp@899
   168
wneuper@1815
   169
		if (calc_elem.getType() == ICalcElement.CALCEL_CALCHEAD) {
wneuper@1815
   170
			//WN040826 phase_ = DIALOGPHASE_SPECIFY; --->startSpecifying
wneuper@1815
   171
			//WN040826
wneuper@1815
   172
			// calc_elem.setViewStyle(CalcHead.VIEWSTYLE_SINGLELINE);--->startSpecifying
akremp@899
   173
wneuper@1815
   174
			//WN040826calc_head = startSpecifying((CalcHead) calc_elem);
wneuper@1815
   175
			// --->startSpecifying
wneuper@1815
   176
			startSpecifying((CalcHead) calc_elem);
wneuper@1815
   177
			//WN040826 math_engine_.completeCalcHead(calc_head);
wneuper@1815
   178
			// --->startSpecifying
wneuper@1815
   179
		} else {
wneuper@1815
   180
			phase_ = DIALOGPHASE_SOLVE;
wneuper@1815
   181
		}
akirchst@1871
   182
    } catch (Exception e) {
akirchst@1871
   183
      e.printStackTrace();
akirchst@1871
   184
    }
wneuper@1815
   185
	}
akremp@1232
   186
wneuper@1815
   187
	/**
wneuper@1815
   188
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   189
	 */
wneuper@1815
   190
	public void modifyCalcHead(CalcHead calc_head) {
wneuper@1815
   191
		// MathEngine.getMathEngine().modifyCalcHead(calc_head);
akirchst@1881
   192
		calc_tree_.modifyCalcHead(calc_head);
wneuper@1815
   193
	}
akremp@899
   194
wneuper@1815
   195
	/*
wneuper@1815
   196
	 * (non-Javadoc)
wneuper@1815
   197
	 * 
wneuper@1815
   198
	 * @see isac.wsdialog.IToCalc#iterator()
wneuper@1815
   199
	 */
wneuper@1815
   200
	public ICalcIterator iterator() {
akirchst@1871
   201
    try {
wneuper@1815
   202
		return new DialogIterator((CalcIterator) calc_tree_.iterator());
akirchst@1871
   203
    } catch (Exception e){
akirchst@1871
   204
      e.printStackTrace();
akirchst@1871
   205
    }
akirchst@1871
   206
    return null;
akirchst@1871
   207
  }
rgradisc@1618
   208
wneuper@1994
   209
	/**
wneuper@1815
   210
	 * @see isac.wsdialog.IToCalc#addListener(isac.wsdialog.IToUser)
wneuper@1815
   211
	 */
akirchst@1993
   212
	public boolean addDataChangeListener(IToUser listener) throws RemoteException{
wneuper@1815
   213
		if (datachange_listeners_.contains(listener)) {
wneuper@1815
   214
			return false;
wneuper@1815
   215
		} else {
wneuper@1815
   216
			datachange_listeners_.add(listener);
wneuper@1815
   217
		}
wneuper@1815
   218
		return true;
wneuper@1815
   219
	}
rgradisc@1618
   220
wneuper@1815
   221
	public boolean registerUIControlListener(IToWorksheet listener) {
wneuper@1815
   222
		if (ui_control_listener_ != null) {
wneuper@1815
   223
			ui_control_listener_.doUIAction(new UserAction(UI_DO_DETACH));
wneuper@1815
   224
		}
wneuper@1815
   225
		ui_control_listener_ = listener;
wneuper@1815
   226
		return true;
wneuper@1815
   227
	}
rgradisc@1618
   228
wneuper@1815
   229
	public Tactic fetchProposedTactic() {
wneuper@1815
   230
		return calc_tree_.fetchProposedTactic();
wneuper@1815
   231
	}
rgradisc@1618
   232
wneuper@1815
   233
	public Tactic[] fetchApplicableTactics(int scope) {
wneuper@1815
   234
		return calc_tree_.fetchApplicableTactics(scope);
wneuper@1815
   235
	}
rgradisc@1618
   236
wneuper@1815
   237
	/**
wneuper@1815
   238
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   239
	 */
wneuper@1815
   240
	public int setNextTactic(Tactic tactic) {
wneuper@1815
   241
		return calc_tree_.setNextTactic(tactic);
wneuper@1815
   242
	}
akremp@966
   243
wneuper@1815
   244
	/**
wneuper@1815
   245
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   246
	 */
wneuper@1815
   247
	public int autoCalculate(int scope, int nSteps) {
wneuper@1815
   248
		return calc_tree_.autoCalculate(scope, nSteps);
wneuper@1815
   249
	}
rgradisc@1618
   250
wneuper@1815
   251
	/**
wneuper@1815
   252
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   253
	 */
wneuper@1815
   254
	public void tryMatch(CalcHead ch, CalcHeadCompoundID problemID)
wneuper@1815
   255
			throws NotInSpecificationPhaseException {
rgradisc@1618
   256
wneuper@1815
   257
		// MathEngine.getMathEngine().tryMatch(ch, problemID);
wneuper@1815
   258
		math_engine_.tryMatch(ch, problemID);
wneuper@1815
   259
	}
rgradisc@1618
   260
wneuper@1815
   261
	/**
wneuper@1815
   262
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   263
	 */
wneuper@1815
   264
	public void tryRefine(CalcHead ch, CalcHeadCompoundID problemID)
wneuper@1815
   265
			throws NotInSpecificationPhaseException {
rgradisc@1618
   266
wneuper@1815
   267
		// MathEngine.getMathEngine().tryRefine(ch , problemID);
wneuper@1815
   268
		math_engine_.tryRefine(ch, problemID);
wneuper@1815
   269
	}
rgradisc@1618
   270
wneuper@1815
   271
	public ICalcIterator getActiveFormula() {
wneuper@1815
   272
		return calc_tree_.getActiveFormula();
wneuper@1815
   273
	}
rgradisc@1618
   274
wneuper@1815
   275
	/**
wneuper@1980
   276
	 * @throws RemoteException
wneuper@1815
   277
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   278
	 */
wneuper@1980
   279
	public int replaceFormula(Formula newFormula) throws RemoteException {
wneuper@1815
   280
		return calc_tree_.replaceFormula(newFormula);
wneuper@1815
   281
	}
rgradisc@1618
   282
wneuper@1815
   283
	/**
wneuper@1980
   284
	 * @throws RemoteException
wneuper@1815
   285
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   286
	 */
wneuper@1980
   287
	public int appendFormula(Formula newFormula) throws RemoteException {
wneuper@1815
   288
		return calc_tree_.appendFormula(newFormula);
wneuper@1815
   289
	}
akremp@1335
   290
wneuper@1815
   291
	/**
wneuper@1815
   292
	 * @deprecated Use {@link #notifyUserAction(IUserAction)}instead
wneuper@1815
   293
	 */
wneuper@1815
   294
	public void moveActiveFormula(ICalcIterator newActiveFormula) {
wneuper@1815
   295
		calc_tree_.moveActiveFormula(newActiveFormula);
wneuper@1815
   296
	}
wneuper@1815
   297
wneuper@1815
   298
	/**
wneuper@1815
   299
	 * Notify the Dialog Guide about interaction from the User
wneuper@1815
   300
	 * 
wneuper@1815
   301
	 * @param action
wneuper@1815
   302
	 * @return true, if the action has been processed, false if the processing
wneuper@1815
   303
	 *         the action has been denied
wneuper@1980
   304
	 * @throws RemoteException
wneuper@1815
   305
	 *  
wneuper@1815
   306
	 */
wneuper@1815
   307
	public boolean notifyUserAction(IUserAction action)
wneuper@1980
   308
			throws DialogProtocolException, RemoteException {
wneuper@1815
   309
		int request = action.getActionID();
wneuper@1981
   310
		logger_.fatal("WS->DG: notifyUserAction request= "+request);
wneuper@1815
   311
wneuper@1815
   312
		switch (phase_) {
wneuper@1815
   313
		case DIALOGPHASE_IDLE:
wneuper@1815
   314
			throw new DialogProtocolException(request, phase_);
wneuper@1978
   315
		case DIALOGPHASE_SPECIFY:
wneuper@1815
   316
			if (request < UI_DUMMY_FIRST_SPECIFY
wneuper@1815
   317
					|| request > UI_DUMMY_LAST_SPECIFY)
wneuper@1815
   318
				throw new DialogProtocolException(request, phase_);
wneuper@1815
   319
			break;
wneuper@1815
   320
		case DIALOGPHASE_SOLVE:
wneuper@1815
   321
			if (request < UI_DUMMY_FIRST_SOLVE || request > UI_DUMMY_LAST_SOLVE)
wneuper@1815
   322
				throw new DialogProtocolException(request, phase_);
wneuper@1815
   323
			break;
wneuper@1815
   324
		}
wneuper@1815
   325
akirchst@1881
   326
    CalcHead calc_head = new CalcHead();
akirchst@1890
   327
    try {
akirchst@1890
   328
      calc_head = (CalcHead) calc_tree_.iterator().getFormula();
akirchst@1890
   329
    } catch (Exception e) {
akirchst@1890
   330
      e.printStackTrace();
akirchst@1881
   331
    }
wneuper@1815
   332
		switch (request) {
wneuper@1815
   333
		case UI_SPECIFY_TRY_MATCH:
wneuper@1815
   334
			try {
akirchst@1881
   335
				tryMatch(calc_head, ((UserActionOnCalcHeadCompoundID) action)
wneuper@1815
   336
						.getObjectID());
wneuper@1815
   337
			} catch (NotInSpecificationPhaseException e) {
wneuper@1815
   338
				throw new DialogMathException(request, phase_, e);
wneuper@1815
   339
			}
wneuper@1815
   340
			break;
wneuper@1815
   341
wneuper@1815
   342
		case UI_SPECIFY_TRY_REFINE:
wneuper@1815
   343
			try {
akirchst@1881
   344
				tryRefine(calc_head, ((UserActionOnCalcHeadCompoundID) action)
wneuper@1815
   345
						.getObjectID());
wneuper@1815
   346
			} catch (NotInSpecificationPhaseException e) {
wneuper@1815
   347
				throw new DialogMathException(request, phase_, e);
wneuper@1815
   348
			}
wneuper@1815
   349
			break;
wneuper@1815
   350
wneuper@1815
   351
		case UI_SPECIFY_CHANGE_VIEW:
akirchst@1881
   352
			calc_head.setViewStyle(((UserActionOnInt) action).getInt());
wneuper@1815
   353
			break;
wneuper@1815
   354
wneuper@1815
   355
		case UI_SPECIFY_COMPLETE_CALCHEAD:
akirchst@1881
   356
			calc_tree_.completeCalcHead();
wneuper@1815
   357
			// old-style filling the fields of the calc-head by setting
wneuper@1815
   358
			// the HELP_ME flag
wneuper@1815
   359
			// calc_head_.setCalcHeadStatus(CalcHead.CALCHEAD_HELP_ME);
wneuper@1815
   360
			// modifyCalcHead(calc_head_);
wneuper@1815
   361
			break;
wneuper@1815
   362
		case UI_SPECIFY_COMPLETE_METHOD:
wneuper@1815
   363
		case UI_SPECIFY_COMPLETE_THEORY:
wneuper@1815
   364
		case UI_SPECIFY_COMPLETE_PROBLEM:
wneuper@1815
   365
		case UI_SPECIFY_COMPLETE_GIVEN:
wneuper@1815
   366
		case UI_SPECIFY_COMPLETE_FIND:
wneuper@1815
   367
		case UI_SPECIFY_COMPLETE_RELATE:
wneuper@1815
   368
			throw new DialogNotImplementedException(request, phase_);
wneuper@1815
   369
wneuper@1815
   370
		case UI_SPECIFY_CHECK_CALCHEAD:
akirchst@1881
   371
			modifyCalcHead(calc_head);
wneuper@1815
   372
			break;
wneuper@1815
   373
wneuper@1815
   374
		// was: newCalculation()
wneuper@1815
   375
		case UI_SPECIFY_CALCULATE_1:
wneuper@1815
   376
		case UI_SPECIFY_CALCULATE_ALL:
akirchst@1881
   377
			modifyCalcHead(calc_head);
akirchst@1881
   378
			if (calc_head.getCalcHeadStatus() != CalcHead.CALCHEAD_CORRECT)
wneuper@1815
   379
				return false;
wneuper@1815
   380
wneuper@1815
   381
			try {
akirchst@1881
   382
				calc_tree_.startSolving();
wneuper@1815
   383
			} catch (Exception e) {
wneuper@1815
   384
				// TODO Auto-generated catch block
wneuper@1815
   385
				e.printStackTrace();
wneuper@1815
   386
			}
wneuper@1815
   387
			// calc_tree_ = MathEngine.getMathEngine().startSolving(calcHead);
wneuper@1815
   388
			calc_tree_.addDataChangeListener(this);
wneuper@1815
   389
			phase_ = DIALOGPHASE_SOLVE;
wneuper@1815
   390
		// fall through to calculate
wneuper@1815
   391
wneuper@1815
   392
		case UI_SOLVE_CALCULATE_1:
wneuper@1815
   393
		case UI_SOLVE_CALCULATE_ALL:
wneuper@1815
   394
			switch (request) {
wneuper@1815
   395
			case UI_SPECIFY_CALCULATE_ALL:
wneuper@1815
   396
			case UI_SOLVE_CALCULATE_ALL:
wneuper@1815
   397
				autoCalculate(SCOPE_CALCULATION, 0);
akremp@1620
   398
				break;
wneuper@1815
   399
			case UI_SPECIFY_CALCULATE_1:
akremp@1620
   400
				break;
wneuper@1815
   401
			default:
wneuper@1815
   402
				autoCalculate(SCOPE_CALCULATION, 1);
wneuper@1815
   403
				break;
wneuper@1815
   404
			}
wneuper@1815
   405
			break;
rgradisc@1618
   406
wneuper@1815
   407
		case UI_SOLVE_CALCULATE_SUBPROBLEM:
wneuper@1815
   408
			autoCalculate(SCOPE_SUBPROBLEM, 0);
wneuper@1815
   409
			break;
rgradisc@1618
   410
wneuper@1815
   411
		case UI_SOLVE_EDIT_ACTIVE_FORMULA:
wneuper@1815
   412
			ui_control_listener_.doUIAction(new UserAction(UI_DO_EDIT_FORMULA));
wneuper@1815
   413
			break;
rgradisc@1618
   414
wneuper@1815
   415
		case UI_SOLVE_EDIT_ACTIVE_FORMULA_COMPLETE:
wneuper@1815
   416
			replaceFormula((Formula) ((UserActionOnCalcElement) action)
wneuper@1815
   417
					.getCalcElement());
wneuper@1815
   418
			break;
rgradisc@1618
   419
wneuper@1815
   420
		case UI_SOLVE_APPEND_USER_FORMULA:
wneuper@1815
   421
			// appendFormula((Formula) ((UserActionOnCalcElement)
wneuper@1815
   422
			// action).getCalcElement());
wneuper@1815
   423
			ui_control_listener_
wneuper@1815
   424
					.doUIAction(new UserAction(UI_DO_APPEND_FORMULA));
wneuper@1815
   425
			break;
rgradisc@1618
   426
wneuper@1815
   427
		case UI_SOLVE_MOVE_ACTIVE_FORMULA:
wneuper@1815
   428
			moveActiveFormula(((UserActionOnIterator) action).getPosition());
wneuper@1815
   429
			break;
rgradisc@1618
   430
wneuper@1815
   431
		case UI_SOLVE_GET_PROPOSED_TACTIC:
wneuper@1815
   432
			throw new DialogNotImplementedException(request, phase_);
rgradisc@1618
   433
wneuper@1815
   434
		case UI_SOLVE_GET_APPLICABLE_TACTICS:
wneuper@1815
   435
			throw new DialogNotImplementedException(request, phase_);
rgradisc@1618
   436
wneuper@1815
   437
		case UI_SOLVE_SET_NEXT_TACTIC:
wneuper@1815
   438
			setNextTactic((Tactic) ((UserActionOnCalcElement) action)
wneuper@1815
   439
					.getCalcElement());
wneuper@1978
   440
			//WN041126 extracted from isac.bridge.CalcTree#setNextTactic @@@
wneuper@1978
   441
			//autoCalculate(SCOPE_CALCULATION, 1);			
wneuper@1815
   442
			break;
rgradisc@1618
   443
wneuper@1815
   444
		case UI_SOLVE_HELP_ENTERING_FORMULA:
wneuper@1815
   445
			throw new DialogNotImplementedException(request, phase_);
rgradisc@1618
   446
wneuper@1815
   447
		case UI_SOLVE_SHOW_ASSUMPTIONS:
wneuper@1815
   448
			throw new DialogNotImplementedException(request, phase_);
rgradisc@1618
   449
wneuper@1815
   450
		case UI_SOLVE_SHOW_DETAILS:
wneuper@1815
   451
			throw new DialogNotImplementedException(request, phase_);
rgradisc@1618
   452
wneuper@1815
   453
		default:
wneuper@1815
   454
			throw new DialogUnknownActionException(request, phase_);
wneuper@1815
   455
		}
wneuper@1815
   456
		return true;
wneuper@1815
   457
	}
rgradisc@1618
   458
wneuper@1815
   459
	private void rmiBind() {
wneuper@1815
   460
		if (System.getSecurityManager() == null) {
wneuper@1815
   461
			System.setSecurityManager(new RMISecurityManager());
wneuper@1815
   462
		}
rgradisc@1618
   463
wneuper@1815
   464
		try {
wneuper@1815
   465
			LocateRegistry.createRegistry(1099);
wneuper@1815
   466
		} catch (java.rmi.RemoteException exc2) {
wneuper@1815
   467
			System.err.println("can not create registry: " + exc2.getMessage());
wneuper@1815
   468
		}
rgradisc@1618
   469
wneuper@1815
   470
		String name = "//localhost/isac-DialogGuide";
wneuper@1815
   471
		try {
wneuper@1815
   472
			System.out.println("try to bind as " + name);
wneuper@1815
   473
			Naming.rebind(name, this);
wneuper@1815
   474
			System.out.println("Dialog Guide bound to " + name);
wneuper@1815
   475
			//WN040906      was Object Manager ...
wneuper@1815
   476
		} catch (java.rmi.ConnectException e) {
wneuper@1815
   477
			System.err.println("failed to contact as " + name
wneuper@1815
   478
					+ " (creating RMI-Server on localhost: 1099)");
wneuper@1815
   479
		} catch (RemoteException e) {
wneuper@1815
   480
			// TODO Auto-generated catch block
wneuper@1815
   481
			e.printStackTrace();
wneuper@1815
   482
		} catch (MalformedURLException e) {
wneuper@1815
   483
			// TODO Auto-generated catch block
wneuper@1815
   484
			e.printStackTrace();
wneuper@1815
   485
		}
wneuper@1815
   486
	}
rgradisc@1618
   487
wneuper@1815
   488
	public static void main(String[] args) {
wneuper@1815
   489
		try {
wneuper@1815
   490
			new DialogGuide(args[0]);
akirchst@1881
   491
      
wneuper@1815
   492
		} catch (RemoteException e) {
wneuper@1815
   493
			e.printStackTrace();
wneuper@1815
   494
		}
wneuper@1815
   495
	}
rgradisc@1618
   496
akirchst@1881
   497
  /* (non-Javadoc)
akirchst@1881
   498
   * @see isac.util.interfaces.IToCalc#startSolving()
akirchst@1881
   499
   */
akirchst@1881
   500
  public void startSolving() throws Exception {
akirchst@1881
   501
    // TODO Auto-generated method stub
akirchst@1881
   502
    
akirchst@1881
   503
  }
wneuper@1877
   504
akirchst@1881
   505
  /* (non-Javadoc)
akirchst@1881
   506
   * @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead)
akirchst@1881
   507
   */
akirchst@1881
   508
  public void completeCalcHead(CalcHead calcHead) {
akirchst@1881
   509
    // TODO Auto-generated method stub
akirchst@1881
   510
    
akirchst@1881
   511
  }
wneuper@1877
   512
akirchst@1881
   513
  /* (non-Javadoc)
akirchst@1881
   514
   * @see isac.util.interfaces.IToCalc#completeCalcHead(isac.util.formulae.CalcHead, int)
akirchst@1881
   515
   */
akirchst@1881
   516
  public void completeCalcHead(CalcHead calcHead, int completeItem) {
akirchst@1881
   517
    // TODO Auto-generated method stub
akirchst@1881
   518
    
akirchst@1881
   519
  }
akirchst@1881
   520
akirchst@1881
   521
  /* (non-Javadoc)
akirchst@1881
   522
   * @see isac.util.interfaces.IToCalc#completeCalcHead()
akirchst@1881
   523
   */
akirchst@1881
   524
  public void completeCalcHead() throws RemoteException {
akirchst@1881
   525
    // TODO Auto-generated method stub
akirchst@1881
   526
    
akirchst@1881
   527
  }
wneuper@1877
   528
wneuper@1815
   529
}