01: package org.osbl.agent.gui.action;
02:
03: import java.util.List;
04:
05: import org.osbl.agent.gui.ActionController;
06: import org.osbl.agent.gui.OperationController;
07: import org.osbl.agent.model.Action;
08: import org.osbl.agent.model.action.BeanShellAction;
09: import org.wings.SComponent;
10: import org.wings.STextArea;
11:
12: /**
13: * The Class BeanShellActionController models a BeanShellAction by allowing the
14: * user to enter/modify a Beanshell script in the UI.
15: *
16: * @author Sebastian Nozzi.
17: */
18: public class BeanShellActionController extends ActionController {
19:
20: /** The input field in which the script can be entered. */
21: private STextArea inputField;
22:
23: /**
24: * Instantiates a new BeanShellActionController.
25: */
26: public BeanShellActionController() {
27: // Initialize our inputField, in which the user can type in a BeanShell script.
28: inputField = new STextArea("");
29: }
30:
31: /*
32: * (non-Javadoc)
33: *
34: * @see agent.controller.OperationController#getComponents()
35: */
36: protected void populateComponentList(List<SComponent> componentList) {
37:
38: componentList.add(inputField);
39: }
40:
41: /*
42: * (non-Javadoc)
43: *
44: * @see java.lang.Object#toString()
45: */
46: public String toString() {
47: return "* BeanShell";
48: }
49:
50: /*
51: * (non-Javadoc)
52: *
53: * @see agent.controller.OperationController#canBeReplacedBy(agent.controller.OperationController)
54: */
55: public boolean canBeReplacedBy(
56: OperationController candidateController) {
57:
58: // Since there is only one BeanShellActioController it's enough if the candidateController
59: // is of this same class.
60: return candidateController instanceof BeanShellActionController;
61: }
62:
63: /*
64: * (non-Javadoc)
65: *
66: * @see org.osbl.agent.gui.action.ActionController#setAction(org.osbl.agent.model.action.Action)
67: */
68: public void setAction(Action action) {
69:
70: // The text of the inputField is set to the BeanShellAction's script
71: inputField.setText(((BeanShellAction) action).getScript());
72: }
73:
74: /* (non-Javadoc)
75: * @see org.osbl.agent.gui.ActionController#populateAction(org.osbl.agent.model.Action)
76: */
77: protected void populateAction(Action action) {
78:
79: // The script in the BeanShellAction is set to the inputField's text.
80: ((BeanShellAction) action).setScript(inputField.getText());
81: }
82:
83: }
|