View Javadoc

1   package com.sri.emo.wizard.creation;
2   
3   import com.jcorporate.expresso.core.controller.Transition;
4   import com.jcorporate.expresso.core.db.DBException;
5   import com.sri.emo.controller.CreationWizardAction;
6   import com.sri.emo.wizard.WizardException;
7   import com.sri.emo.wizard.creation.persistence.CreationDefinition;
8   import com.sri.emo.wizard.expressoimpl.WizardController;
9   import com.sri.emo.wizard.wizardgateway.RunWizard;
10  import com.sri.emo.wizard.wizardgateway.WizardGatewayController;
11  
12  /***
13   * Allows for locating completion wizards for a given node.
14   *
15   * @author Michael Rimov
16   * @version 1.0
17   */
18  public class CreationWizardSelector {
19      public CreationWizardSelector() {
20          super();
21      }
22  
23      /***
24       * Resolves a definingNodeId to a CompletionWizard.
25       *
26       * @param definingNodeId         String the target node id by which the completion wizard
27       *                               is found.
28       * @param optionalNodeToModifyId String the node id to operate the wizard on.  May be null.
29       * @return Transition to the appropriate wizard gateway with parameters populated
30       *         or null if no appropriate completion wizard is found.
31       * @throws WizardException
32       */
33      public Transition locateCompletionWizardForNode(final String definingNodeId,
34                                                      final String optionalNodeToModifyId) throws WizardException {
35          try {
36              CreationDefinition definition = new CreationDefinition();
37              /***
38               * @todo rich: definingNodeId is now a String which contains all of the node ids,
39               * so make sure that this doesn't create a conflict during the
40               * finish stage of the completion wizard (which is when this method gets called)
41               */
42              definition.setField(CreationDefinition.FLD_TARGET_NODE, definingNodeId);
43              if (definition.find()) {
44                  Transition wizardGateway = new Transition();
45                  wizardGateway.setControllerObject(WizardGatewayController.class);
46                  wizardGateway.setState(RunWizard.STATE_NAME);
47                  wizardGateway.setLabel("Run Wizard");
48                  wizardGateway.addParam(WizardController.WIZ_PARAMETER_ID,
49                          definition.getField(CreationDefinition.FLD_ID));
50                  if (optionalNodeToModifyId != null) {
51                      wizardGateway.addParam(CreationWizardAction.PARAM_TARGET_ID, optionalNodeToModifyId);
52                  }
53  
54                  return wizardGateway;
55              } else {
56                  return null;
57              }
58          } catch (DBException ex) {
59              throw new WizardException("Error searching for matching completion wizard", ex);
60          }
61      }
62  
63  }