1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.creation.management;
11
12 import com.jcorporate.expresso.core.controller.ControllerException;
13 import com.jcorporate.expresso.core.controller.ExpressoRequest;
14 import com.jcorporate.expresso.core.controller.ExpressoResponse;
15 import com.jcorporate.expresso.core.controller.Transition;
16 import com.jcorporate.expresso.core.db.DBException;
17 import com.sri.common.controller.AbstractComponentController;
18 import com.sri.emo.EmoSchema;
19 import com.sri.emo.controller.CreationWizardAction;
20 import com.sri.emo.dbobj.WizDefinition;
21 import com.sri.emo.wizard.IWizardManager;
22 import com.sri.emo.wizard.expressoimpl.WizardController;
23
24
25 /***
26 * Controller that manages completion wizards. This class derives from Component
27 * Controller which takes care of the job of assembling all the state handlers
28 * and dispatching them. So the AbstractComponentController is now more of a
29 * mediator and factory then anything else.
30 * <p>Side note: Of course, standard state handlers may be mixed with this
31 * class.</p>
32 *
33 * @author Michael Rimov
34 * @version 1.0
35 */
36 public class CreationEditor extends AbstractComponentController implements IWizardManager {
37
38
39 /***
40 * Default constructor. Creates all the appropriate states for the
41 * controller.
42 */
43 public CreationEditor() {
44 super(EmoSchema.class);
45
46 this.addStateHandler(PromptChooseNode.STATE_NAME, PromptChooseNode.STATE_DESCRIPTION,
47 PromptChooseNode.class);
48
49 this.setInitialState(PromptChooseNode.STATE_NAME);
50
51 this.addStateHandler(DoChooseNodeStep.STATE_NAME, DoChooseNodeStep.STATE_DESCRIPTION, DoChooseNodeStep.class);
52
53 this.addStateHandler(PromptChooseParts.STATE_NAME, PromptChooseParts.STATE_DESCRIPTION,
54 PromptChooseParts.class);
55
56 this.addStateHandler(DoChooseParts.STATE_NAME, DoChooseParts.STATE_DESCRIPTION, DoChooseParts.class);
57
58 this.addStateHandler(PromptChooseCriteria.STATE_NAME, PromptChooseCriteria.STATE_DESCRIPTION,
59 PromptChooseCriteria.class);
60
61 this.addStateHandler(DoChooseCriteria.STATE_NAME, DoChooseCriteria.STATE_DESCRIPTION, DoChooseCriteria.class);
62
63 this.addStateHandler(PromptEditWizard.STATE_NAME, PromptEditWizard.STATE_DESCRIPTION, PromptEditWizard.class);
64
65 this.addStateHandler(DoCancel.STATE_NAME, DoCancel.STATE_DESCRIPTION, DoCancel.class);
66 }
67
68 /***
69 * Begins an 'add' end-user transaction to create a new wizard.
70 *
71 * @param request ExpressoRequest the request object.
72 * @param response ExpressoResponse the response object.
73 * @throws ControllerException
74 */
75 public void add(final ExpressoRequest request, final ExpressoResponse response) throws ControllerException {
76
77
78 ICreationBeanManager beanManager = (ICreationBeanManager) this.locator().locate(
79 ICreationBeanManager.class);
80 beanManager.destroyActionForm(request);
81
82
83 Transition t = new Transition(PromptChooseNode.STATE_NAME, this);
84 t.redirectTransition(request, response);
85 }
86
87 /***
88 * Begins an 'edit' end-user transaction to edit an existing wizard.
89 *
90 * @param wizard The WizardDefinition to edit.
91 * @param request ExpressoRequest the request object.
92 * @param response ExpressoResponse the response object.
93 * @throws ControllerException upon error.
94 * @todo Implement this com.sri.emo.dbobj.IWizardManager method
95 */
96 public void edit(final WizDefinition wizard, final ExpressoRequest request,
97 final ExpressoResponse response) throws ControllerException {
98 Transition t = new Transition(PromptEditWizard.STATE_NAME, this);
99 try {
100 t.addParam(WizardController.WIZ_PARAMETER_ID, wizard.getId());
101 } catch (DBException ex) {
102 throw new ControllerException("Error querying object for id.", ex);
103 }
104 t.redirectTransition(request, response);
105 }
106
107 /***
108 * Runs the wizard that the manager is associated with.
109 *
110 * @param wizard WizDefinition
111 * @param request ExpressoRequest
112 * @param response ExpressoResponse
113 * @throws ControllerException
114 */
115 public void run(final WizDefinition wizard, final ExpressoRequest request, final ExpressoResponse response) throws
116 ControllerException {
117 Transition t = new Transition("", "", CreationWizardAction.class, CreationWizardAction.STATE_BEGIN);
118 try {
119 t.addParam(WizardController.WIZ_PARAMETER_ID, wizard.getId());
120 t.addParam(CreationWizardAction.PARAM_TARGET_ID,
121 request.getParameter(CreationWizardAction.PARAM_TARGET_ID));
122 } catch (DBException ex) {
123 throw new ControllerException("Error querying object for id.", ex);
124 }
125 t.redirectTransition(request, response);
126
127 }
128
129
130 }