1
2
3
4
5
6
7
8
9
10
11 package com.sri.emo.wizard.selection;
12
13 import com.jcorporate.expresso.core.controller.ControllerException;
14 import com.jcorporate.expresso.core.controller.ExpressoRequest;
15 import com.jcorporate.expresso.core.controller.ExpressoResponse;
16 import com.jcorporate.expresso.core.controller.Transition;
17 import com.jcorporate.expresso.core.db.DBException;
18 import com.sri.emo.controller.NodeAction;
19 import com.sri.emo.dbobj.Node;
20 import com.sri.emo.wizard.WizardException;
21 import com.sri.emo.wizard.WizardMonitor;
22 import com.sri.emo.wizard.WizardPage;
23 import com.sri.emo.wizard.defaults.SequentialWizard;
24
25 import java.io.Serializable;
26 import java.util.Map;
27
28 /***
29 * Overrides Sequential Wizard to allow processing of the EMO Decision
30 * Matrix for processing finish.
31 * <p>The Selection Wizard has the following processess:</p>
32 * <p/>
33 * <img src="doc-files/SelectionStates.gif" alt="Selection Wizard State Diagram">
34 * <caption>Selection Wizard State Diagram</caption>
35 * </img>
36 * </p>
37 *
38 * @author Michael Rimov
39 */
40 public class EmoSelectionWizard extends SequentialWizard {
41
42
43 /***
44 *
45 */
46 private static final long serialVersionUID = 1L;
47
48
49 /***
50 * Constructor that the Wizard Factory uses to instantiate
51 * the sequential wizard.
52 *
53 * @param wizMonitor WizardMonitor the Wizard Monitor to use for events.
54 * @param steps WizardPage[] the wizard pages to execute in sequence.
55 */
56 public EmoSelectionWizard(final WizardMonitor wizMonitor, final WizardPage[] steps) {
57 super(wizMonitor, steps);
58 }
59
60 /***
61 * This version returns a <tt>Node<tt> instance if one has
62 * been found.
63 * <p>{@inheritDoc}</p>
64 *
65 * @param src WizardPage the source of the event.
66 * @param data Serializable the data given during wht wizard post.
67 * @param additionalParams anything that the underlying wizard needs. The
68 * values are set by the Application Controller.
69 * @return An instance of a {@link com.sri.emo.dbobj.Node} object
70 * that represents the node the Decision Matrix returned or null if
71 * there was no equivilant data found.
72 * @throws WizardException upon error.
73 */
74 public Object processFinish(final WizardPage src, final Serializable data,
75 final Map additionalParams) throws WizardException {
76
77
78
79 super.processFinish(src, data, additionalParams);
80
81 if (src.getPageErrors() != null && src.getPageErrors().getErrorCount() > 0) {
82 return null;
83 }
84
85
86 Map allData = this.getAllData();
87 String nodeId = (String) allData.get(DisplaySummaryPage.PAGE_ID);
88 String nameId = (String) allData.get(new Integer(NameNodePage.PAGE_ID));
89 Transition cloneNodeTrans = new Transition("clone", "clone",
90 NodeAction.class, NodeAction.DO_CLONE_NODE);
91 cloneNodeTrans.addParam(Node.NODE_ID, nodeId);
92 cloneNodeTrans.addParam(Node.NODE_TITLE, nameId);
93
94
95 try {
96 cloneNodeTrans.redirectTransition((ExpressoRequest) additionalParams.get("request"),
97 (ExpressoResponse) additionalParams.get("response"));
98 } catch (ControllerException ex) {
99 throw new WizardException("Error performing redirect", ex);
100 }
101 return null;
102 }
103
104
105 /***
106 * This particular implementation performs some pre-processing for some
107 * special pages.
108 * <p>{@inheritDoc}</p>
109 *
110 * @param nextPage WizardPage the next page that is about to be displayed.
111 * @param previousPageData Serializable the previously entered data from
112 * the last page where the user clicked 'next'.
113 * @return boolean true if you wish for the user to continue. False if
114 * the page data needs to be vetoed.
115 * @throws WizardException upon error.
116 */
117 protected boolean onNextPage(final WizardPage previousPage,
118 final WizardPage nextPage,
119 final Serializable previousPageData) throws WizardException {
120 try {
121
122
123 if (nextPage instanceof DisplaySummaryPage) {
124 ((DisplaySummaryPage) nextPage).clearCachedNode();
125 } else if (nextPage instanceof NameNodePage) {
126 assert previousPage instanceof DisplaySummaryPage
127 :"Order Error in wizard. Previous page for naming should have been the display results page.";
128
129 NameNodePage theNextPage = (NameNodePage) nextPage;
130 DisplaySummaryPage displaySummaryPage = (DisplaySummaryPage) previousPage;
131 Node selectedNode = displaySummaryPage.getSelectedNode();
132 theNextPage.setSelectedNodeId(selectedNode.getNodeId());
133 }
134
135 } catch (DBException ex) {
136 throw new WizardException("Database Object Query Error", ex);
137 }
138
139 return super.onNextPage(previousPage, nextPage, previousPageData);
140 }
141 }