1
2
3
4
5
6 package net.kwfgrid.gwui.gui;
7
8 import net.kwfgrid.gworkflowdl.protocol.structure.*;
9 import net.kwfgrid.gworkflowdl.structure.*;
10 import net.kwfgrid.gwui.workflow.XMLUtilities;
11
12 import org.glassbox.Theme;
13 import org.glassbox.gui.*;
14 import org.glassbox.executor.Executor;
15
16 import java.awt.GridBagLayout;
17 import java.awt.GridBagConstraints;
18 import java.awt.Insets;
19 import java.awt.event.ActionEvent;
20 import java.awt.event.ActionListener;
21 import java.util.*;
22 import javax.swing.*;
23 import javax.swing.border.TitledBorder;
24
25 /***
26 Abstract super class of an editor for editing the description of a place, transition or a workflow.
27 */
28 public class OperationObjectEditor extends AbstractWorkflowElementEditor implements AutoResetTextArea.TextProvider, ActionListener {
29 private static final String SET_COMMAND = "set";
30 private static final String REVERT_COMMAND = "revert";
31 private static final String REMOVE_COMMAND = "remove";
32
33 private JComponent _view;
34 private JButton _removebutton;
35 private JTextArea _xmlarea;
36 private JButton _setbutton;
37 private JButton _revertbutton;
38
39 /***
40 Constructor.
41 */
42 public OperationObjectEditor(Executor executor, ProtocolWorkflow workflow, ProtocolTransition transition) {
43 super(executor, workflow, transition);
44 _view = null;
45 _removebutton = null;
46 _xmlarea = null;
47 _setbutton = null;
48 _revertbutton = null;
49 }
50
51 public void actionPerformed(ActionEvent e) {
52 if (SET_COMMAND.equals(e.getActionCommand())) {
53 final String xml = _xmlarea.getText();
54 setPerformingTask(true);
55 getExecutor().execute(new GUIMethodCallTask("Setting new generic operation ...",
56 getExecutor(),
57 OperationObjectEditor.this) {
58 protected void execute() throws WorkflowFormatException {
59
60
61 Operation o = Factory.newOperation();
62
63 Transition transition = (Transition)getElement();
64 transition.setOperation(o);
65 }
66 });
67 } else if (REVERT_COMMAND.equals(e.getActionCommand())) {
68 _xmlarea.setText(getValidText());
69 } else if (REMOVE_COMMAND.equals(e.getActionCommand())) {
70 setPerformingTask(true);
71 getExecutor().execute(new GUIMethodCallTask("Making selected transition abstract ...",
72 getExecutor(),
73 OperationObjectEditor.this) {
74 protected void execute() {
75 Operation o = Factory.newOperation();
76 ((Transition)getElement()).setOperation(o);
77 }
78 });
79 }
80 }
81
82 /***
83 Get the valid text for the text area. This will replaced the entered text on focus-lost.
84 */
85 public String getValidText() {
86 Transition transition = (Transition)getElement();
87
88
89 return "";
90 }
91
92 /***
93 Updates the state of this view.
94 */
95 protected void updateState() {
96 _xmlarea.setEnabled(isEnabled() && isEditable() && !isPerformingTask());
97 _setbutton.setEnabled(isEnabled() && isEditable() && !isPerformingTask());
98 _revertbutton.setEnabled(isEnabled() && isEditable() && !isPerformingTask());
99 _removebutton.setEnabled(isEnabled() && isEditable() && !isPerformingTask());
100 }
101
102 /***
103 Updates this view.
104 */
105 protected void updateView() {
106 updateState();
107 _xmlarea.setText(getValidText());
108
109
110
111
112 }
113
114 public JComponent getView() {
115 if (_view==null) {
116 _removebutton = new JButton("revert to abstract operation");
117 _removebutton.addActionListener(this);
118 _removebutton.setActionCommand(REMOVE_COMMAND);
119 _setbutton = new JButton("set");
120 _setbutton.setActionCommand(SET_COMMAND);
121 _setbutton.addActionListener(this);
122 _revertbutton = new JButton("revert");
123 _revertbutton.setActionCommand(REVERT_COMMAND);
124 _revertbutton.addActionListener(this);
125 _xmlarea = new JTextArea(10, 40);
126
127 _view = new JPanel();
128 _view.setBorder(createBorder("Generic Operation"));
129 _view.setLayout(new GridBagLayout());
130 GridBagConstraints c = new GridBagConstraints();
131
132 c.insets = new Insets(5, 0, 0, 0);
133 c.weightx = 1.0;
134 c.weighty = 0.0;
135 c.gridx = 0;
136 c.gridy = 0;
137 c.anchor = GridBagConstraints.WEST;
138 c.fill = GridBagConstraints.NONE;
139 c.gridwidth = GridBagConstraints.REMAINDER;
140
141 _view.add(new JLabel("XML Description"), c);
142
143 c.fill = GridBagConstraints.BOTH;
144 c.anchor = GridBagConstraints.CENTER;
145 c.insets = new Insets(2, 0, 0, 0);
146 c.weighty = 1.0;
147 c.gridy = 1;
148 c.gridwidth = GridBagConstraints.REMAINDER;
149
150 _view.add(new JScrollPane(_xmlarea), c);
151
152 c.insets = new Insets(5, 0, 0, 0);
153 c.weightx = 0.0;
154 c.weighty = 0.0;
155 c.gridy = 2;
156 c.fill = GridBagConstraints.NONE;
157 c.anchor = GridBagConstraints.EAST;
158 c.gridwidth = 1;
159
160 _view.add(_revertbutton, c);
161
162 c.gridx = 1;
163 c.gridwidth = GridBagConstraints.REMAINDER;
164
165 _view.add(_setbutton, c);
166
167 c.gridy = 3;
168 c.gridx = 0;
169 c.fill = GridBagConstraints.HORIZONTAL;
170 c.insets = new Insets(5, 0, 0, 0);
171 c.weighty = 0.0;
172
173 _view.add(new JSeparator(), c);
174
175 c.gridy = 4;
176 c.fill = GridBagConstraints.NONE;
177 c.anchor = GridBagConstraints.WEST;
178 c.fill = GridBagConstraints.NONE;
179
180 _view.add(_removebutton, c);
181
182 updateView();
183 }
184 return _view;
185 }
186 }