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.BeanShellCondition;
09: import org.wings.SComponent;
10: import org.wings.STextArea;
11:
12: /**
13: * The class BeanShellConditionController models the BeanShellContidion by providing a
14: * text-area in which the user can enter the script.
15: *
16: * @author Sebastian Nozzi.
17: */
18: public class BeanShellConditionController extends ConditionController {
19:
20: /** The input field. */
21: private STextArea inputField;
22:
23: /**
24: * Instantiates a new BeanShellConditionController.
25: */
26: public BeanShellConditionController() {
27:
28: // Instantiate a TextArea in which the user can type a BeanShell script.
29: inputField = new STextArea("");
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 java.lang.Object#toString()
46: */
47: public String toString() {
48: return "* BeanShell";
49: }
50:
51: /*
52: * (non-Javadoc)
53: *
54: * @see agent.controller.OperationController#canBeReplacedBy(agent.controller.OperationController)
55: */
56: public boolean canBeReplacedBy(
57: OperationController candidateController) {
58:
59: // Since there is only one BeansShellController in the UI a match is found
60: // as soon as the class is the same.
61: return candidateController instanceof BeanShellConditionController;
62: }
63:
64: /*
65: * (non-Javadoc)
66: *
67: * @see org.osbl.agent.gui.condition.ConditionController#setCondition(org.osbl.agent.model.condition.Condition)
68: */
69: public void setCondition(Condition condition) {
70:
71: // Get the script of the condition and show it in the UI.
72: inputField
73: .setText(((BeanShellCondition) condition).getScript());
74: }
75:
76: /* (non-Javadoc)
77: * @see org.osbl.agent.gui.ConditionController#populateCondition(org.osbl.agent.model.Condition)
78: */
79: protected void populateCondition(Condition condition) {
80:
81: // Set the script in the condition to the text in the UI.
82: ((BeanShellCondition) condition)
83: .setScript(inputField.getText());
84:
85: }
86:
87: }
|