01: package org.osbl.agent.gui.condition;
02:
03: import java.util.List;
04:
05: import org.osbl.agent.gui.ConditionController;
06: import org.osbl.agent.gui.OperationController;
07: import org.osbl.agent.model.Condition;
08: import org.osbl.agent.model.condition.OgnlCondition;
09: import org.wings.SComponent;
10: import org.wings.STextField;
11:
12: /**
13: * The class OgnlConditionController models the OgnlCondition, presenting the user
14: * an input-field in which the OGNL expression can be entered.
15: *
16: * @author Sebastian Nozzi.
17: */
18: public class OgnlConditionController extends ConditionController {
19:
20: /** The input field. */
21: private STextField inputField;
22:
23: /**
24: * Instantiates a new ognl condition controller.
25: */
26: public OgnlConditionController() {
27:
28: // Here the user can type an OGNL expression.
29: inputField = new STextField("");
30: }
31:
32: /*
33: * (non-Javadoc)
34: *
35: * @see agent.controller.OperationController#getComponents()
36: */
37: protected void populateComponentList(List<SComponent> componentList) {
38:
39: componentList.add(inputField);
40: }
41:
42: /*
43: * (non-Javadoc)
44: *
45: * @see org.osbl.agent.gui.condition.ConditionController#setCondition(org.osbl.agent.model.condition.Condition)
46: */
47: public void setCondition(Condition condition) {
48:
49: // Show the expression stored in the OgnlCondition and show it in the UI.
50: inputField.setText(((OgnlCondition) condition).getExpression());
51: }
52:
53: /*
54: * (non-Javadoc)
55: *
56: * @see java.lang.Object#toString()
57: */
58: public String toString() {
59: return "* Ognl";
60: }
61:
62: /*
63: * (non-Javadoc)
64: *
65: * @see agent.controller.OperationController#canBeReplacedBy(agent.controller.OperationController)
66: */
67: public boolean canBeReplacedBy(
68: OperationController candidateController) {
69: // Since there is only one OgnlConditionController it's enough if the
70: // classes match to be replaced.
71: return candidateController instanceof OgnlConditionController;
72: }
73:
74: /* (non-Javadoc)
75: * @see org.osbl.agent.gui.ConditionController#populateCondition(org.osbl.agent.model.Condition)
76: */
77: protected void populateCondition(Condition condition) {
78: // Set the expression in the OgnlCondition to the text in the inputField.
79: ((OgnlCondition) condition).setExpression(inputField.getText());
80: }
81:
82: }
|