1 package com.sri.emo.wizard.selection.management;
2
3 import com.jcorporate.expresso.core.controller.*;
4 import com.jcorporate.expresso.core.db.DBException;
5 import com.sri.common.controller.StateHandler;
6 import com.sri.emo.dbobj.StepAttributes;
7 import com.sri.emo.dbobj.WizStep;
8
9
10 /***
11 * This handler is called when the user indicates that the picklist to use
12 * is based on an attribute defined in the model. It displays the common attributes
13 * of all wizard steps, as well as a list of all fields available for viewing.
14 *
15 * @author Michael Rimov
16 */
17 public class PromptModelField extends EditFinalState implements StateHandler {
18
19 /***
20 * Constant for access to this state.
21 */
22 public static final String STATE_NAME = "promptModelField";
23
24 /***
25 * Constant for description of this state.
26 */
27 public static final String STATE_DESCRIPTION = "Select Model Field";
28
29
30 /***
31 * Constructor that takes a wizard id and a step id and forms its internal
32 * state, allowing for easy retrieval of database objects from subclasses.
33 *
34 * @param wizId The Wizard ID (usually an integer)
35 * @param stepId The Step Id. May be null if there is no step definition.
36 * @throws DBException upon error.
37 */
38 public PromptModelField(final String wizId, final String stepId) throws DBException {
39 super(wizId, stepId);
40 }
41
42
43 /***
44 * Called to handle the request.
45 *
46 * @param request ExpressoRequest The Function's ExpressoRequest
47 * object.
48 * @param response ExpressoResponse The Function's ExpressoResponse
49 * object.
50 * @throws DBException upon underlying database exception error.
51 * @throws ControllerException upon underlying ControllerException error.
52 */
53 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response)
54 throws DBException, ControllerException {
55
56 ErrorCollection ec = request.getErrorCollection();
57 if (ec == null) {
58 ec = new ErrorCollection();
59 }
60
61 WizStep step = getStepFromParameters(request, ec);
62 if (ec.getErrorCount() > 0) {
63 response.saveErrors(ec);
64 }
65
66 String title = "Select Model Field for " + getStepTitle();
67 response.setTitle(title);
68
69 addStepTypeLabel(response, step);
70
71 if (isEditing()) {
72 Transition edit = buildEditTypeTransition(step);
73 response.add(edit);
74 }
75
76
77 Transition save = buildSaveAndReturnTransition(step);
78 save.addParam(StepAttributes.ATTRIBUTE_MODEL, step.getStepAttribute(StepAttributes.ATTRIBUTE_MODEL));
79 response.add(save);
80
81
82 Block commonDef = renderCommonControls(step, request, response);
83 response.add(commonDef);
84
85
86
87 Input modelField = new Input();
88 modelField.setName(StepAttributes.ATTRIBUTE_MODEL_FIELD);
89 modelField.setLabel("Picklist:");
90 modelField.setDefaultValue(response);
91 modelField.setValidValues(step.getPartsValidValues());
92 modelField.setName(StepAttributes.ATTRIBUTE_MODEL_FIELD);
93 commonDef.add(modelField);
94
95 response.add(buildCancelTransition());
96 }
97 }