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.Controller;
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.Input;
17 import com.jcorporate.expresso.core.controller.Output;
18 import com.jcorporate.expresso.core.controller.Transition;
19 import com.jcorporate.expresso.core.db.DBException;
20 import com.jcorporate.expresso.core.dbobj.ValidValue;
21 import com.sri.common.controller.StateHandler;
22 import com.sri.emo.dbobj.Node;
23 import com.sri.emo.dbobj.Part;
24 import com.sri.emo.wizard.creation.model.CreationBean;
25 import com.sri.emo.wizard.creation.model.CreationPartsBean;
26 import com.sri.emo.wizard.creation.model.FieldCompletion;
27
28 import java.util.ArrayList;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Set;
32 import com.sri.emo.wizard.creation.model.*;
33
34
35 /***
36 * @author Michael Rimov
37 */
38 public class PromptChooseParts implements StateHandler {
39
40
41 /***
42 * The name of this state as referred to by the Expresso Controller
43 */
44 public static final String STATE_NAME = "promptChooseParts";
45
46 /***
47 * The description of this state as referred to by the Expresso Controller.
48 */
49 public static final String STATE_DESCRIPTION = "Choose Parts For Wizard";
50
51
52 /***
53 * Parent controller backreference.
54 */
55 private final Controller parent;
56
57 private CreationBeanManager beanManager;
58
59 /***
60 * Constructor that takes the owner controller as a paramter.
61 *
62 * @param owner Controller the owning controller.
63 */
64 public PromptChooseParts(final Controller owner) {
65 parent = owner;
66 beanManager = new CreationBeanManager();
67 }
68
69 /***
70 * Called to handle the request.
71 *
72 * @param request ControllerRequest The Function's ControllerRequest
73 * object.
74 * @param response ControllerResponse The Function's ControllerResponse
75 * object.
76 * @throws DBException upon underlying database exception error.
77 * @throws ControllerException upon underlying ControllerException error.
78 */
79 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
80 ControllerException {
81
82 response.setTitle("Creation Wiz Creator, Part 2");
83
84 List allValidValues = new ArrayList(2);
85 allValidValues.add(new ValidValue(FieldCompletion.NOT_INCLUDED.toString(), "Not Included"));
86 allValidValues.add(new ValidValue(FieldCompletion.WIZARD.toString(), "Allow Creation"));
87
88 if (beanManager.handleSessionTimeout(request, response)) {
89 return;
90 }
91
92 CreationBeans cbs = beanManager.getActionForm(request);
93 /***
94 * @todo rich: make sure that this part works
95 */
96 CreationBean cb = cbs.getCurrentBean();
97 System.out.println("PromptChooseParts. working on bean of type: " + cb.getTargetId() + " part: " + cb.getPartId());
98 Set allParts = cb.getCompletionParts();
99 Node node = new Node();
100 node.setNodeId(cb.getTargetId().toString());
101
102
103
104
105 boolean includedDisabledRadios = false;
106 assert allParts != null;
107 for (Iterator i = allParts.iterator(); i.hasNext();) {
108 CreationPartsBean onePart = (CreationPartsBean) i.next();
109 Part thePart = onePart.getPart();
110
111 Input oneInput = new Input();
112 oneInput.setName(thePart.getPartNum());
113 oneInput.setLabel(thePart.getPartLabel());
114 oneInput.setValidValues(allValidValues);
115
116
117 if (onePart.getFieldCompletion() == null) {
118
119 if (thePart.isOwnedAttribute() && node.getAttributes(thePart.getPartType()).length > 0) {
120
121 oneInput.setDefaultValue(FieldCompletion.NOT_INCLUDED.toString());
122 } else if (thePart.isSharedNodeAttrib() && node.getRelatedNodes(thePart.getNodeRelation(),
123 thePart.getPartType()).length > 0) {
124
125 oneInput.setDefaultValue(FieldCompletion.NOT_INCLUDED.toString());
126 } else {
127 oneInput.setDefaultValue(FieldCompletion.WIZARD.toString());
128 }
129 } else if (onePart.getFieldCompletion() == FieldCompletion.WIZARD) {
130 oneInput.setDefaultValue(FieldCompletion.WIZARD.toString());
131 } else {
132 oneInput.setDefaultValue(FieldCompletion.NOT_INCLUDED.toString());
133 }
134
135
136
137
138
139
140
141
142
143
144 response.add(oneInput);
145
146 }
147
148
149 Transition back = new Transition(PromptChooseNode.STATE_NAME, parent);
150 back.setName("back");
151 back.setLabel("Back");
152 response.add(back);
153
154 Transition next = new Transition(DoChooseParts.STATE_NAME, parent);
155 next.setName("next");
156 next.setLabel("Next");
157 response.add(next);
158
159
160 if (includedDisabledRadios) {
161 response.add(new Output("includedDisabledRadios", node.getNodeTitle()));
162 }
163 }
164 }