|
@@ -37,13 +37,16 @@ import java.beans.PropertyChangeListener;
|
37
|
37
|
import javax.swing.ButtonGroup;
|
38
|
38
|
import javax.swing.JPanel;
|
39
|
39
|
import javax.swing.JRadioButton;
|
|
40
|
+import javax.swing.event.DocumentEvent;
|
|
41
|
+import javax.swing.event.DocumentListener;
|
40
|
42
|
|
41
|
43
|
import net.miginfocom.swing.MigLayout;
|
42
|
44
|
|
43
|
45
|
/**
|
44
|
46
|
* Action conditions tree panel.
|
45
|
47
|
*/
|
46
|
|
-public class ActionConditionsTreePanel extends JPanel implements ActionListener, PropertyChangeListener {
|
|
48
|
+public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
|
49
|
+ PropertyChangeListener, DocumentListener {
|
47
|
50
|
|
48
|
51
|
/**
|
49
|
52
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -97,6 +100,7 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
97
|
100
|
oneButton.addActionListener(this);
|
98
|
101
|
customButton.addActionListener(this);
|
99
|
102
|
rule.addPropertyChangeListener("validationResult", this);
|
|
103
|
+ rule.getDocument().addDocumentListener(this);
|
100
|
104
|
}
|
101
|
105
|
|
102
|
106
|
/** Lays out the components. */
|
|
@@ -120,27 +124,42 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
120
|
124
|
} else {
|
121
|
125
|
type = treeFactory.getType();
|
122
|
126
|
}
|
123
|
|
-
|
|
127
|
+
|
124
|
128
|
switch (type) {
|
125
|
129
|
case DISJUNCTION:
|
126
|
130
|
oneButton.setSelected(true);
|
127
|
131
|
rule.setText("");
|
128
|
132
|
rule.setEnabled(false);
|
129
|
|
- firePropertyChange("validationResult", true, true);
|
130
|
133
|
break;
|
131
|
134
|
case CUSTOM:
|
132
|
135
|
customButton.setSelected(true);
|
133
|
|
- rule.setText(treeFactory.getConditionTree(conditionCount).toString());
|
|
136
|
+ rule.setText(treeFactory.getConditionTree(conditionCount).
|
|
137
|
+ toString());
|
134
|
138
|
rule.setEnabled(true);
|
135
|
|
- rule.checkError();
|
136
|
139
|
break;
|
137
|
140
|
default:
|
138
|
141
|
allButton.setSelected(true);
|
139
|
142
|
rule.setText("");
|
140
|
143
|
rule.setEnabled(false);
|
141
|
|
- firePropertyChange("validationResult", true, true);
|
142
|
144
|
break;
|
143
|
145
|
}
|
|
146
|
+
|
|
147
|
+ sortTreeFactory();
|
|
148
|
+ }
|
|
149
|
+
|
|
150
|
+ /** Sorts the tree factory out. */
|
|
151
|
+ private void sortTreeFactory() {
|
|
152
|
+ if (group.getSelection().equals(allButton.getModel())) {
|
|
153
|
+ treeFactory = new ConditionTreeFactory.ConjunctionFactory();
|
|
154
|
+ firePropertyChange("validationResult", true, true);
|
|
155
|
+ } else if (group.getSelection().equals(oneButton.getModel())) {
|
|
156
|
+ treeFactory = new ConditionTreeFactory.DisjunctionFactory();
|
|
157
|
+ firePropertyChange("validationResult", true, true);
|
|
158
|
+ } else {
|
|
159
|
+ treeFactory =
|
|
160
|
+ new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.getText()));
|
|
161
|
+ rule.checkError();
|
|
162
|
+ }
|
144
|
163
|
}
|
145
|
164
|
|
146
|
165
|
/**
|
|
@@ -151,6 +170,7 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
151
|
170
|
@Override
|
152
|
171
|
public void actionPerformed(final ActionEvent e) {
|
153
|
172
|
rule.setEnabled(e.getSource().equals(customButton));
|
|
173
|
+ sortTreeFactory();
|
154
|
174
|
}
|
155
|
175
|
|
156
|
176
|
/** {@inheritDoc} */
|
|
@@ -170,9 +190,6 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
170
|
190
|
*/
|
171
|
191
|
public ConditionTreeFactoryType getRuleType(final int conditionCount) {
|
172
|
192
|
if (conditionCount >= 2) {
|
173
|
|
- final ConditionTree tree =
|
174
|
|
- ConditionTree.parseString(rule.getText());
|
175
|
|
- treeFactory = ConditionTreeFactory.getFactory(tree, conditionCount);
|
176
|
193
|
return treeFactory.getType();
|
177
|
194
|
} else {
|
178
|
195
|
return ConditionTreeFactoryType.CONJUNCTION;
|
|
@@ -182,10 +199,13 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
182
|
199
|
/**
|
183
|
200
|
* Returns the current custom rule.
|
184
|
201
|
*
|
|
202
|
+ * @param conditionCount number of conditions
|
|
203
|
+ *
|
185
|
204
|
* @return Custom rule
|
186
|
205
|
*/
|
187
|
|
- public String getRule() {
|
188
|
|
- return rule.getText();
|
|
206
|
+ public ConditionTree getRule(final int conditionCount) {
|
|
207
|
+ treeFactory.getConditionTree(conditionCount);
|
|
208
|
+ return treeFactory.getConditionTree(conditionCount);
|
189
|
209
|
}
|
190
|
210
|
|
191
|
211
|
/**
|
|
@@ -205,11 +225,32 @@ public class ActionConditionsTreePanel extends JPanel implements ActionListener,
|
205
|
225
|
/** {@inheritDoc} */
|
206
|
226
|
@Override
|
207
|
227
|
public void propertyChange(final PropertyChangeEvent evt) {
|
208
|
|
- firePropertyChange("validationResult", evt.getOldValue(), evt.getNewValue());
|
|
228
|
+ firePropertyChange("validationResult", evt.getOldValue(),
|
|
229
|
+ evt.getNewValue());
|
209
|
230
|
}
|
210
|
|
-
|
|
231
|
+
|
211
|
232
|
/** Validates the conditions. */
|
212
|
233
|
public void validateConditions() {
|
213
|
234
|
selectTreeButton();
|
214
|
235
|
}
|
|
236
|
+
|
|
237
|
+ /** {@inheritDoc} */
|
|
238
|
+ @Override
|
|
239
|
+ public void insertUpdate(final DocumentEvent e) {
|
|
240
|
+ treeFactory =
|
|
241
|
+ new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.getText()));
|
|
242
|
+ }
|
|
243
|
+
|
|
244
|
+ /** {@inheritDoc} */
|
|
245
|
+ @Override
|
|
246
|
+ public void removeUpdate(final DocumentEvent e) {
|
|
247
|
+ treeFactory =
|
|
248
|
+ new ConditionTreeFactory.CustomFactory(ConditionTree.parseString(rule.getText()));
|
|
249
|
+ }
|
|
250
|
+
|
|
251
|
+ /** {@inheritDoc} */
|
|
252
|
+ @Override
|
|
253
|
+ public void changedUpdate(final DocumentEvent e) {
|
|
254
|
+ //Ignore
|
|
255
|
+ }
|
215
|
256
|
}
|