Browse Source

Remove old alias manager dialog.

Change-Id: I89fed29438eae6e7439e804ee91de11a4848ee06
Reviewed-on: http://gerrit.dmdirc.com/3560
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/60/3560/2
Greg Holmes 10 years ago
parent
commit
fc4e2c7a19

+ 1
- 15
src/com/dmdirc/addons/ui_swing/components/menubar/SettingsMenu.java View File

@@ -53,22 +53,18 @@ public class SettingsMenu extends JMenu implements ActionListener {
53 53
     private final DialogProvider<SwingPreferencesDialog> prefsDialogProvider;
54 54
     /** Provider of alias manager dialogs. */
55 55
     private final DialogProvider<AliasManagerDialog> aliasDialogProvider;
56
-    /** Provider of alias manager dialogs. */
57
-    private final DialogProvider<com.dmdirc.addons.ui_swing.dialogs.newaliases.AliasManagerDialog> newAliasDialogProvider;
58 56
 
59 57
     @Inject
60 58
     public SettingsMenu(
61 59
             final DialogProvider<ProfileManagerDialog> profileDialogProvider,
62 60
             final DialogProvider<ActionsManagerDialog> actionsDialogProvider,
63 61
             final DialogProvider<SwingPreferencesDialog> prefsDialogProvider,
64
-            final DialogProvider<AliasManagerDialog> aliasDialogProvider,
65
-            final DialogProvider<com.dmdirc.addons.ui_swing.dialogs.newaliases.AliasManagerDialog> newAliasDialogProvider) {
62
+            final DialogProvider<AliasManagerDialog> aliasDialogProvider) {
66 63
         super("Settings");
67 64
         this.profileDialogProvider = profileDialogProvider;
68 65
         this.actionsDialogProvider = actionsDialogProvider;
69 66
         this.prefsDialogProvider = prefsDialogProvider;
70 67
         this.aliasDialogProvider = aliasDialogProvider;
71
-        this.newAliasDialogProvider = newAliasDialogProvider;
72 68
 
73 69
         setMnemonic('e');
74 70
         initSettingsMenu();
@@ -109,13 +105,6 @@ public class SettingsMenu extends JMenu implements ActionListener {
109 105
         menuItem.setActionCommand("Aliases");
110 106
         menuItem.addActionListener(this);
111 107
         add(menuItem);
112
-
113
-        menuItem = new JMenuItem();
114
-        menuItem.setMnemonic('l');
115
-        menuItem.setText("New Alias Manager");
116
-        menuItem.setActionCommand("NewAliases");
117
-        menuItem.addActionListener(this);
118
-        add(menuItem);
119 108
     }
120 109
 
121 110
     @Override
@@ -133,9 +122,6 @@ public class SettingsMenu extends JMenu implements ActionListener {
133 122
             case "Aliases":
134 123
                 aliasDialogProvider.displayOrRequestFocus();
135 124
                 break;
136
-            case "NewAliases":
137
-                newAliasDialogProvider.displayOrRequestFocus();
138
-                break;
139 125
         }
140 126
     }
141 127
 

src/com/dmdirc/addons/ui_swing/dialogs/newaliases/AliasManagerController.java → src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerController.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
23
+package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25 25
 /**
26 26
  * Alias manager dialog controller reacts to actions in the UI.

+ 70
- 411
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerDialog.java View File

@@ -22,449 +22,108 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25
-import com.dmdirc.actions.Action;
26
-import com.dmdirc.actions.ActionCondition;
27
-import com.dmdirc.actions.ActionFactory;
28
-import com.dmdirc.actions.ActionManager;
29
-import com.dmdirc.actions.ActionSubstitutorFactory;
30
-import com.dmdirc.actions.CoreActionComparison;
31
-import com.dmdirc.actions.wrappers.Alias;
32
-import com.dmdirc.actions.wrappers.AliasWrapper;
33
-import com.dmdirc.addons.ui_swing.components.PackingTable;
34
-import com.dmdirc.addons.ui_swing.components.renderers.ActionConditionCellRenderer;
35
-import com.dmdirc.addons.ui_swing.components.renderers.ArrayCellRenderer;
25
+import com.dmdirc.ClientModule.GlobalConfig;
26
+import com.dmdirc.addons.ui_swing.components.validating.ValidationFactory;
36 27
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
37
-import com.dmdirc.addons.ui_swing.dialogs.StandardQuestionDialog;
38
-import com.dmdirc.addons.ui_swing.dialogs.StringArrayComparator;
39 28
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
29
+import com.dmdirc.interfaces.CommandController;
30
+import com.dmdirc.interfaces.ui.AliasDialogModel;
31
+import com.dmdirc.ui.IconManager;
32
+import com.dmdirc.util.validators.NotEmptyValidator;
40 33
 
41 34
 import java.awt.Dimension;
42 35
 import java.awt.Window;
43
-import java.awt.event.ActionEvent;
44
-import java.awt.event.ActionListener;
45
-import java.util.ArrayList;
46
-import java.util.Arrays;
47
-import java.util.List;
48 36
 
49 37
 import javax.inject.Inject;
50 38
 import javax.swing.JButton;
39
+import javax.swing.JLabel;
40
+import javax.swing.JPanel;
51 41
 import javax.swing.JScrollPane;
42
+import javax.swing.JSpinner;
52 43
 import javax.swing.JSplitPane;
53 44
 import javax.swing.JTable;
54
-import javax.swing.ListSelectionModel;
55
-import javax.swing.event.ListSelectionEvent;
56
-import javax.swing.event.ListSelectionListener;
57
-import javax.swing.table.TableCellRenderer;
58
-import javax.swing.table.TableRowSorter;
45
+import javax.swing.JTextArea;
46
+import javax.swing.JTextField;
59 47
 
60 48
 import net.miginfocom.layout.PlatformDefaults;
61 49
 import net.miginfocom.swing.MigLayout;
62 50
 
63 51
 /**
64
- * Alias manager dialog.
52
+ * Dialog to list and change command aliases.
65 53
  */
66
-public class AliasManagerDialog extends StandardDialog implements ActionListener,
67
-        ListSelectionListener {
54
+public class AliasManagerDialog extends StandardDialog {
68 55
 
69
-    /** Serial version UID. */
70
-    private static final long serialVersionUID = 3;
71
-    /** Factory to use when creating aliases. */
72
-    private final ActionFactory actionFactory;
73
-    /** Alias wrapper to retrieve aliases from. */
74
-    private final AliasWrapper aliasWrapper;
75
-    /** Actions substitutor factory. */
76
-    private final ActionSubstitutorFactory substitutorFactory;
77
-    /** Table scrollpane. */
78
-    private JScrollPane scrollPane;
79
-    /** Error table. */
80
-    private JTable table;
81
-    /** Table model. */
82
-    private AliasTableModel tableModel;
83
-    /** Error detail panel. */
84
-    private AliasPanel aliasDetails;
85
-    /** Add/edit button. */
86
-    private JButton addButton;
87
-    /** Delete button. */
88
-    private JButton deleteButton;
89
-    /** Selected row. */
90
-    private int selectedRow;
91
-    /** Substitutions panel. */
92
-    private AliasSubstitutionsPanel subsPanel;
93
-    /** Show/Hide substitution button. */
94
-    private JButton showSubs;
56
+    private static final long serialVersionUID = 1;
57
+    private final AliasManagerModel model;
58
+    private final AliasManagerController controller;
59
+    private final AliasManagerLinker linker;
95 60
 
96
-    /**
97
-     * Creates a new instance of ErrorListDialog.
98
-     *
99
-     * @param parentWindow       Parent window
100
-     * @param substitutorFactory Actions substitution factory
101
-     * @param aliasWrapper       The alias wrapper to read aliases from.
102
-     * @param actionFactory      The factory to use to create new actions.
103
-     * @param aliasPanel         The alias panel to use.
104
-     */
105 61
     @Inject
106
-    public AliasManagerDialog(
107
-            @MainWindow final Window parentWindow,
108
-            final ActionSubstitutorFactory substitutorFactory,
109
-            final AliasWrapper aliasWrapper,
110
-            final ActionFactory actionFactory,
111
-            final AliasPanel aliasPanel) {
112
-        super(parentWindow, ModalityType.MODELESS);
113
-
114
-        this.substitutorFactory = substitutorFactory;
115
-        this.aliasWrapper = aliasWrapper;
116
-        this.actionFactory = actionFactory;
117
-
118
-        setTitle("Alias manager");
119
-
120
-        selectedRow = -1;
121
-
122
-        initComponents(aliasPanel);
123
-        layoutComponents();
124
-        initListeners();
125
-    }
126
-
127
-    /** Initialises the components. */
128
-    private void initComponents(final AliasPanel aliasPanel) {
129
-        final TableCellRenderer arrayRenderer = new ArrayCellRenderer();
130
-        final TableCellRenderer conditionRenderer = new ActionConditionCellRenderer();
131
-
132
-        orderButtons(new JButton(), new JButton());
133
-        addButton = new JButton("Add");
134
-        deleteButton = new JButton("Delete");
135
-
136
-        deleteButton.setEnabled(false);
137
-
138
-        scrollPane = new JScrollPane();
139
-
140
-        tableModel = new AliasTableModel(getTableData());
141
-        table = new PackingTable(tableModel, scrollPane, false) {
142
-            /** Java Serialisation verion ID. */
143
-            private static final long serialVersionUID = 1;
144
-
145
-            @Override
146
-            public TableCellRenderer getCellRenderer(final int row,
147
-                    final int column) {
148
-                switch (column) {
149
-                    case 1:
150
-                        return conditionRenderer;
151
-                    case 2:
152
-                        return arrayRenderer;
153
-                    default:
154
-                        return super.getCellRenderer(row, column);
155
-                }
156
-            }
157
-        };
158
-        table.setAutoCreateColumnsFromModel(true);
159
-        table.setColumnSelectionAllowed(false);
160
-        table.setCellSelectionEnabled(false);
161
-        table.setDragEnabled(false);
162
-        table.setFillsViewportHeight(false);
163
-        table.setRowSelectionAllowed(true);
164
-        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
165
-        table.getTableHeader().setReorderingAllowed(false);
166
-
167
-        final TableRowSorter<AliasTableModel> sorter = new TableRowSorter<>(tableModel);
168
-        sorter.setComparator(2, new StringArrayComparator());
169
-        table.setRowSorter(sorter);
170
-        table.getRowSorter().toggleSortOrder(0);
171
-
172
-        scrollPane.setViewportView(table);
173
-
174
-        aliasDetails = aliasPanel;
175
-        subsPanel = new AliasSubstitutionsPanel(substitutorFactory);
176
-        subsPanel.setVisible(false);
177
-        showSubs = new JButton("Show Substitutions");
178
-    }
179
-
180
-    /**
181
-     * Updates the table data.
182
-     */
183
-    public void updateTableData() {
184
-        tableModel.setAliases(getTableData());
185
-    }
186
-
187
-    /**
188
-     * Gets the table data fromt he alias wrapper.
189
-     *
190
-     * @return Alias list
191
-     */
192
-    private List<Alias> getTableData() {
193
-        final List<Alias> aliases = new ArrayList<>();
194
-
195
-        for (Action loopAction : aliasWrapper) {
196
-            final List<ActionCondition> arguments = loopAction.getConditions();
197
-
198
-            ActionCondition argument;
199
-
200
-            argument = arguments.get(0);
201
-
202
-            if (argument.getComparison() != CoreActionComparison.STRING_EQUALS) {
203
-                argument = arguments.get(1);
204
-            }
205
-
206
-            aliases.add(new Alias(actionFactory, argument.getTarget(),
207
-                    arguments, loopAction.getResponse()));
208
-        }
209
-
210
-        return aliases;
211
-    }
212
-
213
-    /** Initialises the listeners. */
214
-    private void initListeners() {
215
-        table.getSelectionModel().addListSelectionListener(this);
216
-        getOkButton().addActionListener(this);
217
-        getCancelButton().addActionListener(this);
218
-        addButton.addActionListener(this);
219
-        deleteButton.addActionListener(this);
220
-        showSubs.addActionListener(this);
221
-    }
222
-
223
-    /** Lays out the components. */
224
-    private void layoutComponents() {
225
-        setLayout(new MigLayout("fill, hidemode 3, pack"));
62
+    public AliasManagerDialog(@MainWindow final Window mainFrame,
63
+            final AliasDialogModel dialogModel,
64
+            @GlobalConfig final IconManager iconManager,
65
+            final CommandController commandController) {
66
+        super(mainFrame, ModalityType.DOCUMENT_MODAL);
67
+        this.model = new AliasManagerModel(dialogModel, commandController);
68
+        controller = new AliasManagerController(this, model);
69
+        linker = new AliasManagerLinker(controller, model, this, iconManager);
70
+        setTitle("Alias Manager");
71
+        final JTable aliasList = new JTable();
72
+        final JTextField command = new JTextField();
73
+        final JSpinner argumentsNumber = new JSpinner();
74
+        final JTextArea response = new JTextArea();
75
+        final JButton addAlias = new JButton("Add Alias");
76
+        final JButton deleteAlias = new JButton("Delete Alias");
77
+        getOkButton();
78
+        getCancelButton();
79
+        setLayout(new MigLayout("fill, pack"));
226 80
         setMinimumSize(new Dimension(800, 400));
227
-        table.setPreferredScrollableViewportSize(new Dimension(800, 150));
81
+        final JScrollPane scrollPane = new JScrollPane(aliasList);
82
+        aliasList.setPreferredScrollableViewportSize(new Dimension(800, 150));
228 83
         scrollPane.setMinimumSize(new Dimension(750, 150));
229
-        final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
230
-                true, scrollPane, aliasDetails);
231
-        splitPane.setDividerSize((int) PlatformDefaults.getPanelInsets(0).
232
-                getValue());
84
+        final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, scrollPane,
85
+                getAliasDetails(command, argumentsNumber, response, iconManager));
86
+        splitPane.setDividerSize((int) PlatformDefaults.getPanelInsets(0).getValue());
233 87
 
234 88
         add(splitPane, "spanx 5, grow, push, wrap");
235
-        add(subsPanel, "spanx 5, grow, pushy, wrap");
236
-        add(showSubs, "split 3, sgx button");
237
-        add(addButton, "sgx button, gap unrel");
238
-        add(deleteButton, "sgx button");
239
-        add(getLeftButton(), "sgx button, gap unrel");
89
+        add(addAlias, "split 2, sgx button");
90
+        add(deleteAlias, "sgx button");
91
+        add(getLeftButton(), "sgx button");
240 92
         add(getRightButton(), "sgx button");
241
-    }
242
-
243
-    /** {@inheritDoc}. */
244
-    @Override
245
-    public void valueChanged(final ListSelectionEvent e) {
246
-        if (!e.getValueIsAdjusting()) {
247 93
 
248
-            if (selectedRow > -1 && selectedRow < tableModel.getRowCount() && aliasDetails.
249
-                    getAlias() == tableModel.getAlias(
250
-                            table.getRowSorter().convertRowIndexToModel(selectedRow))) {
251
-                updateAlias();
252
-            }
253
-
254
-            if (table.getSelectedRow() > -1) {
255
-                aliasDetails.setAlias(tableModel.getAlias(table.getRowSorter().
256
-                        convertRowIndexToModel(table.getSelectedRow())));
257
-                deleteButton.setEnabled(true);
258
-            } else {
259
-                aliasDetails.clear();
260
-                deleteButton.setEnabled(false);
261
-            }
262
-
263
-            selectedRow = table.getSelectedRow();
264
-        }
265
-    }
266
-
267
-    /** Updates the selected alias with the edited details. */
268
-    private void updateAlias() {
269
-        final Alias alias = tableModel.getAlias(table.getRowSorter().
270
-                convertRowIndexToModel(selectedRow));
271
-
272
-        alias.update(aliasDetails.getNewAlias());
273
-
274
-        tableModel.fireTableRowsUpdated(tableModel.indexOf(alias),
275
-                tableModel.indexOf(alias));
276
-    }
277
-
278
-    /**
279
-     * {@inheritDoc}
280
-     *
281
-     * @param e Action event
282
-     */
283
-    @Override
284
-    public void actionPerformed(final ActionEvent e) {
285
-        if (e.getSource() == deleteButton) {
286
-            delete();
287
-        } else if (e.getSource() == addButton) {
288
-            add();
289
-        } else if (e.getSource() == getCancelButton()) {
290
-            dispose();
291
-        } else if (e.getSource() == getOkButton()) {
292
-            if (table.getSelectedRow() != -1) {
293
-                updateAlias();
294
-            }
295
-            if (checkForDuplicates()) {
296
-                final StandardQuestionDialog dialog = new StandardQuestionDialog(
297
-                        this, ModalityType.APPLICATION_MODAL,
298
-                        "Duplicate Aliases", "There are duplicate aliases in "
299
-                        + "the table, these need to be removed before saving") {
300
-                            /** Java Serialisation verion ID. */
301
-                            private static final long serialVersionUID = 1;
302
-
303
-                            @Override
304
-                            public boolean save() {
305
-                                return true;
306
-                            }
307
-
308
-                            @Override
309
-                            public void cancelled() {
310
-                                //Ignore
311
-                            }
312
-                        };
313
-                dialog.getOkButton().setVisible(false);
314
-                dialog.getCancelButton().setText("OK");
315
-                dialog.display();
316
-                return;
317
-            }
318
-            save();
319
-            dispose();
320
-        } else if (e.getSource() == showSubs) {
321
-            if (subsPanel.isVisible()) {
322
-                final Dimension minSize = getMinimumSize();
323
-                minSize.setSize(minSize.getWidth(), minSize.getHeight()
324
-                        - subsPanel.getSize().getHeight());
325
-                setMinimumSize(minSize);
326
-                subsPanel.setVisible(false);
327
-                pack();
328
-                showSubs.setText("Show Substitutions");
329
-            } else {
330
-                subsPanel.setVisible(true);
331
-                pack();
332
-                final Dimension minSize = getMinimumSize();
333
-                minSize.setSize(minSize.getWidth(), minSize.getHeight()
334
-                        + subsPanel.getSize().getHeight());
335
-                setMinimumSize(minSize);
336
-                showSubs.setText("Hide Substitutions");
337
-            }
338
-        }
339
-    }
340
-
341
-    /** Adds an alias. */
342
-    private void add() {
343
-        final Alias alias = new Alias(actionFactory, "");
344
-        tableModel.addRow(alias);
345
-        final int newRow = table.getRowSorter().
346
-                convertRowIndexToView(tableModel.indexOf(alias));
347
-        table.getSelectionModel().setSelectionInterval(newRow, newRow);
348
-        aliasDetails.focusCommand();
349
-    }
350
-
351
-    /** Deletes an alias. */
352
-    private void delete() {
353
-        if (table.getSelectedRow() != -1) {
354
-            tableModel.removeRow(table.getRowSorter().
355
-                    convertRowIndexToModel(table.getSelectedRow()));
356
-        }
357
-    }
358
-
359
-    /** Saves the aliases. */
360
-    private void save() {
361
-        final List<Action> actions = aliasWrapper.getActions();
362
-        final List<Alias> aliases = tableModel.getAliases();
363
-
364
-        final List<Alias> newAliases = new ArrayList<>();
365
-        final List<Alias> modifiedAliases = new ArrayList<>();
366
-
367
-        for (Alias alias : aliases) {
368
-            final Action action = getAction(alias);
369
-
370
-            if (action == null) {
371
-                newAliases.add(alias);
372
-            } else {
373
-                if (!action.getName().equals(alias.getName()) || !action.
374
-                        getConditions().
375
-                        equals(alias.getArguments()) || !Arrays.equals(action.
376
-                                getResponse(), alias.getResponse())) {
377
-                    modifiedAliases.add(alias);
378
-                }
379
-                actions.remove(action);
380
-            }
381
-        }
382
-
383
-        for (Action action : actions) {
384
-            action.delete();
385
-        }
386
-
387
-        saveNewAliases(newAliases);
388
-
389
-        saveModifiedAliases(modifiedAliases);
390
-
391
-        ActionManager.getActionManager().loadUserActions();
94
+        linker.bindCommandList(aliasList);
95
+        linker.bindCommand(command);
96
+        linker.bindArgumentsNumber(argumentsNumber);
97
+        linker.bindResponse(response);
98
+        linker.bindAddAlias(addAlias);
99
+        linker.bindDeleteAlias(deleteAlias);
100
+        linker.bindOKButton(getOkButton());
101
+        linker.bindCancelButton(getCancelButton());
102
+        model.load();
392 103
     }
393 104
 
394 105
     /**
395
-     * Saves new aliases.
106
+     * Creates a panel showing all alias details.
396 107
      *
397
-     * @param aliases List of new aliases to save
398
-     */
399
-    private void saveNewAliases(final List<Alias> aliases) {
400
-        for (Alias alias : aliases) {
401
-            alias.createAction().save();
402
-        }
403
-    }
404
-
405
-    /**
406
-     * Saves modified aliases.
108
+     * @param command         Command name
109
+     * @param argumentsNumber Number of arguments
110
+     * @param response        Alias substitution
407 111
      *
408
-     * @param aliases List of modified aliases to save
112
+     * @return Panel to display
409 113
      */
410
-    private void saveModifiedAliases(final List<Alias> aliases) {
411
-        for (Alias alias : aliases) {
412
-            final Action action = getAction(alias);
413
-            if (action != null) {
414
-                action.setName(alias.getName());
415
-                action.setConditions(alias.getArguments());
416
-                action.setResponse(alias.getResponse());
417
-                action.save();
418
-            }
419
-        }
420
-    }
421
-
422
-    /**
423
-     * Returns the action corresponding to the specified alias.
424
-     *
425
-     * @param alias Alias to check
426
-     *
427
-     * @return Corresponding action or null if none found
428
-     */
429
-    private Action getAction(final Alias alias) {
430
-        final List<Action> actions = aliasWrapper.getActions();
431
-        Action action = null;
432
-
433
-        for (Action loopAction : actions) {
434
-            if (loopAction.getName().equals(alias.getName()) && loopAction.
435
-                    getConditions().
436
-                    equals(alias.getArguments())) {
437
-                action = loopAction;
438
-                break;
439
-            }
440
-        }
441
-
442
-        return action;
443
-    }
444
-
445
-    /**
446
-     * Checks if ths alias matches another alias.
447
-     *
448
-     * @return true iif there are duplicate matches
449
-     */
450
-    private boolean checkForDuplicates() {
451
-        final List<Alias> aliases = tableModel.getAliases();
452
-
453
-        for (Alias alias : aliases) {
454
-            int matches = 0;
455
-
456
-            for (Alias loopAlias : aliases) {
457
-                if (loopAlias.matches(alias)) {
458
-                    matches++;
459
-                }
460
-            }
461
-
462
-            if (matches > 1) {
463
-                return true;
464
-            }
465
-        }
466
-
467
-        return false;
114
+    private JPanel getAliasDetails(final JTextField command, final JSpinner argumentsNumber,
115
+            final JTextArea response, final IconManager iconManager) {
116
+        final JPanel aliasDetails = new JPanel();
117
+        aliasDetails.setLayout(new MigLayout("fill, ins 0"));
118
+        aliasDetails.add(new JLabel("Command: "));
119
+        aliasDetails.add(ValidationFactory.getValidatorPanel(command,
120
+                model.getCommandValidator(), iconManager), "sgy args, growx, pushx");
121
+        aliasDetails.add(new JLabel("#Arguments: "));
122
+        aliasDetails.add(argumentsNumber, "sgy args, growx, pushx, wrap");
123
+        aliasDetails.add(new JLabel("Response: "));
124
+        aliasDetails.add(ValidationFactory.getValidatorPanel(new JScrollPane(response),
125
+                response, new NotEmptyValidator(), iconManager), "span 3, grow, push, wrap");
126
+        return aliasDetails;
468 127
     }
469 128
 
470 129
 }

src/com/dmdirc/addons/ui_swing/dialogs/newaliases/AliasManagerLinker.java → src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerLinker.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
23
+package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.components.GenericTableModel;
26 26
 import com.dmdirc.addons.ui_swing.components.vetoable.VetoableListSelectionModel;

src/com/dmdirc/addons/ui_swing/dialogs/newaliases/AliasManagerModel.java → src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasManagerModel.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
23
+package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25 25
 import com.dmdirc.commandparser.aliases.Alias;
26 26
 import com.dmdirc.commandparser.validators.CommandNameValidator;

src/com/dmdirc/addons/ui_swing/dialogs/newaliases/AliasNameValidator.java → src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasNameValidator.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
23
+package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25 25
 import com.dmdirc.commandparser.aliases.Alias;
26 26
 import com.dmdirc.util.validators.ValidationResponse;

+ 0
- 301
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasPanel.java View File

@@ -1,301 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.aliases;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.actions.ActionCondition;
27
-import com.dmdirc.actions.ActionFactory;
28
-import com.dmdirc.actions.CoreActionComparison;
29
-import com.dmdirc.actions.CoreActionComponent;
30
-import com.dmdirc.actions.wrappers.Alias;
31
-import com.dmdirc.addons.ui_swing.UIUtilities;
32
-import com.dmdirc.addons.ui_swing.components.inputfields.ValidatingTextFieldInputField;
33
-import com.dmdirc.addons.ui_swing.components.renderers.ActionComparisonCellRenderer;
34
-import com.dmdirc.commandparser.validators.CommandNameValidator;
35
-import com.dmdirc.interfaces.CommandController;
36
-import com.dmdirc.interfaces.config.AggregateConfigProvider;
37
-import com.dmdirc.ui.IconManager;
38
-import com.dmdirc.ui.messages.ColourManager;
39
-import com.dmdirc.util.validators.FileNameValidator;
40
-import com.dmdirc.util.validators.ValidatorChain;
41
-
42
-import java.awt.event.ActionEvent;
43
-import java.awt.event.ActionListener;
44
-import java.util.ArrayList;
45
-import java.util.List;
46
-
47
-import javax.inject.Inject;
48
-import javax.swing.JComboBox;
49
-import javax.swing.JLabel;
50
-import javax.swing.JPanel;
51
-import javax.swing.JScrollPane;
52
-import javax.swing.JSpinner;
53
-import javax.swing.JTextArea;
54
-import javax.swing.SpinnerNumberModel;
55
-
56
-import net.miginfocom.swing.MigLayout;
57
-
58
-/**
59
- * Panel to display an alias.
60
- */
61
-public class AliasPanel extends JPanel implements ActionListener {
62
-
63
-    /** A version number for this class. */
64
-    private static final long serialVersionUID = 2;
65
-    /** Factory to use when creating aliases. */
66
-    private final ActionFactory actionFactory;
67
-    /** Name field. */
68
-    private final ValidatingTextFieldInputField command;
69
-    /** argument component combo box. */
70
-    private final JComboBox<Object> argumentComponent;
71
-    /** Argument number spinner. */
72
-    private final JSpinner argumentNumber;
73
-    /** Response field. */
74
-    private final JTextArea response;
75
-    /** Alias. */
76
-    private Alias alias;
77
-
78
-    /**
79
-     * Creates a new instance of AliasPanel.
80
-     *
81
-     * @param iconManager       The icon manager to use for validation and dialog icons.
82
-     * @param colourManager     The manager to use for colour input.
83
-     * @param globalConfig      The config to read settings from.
84
-     * @param actionFactory     The factory to use to create new actions.
85
-     * @param commandController The controller to use to retrieve command information.
86
-     */
87
-    @Inject
88
-    public AliasPanel(
89
-            @GlobalConfig final IconManager iconManager,
90
-            final ColourManager colourManager,
91
-            @GlobalConfig final AggregateConfigProvider globalConfig,
92
-            final ActionFactory actionFactory,
93
-            final CommandController commandController) {
94
-        super();
95
-
96
-        this.actionFactory = actionFactory;
97
-
98
-        final ValidatorChain<String> chain = ValidatorChain.<String>builder()
99
-                .addValidator(new CommandNameValidator(commandController.getCommandChar()))
100
-                .addValidator(new FileNameValidator())
101
-                .build();
102
-        command = new ValidatingTextFieldInputField(iconManager, colourManager, globalConfig, chain);
103
-        command.setEnabled(false);
104
-
105
-        argumentComponent = new JComboBox<Object>(new CoreActionComparison[]{null,
106
-            CoreActionComparison.INT_GREATER, CoreActionComparison.INT_EQUALS,
107
-            CoreActionComparison.INT_LESS,});
108
-        argumentNumber = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
109
-        response = new JTextArea();
110
-
111
-        argumentNumber.setEnabled(false);
112
-        response.setRows(5);
113
-
114
-        argumentComponent.setRenderer(new ActionComparisonCellRenderer(
115
-                argumentComponent.getRenderer()));
116
-        argumentComponent.putClientProperty("JComboBox.isTableCellEditor",
117
-                Boolean.TRUE);
118
-        argumentComponent.addActionListener(this);
119
-
120
-        UIUtilities.addUndoManager(response);
121
-
122
-        layoutComponents();
123
-
124
-        clear();
125
-    }
126
-
127
-    /** Lays out and initialises the components. */
128
-    private void layoutComponents() {
129
-        setLayout(new MigLayout("fill"));
130
-
131
-        add(new JLabel("Command: "));
132
-        add(command, "span 2, growx, pushx, wrap");
133
-
134
-        add(new JLabel("#Arguments: "));
135
-        add(argumentComponent, "sgy args");
136
-        add(argumentNumber, "sgy args, growx, pushx, wrap");
137
-
138
-        add(new JLabel("Response: "));
139
-        add(new JScrollPane(response), "span 2, grow, push, wrap");
140
-    }
141
-
142
-    /** Clears the details. */
143
-    public void clear() {
144
-        alias = null;
145
-        command.setText("");
146
-        command.setEnabled(false);
147
-        argumentComponent.setSelectedItem(null);
148
-        argumentNumber.setValue(0);
149
-        response.setText("");
150
-        command.setEnabled(false);
151
-        argumentComponent.setEnabled(false);
152
-        argumentNumber.setEnabled(false);
153
-        response.setEnabled(false);
154
-    }
155
-
156
-    /**
157
-     * Sets the alias details.
158
-     *
159
-     * @param alias List of alias details to display
160
-     */
161
-    public void setAlias(final Alias alias) {
162
-        if (alias == null) {
163
-            clear();
164
-            return;
165
-        }
166
-        this.alias = alias;
167
-        command.setEnabled(true);
168
-        argumentComponent.setEnabled(true);
169
-        response.setEnabled(true);
170
-        command.setText(alias.getCommand());
171
-
172
-        final List<ActionCondition> arguments = alias.getArguments();
173
-        ActionCondition argument;
174
-
175
-        if (arguments.size() == 1) {
176
-            argumentComponent.setSelectedItem(null);
177
-            argumentNumber.setValue(0);
178
-            argumentNumber.setEnabled(false);
179
-        } else {
180
-            argument = arguments.get(0);
181
-
182
-            if (argument.getComparison() == CoreActionComparison.STRING_EQUALS) {
183
-                argument = arguments.get(1);
184
-            }
185
-            argumentComponent.setSelectedItem(argument.getComparison());
186
-            argumentNumber.setValue(Integer.parseInt(argument.getTarget()));
187
-            argumentNumber.setEnabled(true);
188
-        }
189
-
190
-        final StringBuffer sb = new StringBuffer();
191
-        for (String line : alias.getResponse()) {
192
-            sb.append(line).append('\n');
193
-        }
194
-
195
-        if (sb.length() > 1) {
196
-            response.setText(sb.substring(0, sb.length() - 1));
197
-        } else {
198
-            response.setText("");
199
-        }
200
-    }
201
-
202
-    /**
203
-     * {@inheritDoc}.
204
-     *
205
-     * @param e Action event
206
-     */
207
-    @Override
208
-    public void actionPerformed(final ActionEvent e) {
209
-        ((SpinnerNumberModel) argumentNumber.getModel()).setMinimum(0);
210
-        if (argumentComponent.getSelectedIndex() > 0) {
211
-            argumentNumber.setEnabled(true);
212
-            if (argumentComponent.getSelectedItem() == CoreActionComparison.INT_LESS) {
213
-                if (argumentNumber.getModel().getValue().equals(0)) {
214
-                    argumentNumber.getModel().setValue(1);
215
-                }
216
-                ((SpinnerNumberModel) argumentNumber.getModel()).setMinimum(1);
217
-            }
218
-        } else {
219
-            argumentNumber.setEnabled(false);
220
-        }
221
-    }
222
-
223
-    /**
224
-     * Returns the current command.
225
-     *
226
-     * @return Alias command
227
-     */
228
-    public String getCommand() {
229
-        return command.getText();
230
-    }
231
-
232
-    /**
233
-     * Returns the arguments condition.
234
-     *
235
-     * @return Action argument condition
236
-     */
237
-    public ActionCondition getArguments() {
238
-        if (argumentComponent.getSelectedItem() == null) {
239
-            return null;
240
-        }
241
-        switch ((CoreActionComparison) argumentComponent.getSelectedItem()) {
242
-            case INT_EQUALS:
243
-                return new ActionCondition(2,
244
-                        CoreActionComponent.STRINGARRAY_LENGTH,
245
-                        CoreActionComparison.INT_EQUALS,
246
-                        argumentNumber.getValue().toString());
247
-            case INT_GREATER:
248
-                return new ActionCondition(2,
249
-                        CoreActionComponent.STRINGARRAY_LENGTH,
250
-                        CoreActionComparison.INT_GREATER,
251
-                        argumentNumber.getValue().toString());
252
-            case INT_LESS:
253
-                return new ActionCondition(2,
254
-                        CoreActionComponent.STRINGARRAY_LENGTH,
255
-                        CoreActionComparison.INT_LESS,
256
-                        argumentNumber.getValue().toString());
257
-            default:
258
-                return null;
259
-        }
260
-    }
261
-
262
-    /**
263
-     * Returns the user response to the alias.
264
-     *
265
-     * @return Alias response
266
-     */
267
-    protected String[] getResponse() {
268
-        return response.getText().split("\n");
269
-    }
270
-
271
-    /**
272
-     * Returns the alias being shown in this panel.
273
-     *
274
-     * @return Alias
275
-     */
276
-    protected Alias getAlias() {
277
-        return alias;
278
-    }
279
-
280
-    /**
281
-     * Returns an alias reflecting the changes in this panel.
282
-     *
283
-     * @return New alias reflecting the edited alias.
284
-     */
285
-    protected Alias getNewAlias() {
286
-        final List<ActionCondition> conditions = new ArrayList<>();
287
-        conditions.add(new ActionCondition(1,
288
-                CoreActionComponent.STRING_STRING,
289
-                CoreActionComparison.STRING_EQUALS, getCommand()));
290
-        if (getArguments() != null) {
291
-            conditions.add(getArguments());
292
-        }
293
-        return new Alias(actionFactory, getCommand(), conditions, getResponse());
294
-    }
295
-
296
-    /** Focuses the command field. */
297
-    public void focusCommand() {
298
-        command.requestFocusInWindow();
299
-    }
300
-
301
-}

+ 0
- 112
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasSubstitutionsPanel.java View File

@@ -1,112 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.aliases;
24
-
25
-import com.dmdirc.actions.ActionSubstitutor;
26
-import com.dmdirc.actions.ActionSubstitutorFactory;
27
-import com.dmdirc.actions.CoreActionType;
28
-import com.dmdirc.addons.ui_swing.components.substitutions.Substitution;
29
-import com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionLabel;
30
-import com.dmdirc.addons.ui_swing.components.substitutions.SubstitutionsPanel;
31
-import com.dmdirc.interfaces.actions.ActionType;
32
-
33
-import java.util.ArrayList;
34
-import java.util.Map.Entry;
35
-
36
-import javax.swing.SwingUtilities;
37
-
38
-/**
39
- * Lists substitutions for aliases.
40
- */
41
-public class AliasSubstitutionsPanel extends SubstitutionsPanel<ActionType> {
42
-
43
-    /** A version number for this class. */
44
-    private static final long serialVersionUID = 1;
45
-    /** Factory to use to create {@link ActionSubstitutor}s. */
46
-    private final ActionSubstitutorFactory substitutorFactory;
47
-
48
-    /**
49
-     * Instantiates the panel.
50
-     *
51
-     * @param substitutorFactory Factory to use to create {@link ActionSubstitutor}s.
52
-     */
53
-    public AliasSubstitutionsPanel(final ActionSubstitutorFactory substitutorFactory) {
54
-        super("Substitutions may be used in the response field",
55
-                SubstitutionsPanel.Alignment.VERTICAL,
56
-                CoreActionType.UNKNOWN_COMMAND);
57
-
58
-        this.substitutorFactory = substitutorFactory;
59
-    }
60
-
61
-    /**
62
-     * Sets the action type for this substitution panel.
63
-     *
64
-     * @param type New action type
65
-     */
66
-    @Override
67
-    public void setType(final ActionType type) {
68
-        SwingUtilities.invokeLater(new Runnable() {
69
-
70
-            @Override
71
-            public void run() {
72
-                substitutions = new ArrayList<>();
73
-
74
-                if (type != null) {
75
-                    final ActionSubstitutor sub = substitutorFactory.getActionSubstitutor(type);
76
-
77
-                    for (final Entry<String, String> entry : sub.getComponentSubstitutions().
78
-                            entrySet()) {
79
-                        substitutions.add(new SubstitutionLabel(new Substitution(entry.getValue(),
80
-                                entry.getKey())));
81
-                    }
82
-
83
-                    for (final String entry : sub.getConfigSubstitutions()) {
84
-                        substitutions.add(new SubstitutionLabel(new Substitution(entry,
85
-                                entry)));
86
-                    }
87
-
88
-                    for (final Entry<String, String> entry : sub.getServerSubstitutions().
89
-                            entrySet()) {
90
-                        substitutions.add(new SubstitutionLabel(new Substitution(entry.getValue(),
91
-                                entry.getKey())));
92
-                    }
93
-
94
-                    for (int i = 1; i < 4; i++) {
95
-                        substitutions.add(new SubstitutionLabel(new Substitution("Argument #" + i,
96
-                                Integer.toString(i))));
97
-                    }
98
-
99
-                    for (int i = 1; i < 4; i++) {
100
-                        substitutions.add(new SubstitutionLabel(new Substitution("Argument #" + i
101
-                                + " onwards", i + "-")));
102
-                    }
103
-                }
104
-
105
-                layoutComponents();
106
-                validate();
107
-                layoutComponents();
108
-            }
109
-        });
110
-    }
111
-
112
-}

+ 0
- 206
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasTableModel.java View File

@@ -1,206 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.aliases;
24
-
25
-import com.dmdirc.actions.ActionCondition;
26
-import com.dmdirc.actions.wrappers.Alias;
27
-
28
-import java.util.ArrayList;
29
-import java.util.List;
30
-
31
-import javax.swing.table.AbstractTableModel;
32
-
33
-/**
34
- * Table model for displaying aliases.
35
- */
36
-public final class AliasTableModel extends AbstractTableModel {
37
-
38
-    /** A version number for this class. */
39
-    private static final long serialVersionUID = 3;
40
-    /** Data list. */
41
-    private List<Alias> aliases;
42
-
43
-    /** Creates a new instance of AliasTableModel. */
44
-    public AliasTableModel() {
45
-        this(new ArrayList<Alias>());
46
-    }
47
-
48
-    /**
49
-     * Creates a new instance of AliasTableModel.
50
-     *
51
-     * @param aliases List of aliases
52
-     */
53
-    public AliasTableModel(final List<Alias> aliases) {
54
-        super();
55
-
56
-        this.aliases = new ArrayList<>(aliases);
57
-    }
58
-
59
-    /**
60
-     * Sets the alias list.
61
-     *
62
-     * @param aliases List of aliases
63
-     */
64
-    public void setAliases(final List<Alias> aliases) {
65
-        this.aliases = new ArrayList<>(aliases);
66
-
67
-        fireTableDataChanged();
68
-    }
69
-
70
-    public int getRowCount() {
71
-        return aliases.size();
72
-    }
73
-
74
-    public int getColumnCount() {
75
-        return 3;
76
-    }
77
-
78
-    public String getColumnName(final int columnIndex) {
79
-        switch (columnIndex) {
80
-            case 0:
81
-                return "Command";
82
-            case 1:
83
-                return "# of Arguments";
84
-            case 2:
85
-                return "Response";
86
-            default:
87
-                throw new IllegalArgumentException("Unknown column: "
88
-                        + columnIndex);
89
-        }
90
-    }
91
-
92
-    public Class<?> getColumnClass(final int columnIndex) {
93
-        switch (columnIndex) {
94
-            case 0:
95
-                return String.class;
96
-            case 1:
97
-                return ActionCondition.class;
98
-            case 2:
99
-                return String[].class;
100
-            default:
101
-                throw new IllegalArgumentException("Unknown column: "
102
-                        + columnIndex);
103
-        }
104
-    }
105
-
106
-    public boolean isCellEditable(final int rowIndex, final int columnIndex) {
107
-        return false;
108
-    }
109
-
110
-    public Object getValueAt(final int rowIndex, final int columnIndex) {
111
-        if (aliases.size() <= rowIndex) {
112
-            throw new IndexOutOfBoundsException(rowIndex + " >= " + aliases.size());
113
-        }
114
-        if (rowIndex < 0) {
115
-            throw new IllegalArgumentException("Must specify a positive integer");
116
-        }
117
-        switch (columnIndex) {
118
-            case 0:
119
-                return aliases.get(rowIndex).getCommand();
120
-            case 1:
121
-                return aliases.get(rowIndex).getArgsArgument();
122
-            case 2:
123
-                return aliases.get(rowIndex).getResponse();
124
-            default:
125
-                throw new IllegalArgumentException("Unknown column: "
126
-                        + columnIndex);
127
-        }
128
-    }
129
-
130
-    public void setValueAt(final Object aValue, final int rowIndex,
131
-            final int columnIndex) {
132
-        if (aliases.size() <= rowIndex) {
133
-            throw new IndexOutOfBoundsException(rowIndex + " >= " + aliases.size());
134
-        }
135
-        if (rowIndex < 0) {
136
-            throw new IllegalArgumentException("Must specify a positive integer");
137
-        }
138
-        switch (columnIndex) {
139
-            case 0:
140
-                aliases.get(rowIndex).setCommand((String) aValue);
141
-                break;
142
-            case 1:
143
-                aliases.get(rowIndex).getArguments().set(1, (ActionCondition) aValue);
144
-                break;
145
-            case 2:
146
-                aliases.get(rowIndex).setResponse((String[]) aValue);
147
-                break;
148
-            default:
149
-                throw new IllegalArgumentException("Unknown column: "
150
-                        + columnIndex);
151
-        }
152
-        fireTableCellUpdated(rowIndex, columnIndex);
153
-    }
154
-
155
-    /**
156
-     * Gets the alias at the specified row.
157
-     *
158
-     * @param rowIndex Row to retrieve
159
-     *
160
-     * @return Specified Alias
161
-     */
162
-    public Alias getAlias(final int rowIndex) {
163
-        return aliases.get(rowIndex);
164
-    }
165
-
166
-    /**
167
-     * Gets a list of all aliases (including deleted ones).
168
-     *
169
-     * @return Complete alias list
170
-     */
171
-    public List<Alias> getAliases() {
172
-        return new ArrayList<>(aliases);
173
-    }
174
-
175
-    /**
176
-     * Adds an alias to the list.
177
-     *
178
-     * @param alias Alias to add
179
-     */
180
-    public void addRow(final Alias alias) {
181
-        aliases.add(alias);
182
-        fireTableRowsInserted(aliases.indexOf(alias), aliases.indexOf(alias));
183
-    }
184
-
185
-    /**
186
-     * Removes a specified row from the list.
187
-     *
188
-     * @param row Row to remove
189
-     */
190
-    public void removeRow(final int row) {
191
-        aliases.remove(row);
192
-        fireTableRowsDeleted(row, row);
193
-    }
194
-
195
-    /**
196
-     * Returns the index of the specified alias.
197
-     *
198
-     * @param alias Alias to get index of
199
-     *
200
-     * @return Index of the alias or -1 if not found.
201
-     */
202
-    public int indexOf(final Alias alias) {
203
-        return aliases.indexOf(alias);
204
-    }
205
-
206
-}

src/com/dmdirc/addons/ui_swing/dialogs/newaliases/UniqueAliasNameValidator.java → src/com/dmdirc/addons/ui_swing/dialogs/aliases/UniqueAliasNameValidator.java View File

@@ -20,7 +20,7 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
23
+package com.dmdirc.addons.ui_swing.dialogs.aliases;
24 24
 
25 25
 import com.dmdirc.commandparser.aliases.Alias;
26 26
 import com.dmdirc.util.validators.ValidationResponse;

+ 0
- 26
src/com/dmdirc/addons/ui_swing/dialogs/aliases/package-info.java View File

@@ -1,26 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-/**
24
- * Alias manager.
25
- */
26
-package com.dmdirc.addons.ui_swing.dialogs.aliases;

+ 0
- 129
src/com/dmdirc/addons/ui_swing/dialogs/newaliases/AliasManagerDialog.java View File

@@ -1,129 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5
- * of this software and associated documentation files (the "Software"), to deal
6
- * in the Software without restriction, including without limitation the rights
7
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
- * copies of the Software, and to permit persons to whom the Software is
9
- * furnished to do so, subject to the following conditions:
10
- *
11
- * The above copyright notice and this permission notice shall be included in
12
- * all copies or substantial portions of the Software.
13
- *
14
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
- * SOFTWARE.
21
- */
22
-
23
-package com.dmdirc.addons.ui_swing.dialogs.newaliases;
24
-
25
-import com.dmdirc.ClientModule.GlobalConfig;
26
-import com.dmdirc.addons.ui_swing.components.validating.ValidationFactory;
27
-import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
28
-import com.dmdirc.addons.ui_swing.injection.MainWindow;
29
-import com.dmdirc.interfaces.CommandController;
30
-import com.dmdirc.interfaces.ui.AliasDialogModel;
31
-import com.dmdirc.ui.IconManager;
32
-import com.dmdirc.util.validators.NotEmptyValidator;
33
-
34
-import java.awt.Dimension;
35
-import java.awt.Window;
36
-
37
-import javax.inject.Inject;
38
-import javax.swing.JButton;
39
-import javax.swing.JLabel;
40
-import javax.swing.JPanel;
41
-import javax.swing.JScrollPane;
42
-import javax.swing.JSpinner;
43
-import javax.swing.JSplitPane;
44
-import javax.swing.JTable;
45
-import javax.swing.JTextArea;
46
-import javax.swing.JTextField;
47
-
48
-import net.miginfocom.layout.PlatformDefaults;
49
-import net.miginfocom.swing.MigLayout;
50
-
51
-/**
52
- * Dialog to list and change command aliases.
53
- */
54
-public class AliasManagerDialog extends StandardDialog {
55
-
56
-    private static final long serialVersionUID = 1;
57
-    private final AliasManagerModel model;
58
-    private final AliasManagerController controller;
59
-    private final AliasManagerLinker linker;
60
-
61
-    @Inject
62
-    public AliasManagerDialog(@MainWindow final Window mainFrame,
63
-            final AliasDialogModel dialogModel,
64
-            @GlobalConfig final IconManager iconManager,
65
-            final CommandController commandController) {
66
-        super(mainFrame, ModalityType.DOCUMENT_MODAL);
67
-        this.model = new AliasManagerModel(dialogModel, commandController);
68
-        controller = new AliasManagerController(this, model);
69
-        linker = new AliasManagerLinker(controller, model, this, iconManager);
70
-        setTitle("Alias Manager");
71
-        final JTable aliasList = new JTable();
72
-        final JTextField command = new JTextField();
73
-        final JSpinner argumentsNumber = new JSpinner();
74
-        final JTextArea response = new JTextArea();
75
-        final JButton addAlias = new JButton("Add Alias");
76
-        final JButton deleteAlias = new JButton("Delete Alias");
77
-        getOkButton();
78
-        getCancelButton();
79
-        setLayout(new MigLayout("fill, pack"));
80
-        setMinimumSize(new Dimension(800, 400));
81
-        final JScrollPane scrollPane = new JScrollPane(aliasList);
82
-        aliasList.setPreferredScrollableViewportSize(new Dimension(800, 150));
83
-        scrollPane.setMinimumSize(new Dimension(750, 150));
84
-        final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, scrollPane,
85
-                getAliasDetails(command, argumentsNumber, response, iconManager));
86
-        splitPane.setDividerSize((int) PlatformDefaults.getPanelInsets(0).getValue());
87
-
88
-        add(splitPane, "spanx 5, grow, push, wrap");
89
-        add(addAlias, "split 2, sgx button");
90
-        add(deleteAlias, "sgx button");
91
-        add(getLeftButton(), "sgx button");
92
-        add(getRightButton(), "sgx button");
93
-
94
-        linker.bindCommandList(aliasList);
95
-        linker.bindCommand(command);
96
-        linker.bindArgumentsNumber(argumentsNumber);
97
-        linker.bindResponse(response);
98
-        linker.bindAddAlias(addAlias);
99
-        linker.bindDeleteAlias(deleteAlias);
100
-        linker.bindOKButton(getOkButton());
101
-        linker.bindCancelButton(getCancelButton());
102
-        model.load();
103
-    }
104
-
105
-    /**
106
-     * Creates a panel showing all alias details.
107
-     *
108
-     * @param command         Command name
109
-     * @param argumentsNumber Number of arguments
110
-     * @param response        Alias substitution
111
-     *
112
-     * @return Panel to display
113
-     */
114
-    private JPanel getAliasDetails(final JTextField command, final JSpinner argumentsNumber,
115
-            final JTextArea response, final IconManager iconManager) {
116
-        final JPanel aliasDetails = new JPanel();
117
-        aliasDetails.setLayout(new MigLayout("fill, ins 0"));
118
-        aliasDetails.add(new JLabel("Command: "));
119
-        aliasDetails.add(ValidationFactory.getValidatorPanel(command,
120
-                model.getCommandValidator(), iconManager), "sgy args, growx, pushx");
121
-        aliasDetails.add(new JLabel("#Arguments: "));
122
-        aliasDetails.add(argumentsNumber, "sgy args, growx, pushx, wrap");
123
-        aliasDetails.add(new JLabel("Response: "));
124
-        aliasDetails.add(ValidationFactory.getValidatorPanel(new JScrollPane(response),
125
-                response, new NotEmptyValidator(), iconManager), "span 3, grow, push, wrap");
126
-        return aliasDetails;
127
-    }
128
-
129
-}

+ 1
- 8
src/com/dmdirc/addons/ui_swing/injection/DialogModule.java View File

@@ -32,10 +32,10 @@ import com.dmdirc.addons.ui_swing.dialogs.FeedbackDialog;
32 32
 import com.dmdirc.addons.ui_swing.dialogs.NewServerDialog;
33 33
 import com.dmdirc.addons.ui_swing.dialogs.about.AboutDialog;
34 34
 import com.dmdirc.addons.ui_swing.dialogs.actionsmanager.ActionsManagerDialog;
35
-import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
36 35
 import com.dmdirc.addons.ui_swing.dialogs.channellist.ChannelListDialog;
37 36
 import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
38 37
 import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
38
+import com.dmdirc.addons.ui_swing.dialogs.aliases.AliasManagerDialog;
39 39
 import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
40 40
 import com.dmdirc.addons.ui_swing.dialogs.profiles.ProfileManagerDialog;
41 41
 import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
@@ -114,13 +114,6 @@ public class DialogModule {
114 114
         return new DialogProvider<>(provider);
115 115
     }
116 116
 
117
-    @Provides
118
-    @Singleton
119
-    public DialogProvider<com.dmdirc.addons.ui_swing.dialogs.newaliases.AliasManagerDialog> getNewAliasManagerDialogProvider(
120
-            final Provider<com.dmdirc.addons.ui_swing.dialogs.newaliases.AliasManagerDialog> provider) {
121
-        return new DialogProvider<>(provider);
122
-    }
123
-
124 117
     @Provides
125 118
     @Singleton
126 119
     public DialogProvider<ErrorListDialog> getErrorListDialogProvider(

Loading…
Cancel
Save