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