1 | void actionPerformed(ActionEvent e) {↵ | | 1 | void actionPerformed(ActionEvent e) {↵
|
2 | String action = e.getActionCommand();↵ | | 2 | String action = e.getActionCommand();↵
|
3 | if (action.equals(DELETE)) {↵ | | 3 | if (action.equals(DELETE)) {↵
|
4 | deleteArgument();↵ | | 4 | deleteArgument();↵
|
5 | } else if (action.equals(ADD)) {↵ | | 5 | } else if (action.equals(ADD)) {↵
|
6 | addArgument();↵ | | 6 | addArgument();↵
|
7 | }↵ | | 7 | }↵
|
8 | }↵ | | 8 | }↵
|
|
9 | /**↵ | | 9 | /**↵
|
10 | * Remove the currently selected argument from the table.↵ | | 10 | * Remove the currently selected argument from the table.↵
|
11 | */↵ | | 11 | */↵
|
12 | protected void deleteArgument() {↵ | | 12 | protected void deleteArgument() {↵
|
13 | // If a table cell is being edited, we must cancel the editing before↵ | | 13 | // If a table cell is being edited, we must cancel the editing before↵
|
14 | // deleting the row↵ | | 14 | // deleting the row↵
|
15 | if (table.isEditing()) {↵ | | 15 | if (table.isEditing()) {↵
|
16 | TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());↵ | | 16 | TableCellEditor cellEditor = table.getCellEditor(table.getEditingRow(), table.getEditingColumn());↵
|
17 | cellEditor.cancelCellEditing();↵ | | 17 | cellEditor.cancelCellEditing();↵
|
18 | }↵ | | 18 | }↵
|
|
19 | int rowSelected = table.getSelectedRow();↵ | | 19 | int rowSelected = table.getSelectedRow();↵
|
20 | if (rowSelected >= 0) {↵ | | 20 | if (rowSelected >= 0) {↵
|
21 | tableModel.removeRow(rowSelected);↵ | | 21 | tableModel.removeRow(rowSelected);↵
|
22 | tableModel.fireTableDataChanged();↵ | | 22 | tableModel.fireTableDataChanged();↵
|
|
23 | // Disable DELETE if there are no rows in the table to delete.↵ | | 23 | // Disable DELETE if there are no rows in the table to delete.↵
|
24 | if (tableModel.getRowCount() == 0) {↵ | | 24 | if (tableModel.getRowCount() == 0) {↵
|
25 | delete.setEnabled(false);↵ | | 25 | delete.setEnabled(false);↵
|
26 | }↵ | | 26 | }↵
|
|
27 | // Table still contains one or more rows, so highlight (select)↵ | | 27 | // Table still contains one or more rows, so highlight (select)↵
|
28 | // the appropriate one.↵ | | 28 | // the appropriate one.↵
|
29 | else {↵ | | 29 | else {↵
|
30 | int rowToSelect = rowSelected;↵ | | 30 | int rowToSelect = rowSelected;↵
|
|
31 | if (rowSelected >= tableModel.getRowCount()) {↵ | | 31 | if (rowSelected >= tableModel.getRowCount()) {↵
|
32 | rowToSelect = rowSelected - 1;↵ | | 32 | rowToSelect = rowSelected - 1;↵
|
33 | }↵ | | 33 | }↵
|
|
34 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵ | | 34 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵
|
35 | }↵ | | 35 | }↵
|
36 | }↵ | | 36 | }↵
|
37 | }↵ | | 37 | }↵
|
|
38 | /**↵ | | 38 | /**↵
|
39 | * Add a new argument row to the table.↵ | | 39 | * Add a new argument row to the table.↵
|
40 | */↵ | | 40 | */↵
|
41 | protected void addArgument() {↵ | | 41 | protected void addArgument() {↵
|
42 | // If a table cell is being edited, we should accept the current value↵ | | 42 | // If a table cell is being edited, we should accept the current value↵
|
43 | // and stop the editing before adding a new row.↵ | | 43 | // and stop the editing before adding a new row.↵
|
44 | stopTableEditing();↵ | | 44 | stopTableEditing();↵
|
|
45 | tableModel.addRow(makeNewArgument());↵ | | 45 | tableModel.addRow(makeNewLDAPArgument());↵
|
|
46 | // Enable DELETE (which may already be enabled, but it won't hurt)↵ | | 46 | // Enable DELETE (which may already be enabled, but it won't hurt)↵
|
47 | delete.setEnabled(true);↵ | | 47 | delete.setEnabled(true);↵
|
|
48 | // Highlight (select) the appropriate row.↵ | | 48 | // Highlight (select) the appropriate row.↵
|
49 | int rowToSelect = tableModel.getRowCount() - 1;↵ | | 49 | int rowToSelect = tableModel.getRowCount() - 1;↵
|
50 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵ | | 50 | table.setRowSelectionInterval(rowToSelect, rowToSelect);↵
|
51 | | | 51 |
|