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 import java.util.List;
10
11 /***
12 * Prompts for the type of text entry available for the user.
13 *
14 * @author Michael Rimov
15 */
16 public class PromptTextEntry extends EditFinalState implements StateHandler {
17 /***
18 * Constant for access to this state.
19 */
20 public static final String STATE_NAME = "promptTextEntry";
21
22 /***
23 * Constant for description of this state.
24 */
25 public static final String STATE_DESCRIPTION = "Define Text Entry";
26
27
28 /***
29 * Constructor that takes a wizard id and step id to handle the state.
30 *
31 * @param wizId String the wizard id.
32 * @param stepId String the wizard's step id (may be null for new steps)
33 * @throws DBException upon error.
34 */
35 public PromptTextEntry(final String wizId, final String stepId) throws DBException {
36 super(wizId, stepId);
37 }
38
39 /***
40 * Called to handle the request.
41 *
42 * @param request ExpressoRequest The Function's ExpressoRequest
43 * object.
44 * @param response ExpressoResponse The Function's ExpressoResponse
45 * object.
46 * @throws DBException upon underlying database exception error.
47 * @throws ControllerException upon underlying ControllerException error.
48 * @todo Implement this com.sri.common.controller.StateHandler method
49 */
50 public void handleRequest(final ExpressoRequest request, final ExpressoResponse response) throws DBException,
51 ControllerException {
52 String title = "Define free-text entry style for " + getStepTitle();
53 response.setTitle(title);
54 response.add(new Output("pageTitle", title));
55
56
57 ErrorCollection ec = request.getErrorCollection();
58 if (ec == null) {
59 ec = new ErrorCollection();
60 }
61
62 WizStep step = getStepFromParameters(request, ec);
63 if (ec.getErrorCount() > 0) {
64 response.saveErrors(ec);
65 }
66
67
68 Block commonDef = renderCommonControls(step, request, response);
69 response.add(commonDef);
70
71
72 addStepTypeLabel(response, step);
73 if (isEditing()) {
74 Transition edit = buildEditTypeTransition(step);
75 response.add(edit);
76 }
77
78
79 Transition save = buildSaveAndReturnTransition(step);
80 response.add(save);
81
82
83 response.add(buildCancelTransition());
84
85
86 Input textEntry = new Input();
87 textEntry.setName(StepAttributes.ATTRIBUTE_TEXT_STYLE);
88
89 textEntry.setValidValues((List) step.getTextStyleValidValues());
90 String defaultValue = step.getStepAttribute(StepAttributes.ATTRIBUTE_TEXT_STYLE);
91 if (defaultValue == null) {
92 textEntry.setDefaultValue(WizStep.TEXT_VV_SINGLELINE);
93 } else {
94 textEntry.setDefaultValue(step.getStepAttribute(StepAttributes.ATTRIBUTE_TEXT_STYLE));
95 }
96 response.add(textEntry);
97 }
98
99
100 }