01: package org.osbl.agent.gui.action;
02:
03: import java.util.List;
04:
05: import org.osbl.agent.model.Action;
06: import org.osbl.agent.model.action.SetPropertyAction;
07: import org.osbl.agent.model.action.SetValueAction;
08: import org.wings.SComponent;
09: import org.wings.STextField;
10:
11: /**
12: * The class SetValueActionController models the SetValueAction by providing
13: * an input field in which the user can enter the value to be assigned to the
14: * property.
15: *
16: * @author Sebastian Nozzi.
17: */
18: public class SetValueActionController extends
19: SetPropertyActionController {
20:
21: /** The input field. */
22: protected STextField inputField;
23:
24: /**
25: * Instantiates a new SetValueActionController.
26: */
27: public SetValueActionController() {
28:
29: // Initialize our inputField, we'll be using for the value that the
30: // property will get at Rule run-time.
31: inputField = new STextField();
32:
33: }
34:
35: /* (non-Javadoc)
36: * @see org.osbl.agent.gui.action.SetPropertyActionController#populateComponentList(java.util.List)
37: */
38: protected void populateComponentList(List<SComponent> componentList) {
39:
40: // Populate the componentList with the parent's components first.
41: super .populateComponentList(componentList);
42:
43: // To it, add the inputField we use for user input.
44: componentList.add(inputField);
45: }
46:
47: /* (non-Javadoc)
48: * @see org.osbl.agent.gui.action.SetPropertyActionController#setAction(org.osbl.agent.model.Action)
49: */
50: public void setAction(Action action) {
51:
52: // First let the parent SetProperyActionController set the inherited fields up
53: // acording to the action given (which is, after all, a SetPropertyAction).
54: super .setAction(action);
55:
56: // Get the valueToSet from the Action and show it in the UI.
57: inputField.setText((String) ((SetPropertyAction) action)
58: .getValueToSet());
59: }
60:
61: /* (non-Javadoc)
62: * @see org.osbl.agent.gui.action.SetPropertyActionController#populateAction(org.osbl.agent.model.Action)
63: */
64: protected void populateAction(Action action) {
65:
66: // Let the parent populate the Action with whatever information it manages.
67: super .populateAction(action);
68:
69: // Now, we populate it with the special information managed by this Controller.
70:
71: // Set the valueToSet to the contents of the inputField.
72: ((SetValueAction) action).setValueToSet(inputField.getText());
73:
74: }
75:
76: }
|