소스 검색

Fixes issue 3724: AED shows validation error on name when editing an existing action

Change-Id: Ie1ac0a8eb2c05403f4a926479f85cf79e85b8203
Reviewed-on: http://gerrit.dmdirc.com/845
Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.3
Gregory Holmes 14 년 전
부모
커밋
732bbc91a9

+ 10
- 0
src/com/dmdirc/addons/ui_swing/components/validating/ValidatingJTextField.java 파일 보기

@@ -93,6 +93,16 @@ public class ValidatingJTextField extends JComponent implements DocumentListener
93 93
         textField.getDocument().addDocumentListener(this);
94 94
     }
95 95
 
96
+    /**
97
+     * Updates the validator for this textfield.
98
+     *
99
+     * @param validator new validator
100
+     */
101
+    public void setValidator(final Validator<String> validator) {
102
+        this.validator = validator;
103
+        checkError();
104
+    }
105
+
96 106
     /**
97 107
      * Checks the text for errors and sets the error state accordingly.
98 108
      */

+ 17
- 9
src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionNamePanel.java 파일 보기

@@ -52,7 +52,7 @@ public class ActionNamePanel extends JPanel implements PropertyChangeListener {
52 52
      */
53 53
     private static final long serialVersionUID = 1;
54 54
     /** Original name. */
55
-    private final String originalName;
55
+    private String existingName;
56 56
     /** Action name field. */
57 57
     private ValidatingJTextField name;
58 58
     /** Action group. */
@@ -77,9 +77,9 @@ public class ActionNamePanel extends JPanel implements PropertyChangeListener {
77 77
         super();
78 78
 
79 79
         if (name == null) {
80
-            this.originalName = "";
80
+            this.existingName = "";
81 81
         } else {
82
-            this.originalName = name;
82
+            this.existingName = name;
83 83
         }
84 84
         this.group = ActionManager.getGroup(group);
85 85
 
@@ -92,10 +92,18 @@ public class ActionNamePanel extends JPanel implements PropertyChangeListener {
92 92
     /**
93 93
      * Sets the action name.
94 94
      * 
95
-     * @param name new name
95
+     * @param newName new name
96 96
      */
97
-    void setActionName(final String name) {
98
-        this.name.setText(name);
97
+    @SuppressWarnings("unchecked")
98
+    void setActionName(final String newName) {
99
+        if (newName == null) {
100
+            this.existingName = "";
101
+        } else {
102
+            this.existingName = newName;
103
+        }
104
+        name.setValidator(new ValidatorChain<String>(new FileNameValidator(),
105
+                new ActionNameValidator(group, existingName)));
106
+        this.name.setText(newName);
99 107
     }
100 108
 
101 109
     /** Validates the name. */
@@ -106,9 +114,9 @@ public class ActionNamePanel extends JPanel implements PropertyChangeListener {
106 114
     /** Initialises the components. */
107 115
     @SuppressWarnings("unchecked")
108 116
     private void initComponents() {
109
-        name = new ValidatingJTextField(new JTextField(originalName), 
117
+        name = new ValidatingJTextField(new JTextField(existingName),
110 118
                 new ValidatorChain<String>(new FileNameValidator(),
111
-                new ActionNameValidator(group)));
119
+                new ActionNameValidator(group, existingName)));
112 120
     }
113 121
 
114 122
     /** Adds the listeners. */
@@ -134,7 +142,7 @@ public class ActionNamePanel extends JPanel implements PropertyChangeListener {
134 142
 
135 143
      */
136 144
     public boolean hasNameChanged() {
137
-        return getActionName().equals(originalName);
145
+        return getActionName().equals(existingName);
138 146
     }
139 147
 
140 148
     /**

Loading…
취소
저장