View Javadoc

1   package com.sri.emo.wizard.wizardgateway;
2   
3   import com.jcorporate.expresso.core.controller.*;
4   import com.jcorporate.expresso.core.db.DBException;
5   import com.jcorporate.expresso.core.dbobj.ValidValue;
6   import com.sri.common.controller.StateHandler;
7   
8   import java.util.List;
9   
10  /***
11   * Prompts for adding a wizard.  It must allow the user to distinguish
12   * between different types of wizards.
13   *
14   * @author Michael Rimov
15   * @version 1.0
16   */
17  public class PromptAddWizard extends AddWizardHandler implements StateHandler {
18  
19      /***
20       * Name of the State for which this handler deals with.
21       */
22      public static final String STATE_NAME = "promptAdd";
23  
24  
25      /***
26       * Friendly description of this handler.
27       */
28      public static final String STATE_DESCRIPTION = "Prompt To Add A Wizard";
29  
30      /***
31       * Constructs this particular state handler.
32       *
33       * @param handlerOwner Controller the controller that is the parent of this
34       *                     state handler.
35       */
36      public PromptAddWizard(final Controller handlerOwner) {
37          super(handlerOwner);
38      }
39  
40      /***
41       * Called to handle the request.
42       *
43       * @param request  ControllerRequest The Function's ControllerRequest
44       *                 object.
45       * @param response ControllerResponse The Function's ControllerResponse
46       *                 object.
47       * @throws DBException         upon underlying database exception error.
48       * @throws ControllerException upon underlying ControllerException error.
49       */
50      public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
51              ControllerException {
52          response.setTitle("Choose Type of Wizard");
53          Transition cancel = new Transition("Cancel", this.getOwner().getClass(), ListWizards.STATE_NAME);
54          cancel.setName("cancel");
55          response.add(cancel);
56  
57          Input selection = new Input();
58          selection.setName(AddWizardHandler.PARAM_WIZARD_TYPE);
59          selection.setAttribute(Input.ATTRIBUTE_MULTIVALUED, "Y");
60  
61          List selectionValidValues = getWizardTypeList();
62          selection.setValidValues(selectionValidValues);
63          response.add(selection);
64          if (response.getFormCache(AddWizardHandler.PARAM_WIZARD_TYPE) == null
65                  || response.getFormCache(AddWizardHandler.PARAM_WIZARD_TYPE).length() == 0) {
66              selection.setDefaultValue(((ValidValue) selectionValidValues.get(0)).getKey());
67          } else {
68              selection.setDefaultValue(response);
69          }
70  
71          Transition submit = new Transition("Next", this.getOwner().getClass(), DoAddWizard.STATE_NAME);
72          submit.setName("next");
73          response.add(submit);
74  
75      }
76  
77  }