|
@@ -32,7 +32,6 @@ import com.dmdirc.addons.ui_swing.Apple;
|
32
|
32
|
import com.dmdirc.addons.ui_swing.MainFrame;
|
33
|
33
|
import com.dmdirc.addons.ui_swing.SwingController;
|
34
|
34
|
import com.dmdirc.config.IdentityManager;
|
35
|
|
-import com.dmdirc.config.prefs.validator.ActionGroupValidator;
|
36
|
35
|
import com.dmdirc.config.prefs.validator.FileNameValidator;
|
37
|
36
|
import com.dmdirc.config.prefs.validator.ValidatorChain;
|
38
|
37
|
import com.dmdirc.addons.ui_swing.components.text.TextLabel;
|
|
@@ -41,6 +40,7 @@ import com.dmdirc.addons.ui_swing.components.SortedListModel;
|
41
|
40
|
import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
|
42
|
41
|
import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
|
43
|
42
|
import com.dmdirc.addons.ui_swing.components.renderers.ActionGroupListCellRenderer;
|
|
43
|
+import com.dmdirc.addons.ui_swing.components.validating.NoDuplicatesInListValidator;
|
44
|
44
|
import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
|
45
|
45
|
|
46
|
46
|
import java.awt.Window;
|
|
@@ -100,16 +100,22 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
100
|
100
|
private JPanel groupPanel;
|
101
|
101
|
/** Are we saving? */
|
102
|
102
|
private final AtomicBoolean saving = new AtomicBoolean(false);
|
|
103
|
+ /** Duplicate action group validator. */
|
|
104
|
+ private ValidatorChain<String> validator;
|
103
|
105
|
|
104
|
106
|
/**
|
105
|
107
|
* Creates a new instance of ActionsManagerDialog.
|
106
|
108
|
*/
|
|
109
|
+ @SuppressWarnings("unchecked")
|
107
|
110
|
private ActionsManagerDialog(final Window parentWindow,
|
108
|
111
|
final SwingController controller) {
|
109
|
112
|
super(Apple.isAppleUI() ? new AppleJFrame((MainFrame) parentWindow,
|
110
|
113
|
controller) : null, ModalityType.MODELESS);
|
111
|
114
|
|
112
|
115
|
initComponents();
|
|
116
|
+ validator = new ValidatorChain<String>(
|
|
117
|
+ new ActionGroupNoDuplicatesInListValidator(groups,
|
|
118
|
+ (DefaultListModel) groups.getModel()), new FileNameValidator());
|
113
|
119
|
addListeners();
|
114
|
120
|
layoutGroupPanel();
|
115
|
121
|
layoutComponents();
|
|
@@ -335,13 +341,12 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
335
|
341
|
/**
|
336
|
342
|
* Prompts then adds an action group.
|
337
|
343
|
*/
|
338
|
|
- @SuppressWarnings("unchecked")
|
339
|
344
|
private void addGroup() {
|
|
345
|
+ final int index = groups.getSelectedIndex();
|
|
346
|
+ groups.getSelectionModel().clearSelection();
|
340
|
347
|
final StandardInputDialog inputDialog = new StandardInputDialog(this,
|
341
|
348
|
ModalityType.DOCUMENT_MODAL, "New action group",
|
342
|
|
- "Please enter the name of the new action group",
|
343
|
|
- new ValidatorChain<String>(new FileNameValidator(),
|
344
|
|
- new ActionGroupValidator())) {
|
|
349
|
+ "Please enter the name of the new action group", validator) {
|
345
|
350
|
|
346
|
351
|
/**
|
347
|
352
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -354,6 +359,7 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
354
|
359
|
@Override
|
355
|
360
|
public boolean save() {
|
356
|
361
|
if (!saving.getAndSet(true)) {
|
|
362
|
+ groups.setSelectedIndex(index);
|
357
|
363
|
if (getText() == null || getText().isEmpty() && !ActionManager.
|
358
|
364
|
getGroups().
|
359
|
365
|
containsKey(getText())) {
|
|
@@ -371,7 +377,7 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
371
|
377
|
/** {@inheritDoc} */
|
372
|
378
|
@Override
|
373
|
379
|
public void cancelled() {
|
374
|
|
- //Ignore
|
|
380
|
+ groups.setSelectedIndex(index);
|
375
|
381
|
}
|
376
|
382
|
};
|
377
|
383
|
inputDialog.display(this);
|
|
@@ -380,16 +386,12 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
380
|
386
|
/**
|
381
|
387
|
* Prompts then edits an action group.
|
382
|
388
|
*/
|
383
|
|
- @SuppressWarnings("unchecked")
|
384
|
389
|
private void editGroup() {
|
385
|
390
|
final String oldName =
|
386
|
391
|
((ActionGroup) groups.getSelectedValue()).getName();
|
387
|
392
|
final StandardInputDialog inputDialog = new StandardInputDialog(this,
|
388
|
|
- ModalityType.DOCUMENT_MODAL,
|
389
|
|
- "Edit action group",
|
390
|
|
- "Please enter the new name of the action group",
|
391
|
|
- new ValidatorChain<String>(new FileNameValidator(),
|
392
|
|
- new ActionGroupValidator())) {
|
|
393
|
+ ModalityType.DOCUMENT_MODAL, "Edit action group",
|
|
394
|
+ "Please enter the new name of the action group", validator) {
|
393
|
395
|
|
394
|
396
|
/**
|
395
|
397
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -521,3 +523,52 @@ public final class ActionsManagerDialog extends StandardDialog implements
|
521
|
523
|
}
|
522
|
524
|
}
|
523
|
525
|
}
|
|
526
|
+
|
|
527
|
+/**
|
|
528
|
+ * No duplicates list validator, overriden to work with action groups.
|
|
529
|
+ */
|
|
530
|
+class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator {
|
|
531
|
+
|
|
532
|
+ /**
|
|
533
|
+ * Creates a new validator.
|
|
534
|
+ *
|
|
535
|
+ * @param list List
|
|
536
|
+ * @param model Model to validate
|
|
537
|
+ */
|
|
538
|
+ public ActionGroupNoDuplicatesInListValidator(final JList list,
|
|
539
|
+ final DefaultListModel model) {
|
|
540
|
+ super(true, list, model);
|
|
541
|
+ }
|
|
542
|
+
|
|
543
|
+ /**
|
|
544
|
+ * Creates a new validator.
|
|
545
|
+ *
|
|
546
|
+ * @param list List
|
|
547
|
+ * @param caseSensitive Case sensitive check?
|
|
548
|
+ * @param model Model to validate
|
|
549
|
+ */
|
|
550
|
+ public ActionGroupNoDuplicatesInListValidator(final boolean caseSensitive,
|
|
551
|
+ final JList list, final DefaultListModel model) {
|
|
552
|
+ super(caseSensitive, list, model);
|
|
553
|
+ }
|
|
554
|
+
|
|
555
|
+ /** {@inheritDoc} */
|
|
556
|
+ @Override
|
|
557
|
+ public String listValueToString(final Object object) {
|
|
558
|
+ return ((ActionGroup) object).getName();
|
|
559
|
+ }
|
|
560
|
+
|
|
561
|
+ /** {@inheritDoc} */
|
|
562
|
+ @Override
|
|
563
|
+ public int indexOfString(final String string) {
|
|
564
|
+ final String value = caseSensitive ? string : string.toLowerCase();
|
|
565
|
+ int index = -1;
|
|
566
|
+ for (int i = 0; i < model.getSize(); i++) {
|
|
567
|
+ if (((ActionGroup) model.get(i)).getName().equals(value)) {
|
|
568
|
+ index = i;
|
|
569
|
+ break;
|
|
570
|
+ }
|
|
571
|
+ }
|
|
572
|
+ return index;
|
|
573
|
+ }
|
|
574
|
+}
|