Browse Source

fixes issue 1027

git-svn-id: http://svn.dmdirc.com/trunk@4500 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Gregory Holmes 16 years ago
parent
commit
b604e578ec

+ 9
- 1
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionEditorPanel.java View File

@@ -160,23 +160,31 @@ public class ActionConditionEditorPanel extends JPanel implements ActionListener
160 160
     
161 161
     /** Handles the argument changing. */
162 162
     private void handleArgumentChange() {
163
-        System.out.println(condition.getArg() + " => " + arguments.getSelectedIndex());
164 163
         condition.setArg(arguments.getSelectedIndex());
164
+        populateComponents();
165
+        components.setEnabled(true);
165 166
         components.setSelectedItem(null);
166 167
         comparisons.setSelectedItem(null);
168
+        comparisons.setEnabled(false);
167 169
         target.setText(null);
170
+        target.setEnabled(false);
168 171
     }
169 172
     
170 173
     /** Handles the component changing. */
171 174
     private void handleComponentChange() {
172 175
         condition.setComponent((ActionComponent) components.getSelectedItem());
176
+        populateComparisons();
177
+        comparisons.setEnabled(true);
173 178
         comparisons.setSelectedItem(null);
174 179
         target.setText(null);
180
+        target.setEnabled(false);
175 181
     }
176 182
     
177 183
     /** Handles the comparison changing. */
178 184
     private void handleComparisonChange() {
179 185
         condition.setComparison((ActionComparison) comparisons.getSelectedItem());
186
+        populateTarget();
187
+        target.setEnabled(true);
180 188
         target.setText(null);
181 189
     }
182 190
 

+ 2
- 2
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionsPanel.java View File

@@ -175,7 +175,7 @@ public class ActionConditionsPanel extends JPanel implements ActionListener, Pro
175 175
      * 
176 176
      * @return condition type
177 177
      */
178
-    public ConditionTreeFactoryType getConditionType() {
178
+    public ConditionTreeFactoryType getConditionTreeType() {
179 179
         return tree.getRuleType(list.getConditions().size());
180 180
     }
181 181
     
@@ -185,7 +185,7 @@ public class ActionConditionsPanel extends JPanel implements ActionListener, Pro
185 185
      * @return condition tree
186 186
      */
187 187
     public ConditionTree getConditionTree() {
188
-        return ConditionTree.parseString(tree.getRule());
188
+        return tree.getRule(list.getConditions().size());
189 189
     }
190 190
     
191 191
     /**

+ 54
- 13
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionConditionsTreePanel.java View File

@@ -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
 }

+ 25
- 0
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionEditorDialog.java View File

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.ui.swing.dialogs.actioneditor;
24 24
 
25 25
 import com.dmdirc.actions.Action;
26
+import com.dmdirc.actions.ConditionTreeFactory.ConditionTreeFactoryType;
26 27
 import com.dmdirc.ui.swing.components.StandardDialog;
27 28
 
28 29
 import java.awt.Window;
@@ -233,12 +234,36 @@ public class ActionEditorDialog extends StandardDialog implements ActionListener
233 234
             showSubstitutions.setText(substitutions.isVisible() ? "Hide Substitutions"
234 235
                     : "Show Substitutions");
235 236
         } else if (e.getSource().equals(getOkButton())) {
237
+            save();
236 238
             dispose();
237 239
         } else if (e.getSource().equals(getCancelButton())) {
238 240
             dispose();
239 241
         }
240 242
     }
241 243
 
244
+    /** Saves the action being edited. */
245
+    private void save() {
246
+        name.getActionName();
247
+        triggers.getTriggers();
248
+        response.getResponse();
249
+        response.getFormatter();
250
+        conditions.getConditions();
251
+        conditions.getConditionTree();
252
+        if (action == null) {
253
+            new Action(group, name.getActionName(), triggers.getTriggers(),
254
+                    response.getResponse(), conditions.getConditions(),
255
+                    conditions.getConditionTree(), response.getFormatter());
256
+        } else {
257
+            action.setName(name.getActionName());
258
+            action.setConditionTree(conditions.getConditionTree());
259
+            action.setConditions(conditions.getConditions());
260
+            action.setNewFormat(response.getFormatter());
261
+            action.setResponse(response.getResponse());
262
+            action.setTriggers(triggers.getTriggers());
263
+            action.save();
264
+        }
265
+    }
266
+
242 267
     /** @{inheritDoc} */
243 268
     @Override
244 269
     public void propertyChange(final PropertyChangeEvent evt) {

+ 2
- 2
src/com/dmdirc/ui/swing/dialogs/actioneditor/ActionResponsePanel.java View File

@@ -130,8 +130,8 @@ public class ActionResponsePanel extends JPanel {
130 130
      * 
131 131
      * @return Response text
132 132
      */
133
-    public String getResponse() {
134
-        return response.getText();
133
+    public String[] getResponse() {
134
+        return response.getText().split("\n");
135 135
     }
136 136
     
137 137
     /**

Loading…
Cancel
Save