1
2
3
4
5
6
7
8
9
10 package com.sri.emo.wizard.completion.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.CompletionWizardAction;
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 CompletionEditor extends AbstractComponentController implements IWizardManager {
37
38
39 /***
40 *
41 */
42 private static final long serialVersionUID = 1L;
43
44 /***
45 * Default constructor. Creates all the appropriate states for the
46 * controller.
47 */
48 public CompletionEditor() {
49 super(EmoSchema.class);
50
51 this.addStateHandler(PromptChooseNode.STATE_NAME, PromptChooseNode.STATE_DESCRIPTION,
52 PromptChooseNode.class);
53
54 this.setInitialState(PromptChooseNode.STATE_NAME);
55
56 this.addStateHandler(DoChooseNodeStep.STATE_NAME, DoChooseNodeStep.STATE_DESCRIPTION, DoChooseNodeStep.class);
57
58 this.addStateHandler(PromptChooseParts.STATE_NAME, PromptChooseParts.STATE_DESCRIPTION,
59 PromptChooseParts.class);
60
61 this.addStateHandler(DoChooseParts.STATE_NAME, DoChooseParts.STATE_DESCRIPTION, DoChooseParts.class);
62
63 this.addStateHandler(PromptChooseCriteria.STATE_NAME, PromptChooseCriteria.STATE_DESCRIPTION,
64 PromptChooseCriteria.class);
65
66 this.addStateHandler(DoChooseCriteria.STATE_NAME, DoChooseCriteria.STATE_DESCRIPTION, DoChooseCriteria.class);
67
68 this.addStateHandler(PromptEditWizard.STATE_NAME, PromptEditWizard.STATE_DESCRIPTION, PromptEditWizard.class);
69
70 this.addStateHandler(DoCancel.STATE_NAME, DoCancel.STATE_DESCRIPTION, DoCancel.class);
71 }
72
73 /***
74 * Begins an 'add' end-user transaction to create a new wizard.
75 *
76 * @param request ExpressoRequest the request object.
77 * @param response ExpressoResponse the response object.
78 * @throws ControllerException
79 */
80 public void add(final ExpressoRequest request, final ExpressoResponse response) throws ControllerException {
81
82
83 ICompletionBeanManager beanManager = (ICompletionBeanManager) this.locator().locate(
84 ICompletionBeanManager.class);
85 beanManager.destroyActionForm(request);
86
87
88 Transition t = new Transition(PromptChooseNode.STATE_NAME, this);
89 t.redirectTransition(request, response);
90 }
91
92 /***
93 * Begins an 'edit' end-user transaction to edit an existing wizard.
94 *
95 * @param wizard The WizardDefinition to edit.
96 * @param request ExpressoRequest the request object.
97 * @param response ExpressoResponse the response object.
98 * @throws ControllerException upon error.
99 * @todo Implement this com.sri.emo.dbobj.IWizardManager method
100 */
101 public void edit(final WizDefinition wizard, final ExpressoRequest request,
102 final ExpressoResponse response) throws ControllerException {
103 Transition t = new Transition(PromptEditWizard.STATE_NAME, this);
104 try {
105 t.addParam(WizardController.WIZ_PARAMETER_ID, wizard.getId());
106 } catch (DBException ex) {
107 throw new ControllerException("Error querying object for id.", ex);
108 }
109 t.redirectTransition(request, response);
110 }
111
112 /***
113 * Runs the wizard that the manager is associated with.
114 *
115 * @param wizard WizDefinition
116 * @param request ExpressoRequest
117 * @param response ExpressoResponse
118 * @throws ControllerException
119 */
120 public void run(final WizDefinition wizard, final ExpressoRequest request, final ExpressoResponse response) throws
121 ControllerException {
122 Transition t = new Transition("", "", CompletionWizardAction.class, CompletionWizardAction.STATE_BEGIN);
123 try {
124 t.addParam(WizardController.WIZ_PARAMETER_ID, wizard.getId());
125 t.addParam(CompletionWizardAction.PARAM_TARGET_ID,
126 request.getParameter(CompletionWizardAction.PARAM_TARGET_ID));
127 } catch (DBException ex) {
128 throw new ControllerException("Error querying object for id.", ex);
129 }
130 t.redirectTransition(request, response);
131
132 }
133
134
135 }