21
21
import java .util .Iterator ;
22
22
import java .util .Map ;
23
23
24
+ import java .util .function .*;
25
+
24
26
import javax .swing .Box ;
25
27
import javax .swing .BoxLayout ;
26
28
import javax .swing .DefaultCellEditor ;
@@ -144,41 +146,6 @@ public void actionPerformed(final ActionEvent e) {
144
146
}
145
147
});
146
148
147
- JButton upButton = new JButton ("Up" );
148
- upButton .addActionListener (new ActionListener () {
149
- public void actionPerformed (final ActionEvent e ) {
150
- int [] selectedRows = m_table .getSelectedRows ();
151
- logger .debug ("selectedRows = " + selectedRows );
152
-
153
- if (selectedRows .length == 0 ) {
154
- return ;
155
- }
156
- ((ScriptNodeOutputColumnsTableModel ) m_table .getModel ())
157
- .moveRowsUp (selectedRows );
158
- }
159
- });
160
-
161
- JButton downButton = new JButton ("Down" );
162
- downButton .addActionListener (new ActionListener () {
163
- public void actionPerformed (final ActionEvent e ) {
164
- int [] selectedRows = m_table .getSelectedRows ();
165
- logger .debug ("selectedRows = " + selectedRows );
166
-
167
- if (selectedRows .length == 0 ) {
168
- return ;
169
- }
170
-
171
- ((ScriptNodeOutputColumnsTableModel ) m_table .getModel ())
172
- .moveRowsDown (selectedRows );
173
- }
174
- });
175
-
176
- outputButtonPanel .add (addButton );
177
- outputButtonPanel .add (removeButton );
178
- outputButtonPanel .add (Box .createHorizontalStrut (40 ));
179
- outputButtonPanel .add (upButton );
180
- outputButtonPanel .add (downButton );
181
-
182
149
m_table = new JTable ();
183
150
m_table .putClientProperty ("terminateEditOnFocusLost" , Boolean .TRUE );
184
151
@@ -190,6 +157,17 @@ public void actionPerformed(final ActionEvent e) {
190
157
m_counter ++;
191
158
m_table .setModel (model );
192
159
160
+ JButton upButton = createButtonForRowsMoving ("Up" ,
161
+ selectedRows -> model .moveRowsUp (selectedRows ));
162
+ JButton downButton = createButtonForRowsMoving ("Down" ,
163
+ selectedRows -> model .moveRowsDown (selectedRows ));
164
+
165
+ outputButtonPanel .add (addButton );
166
+ outputButtonPanel .add (removeButton );
167
+ outputButtonPanel .add (Box .createHorizontalStrut (40 ));
168
+ outputButtonPanel .add (upButton );
169
+ outputButtonPanel .add (downButton );
170
+
193
171
outputMainPanel .add (m_table .getTableHeader (), BorderLayout .PAGE_START );
194
172
outputMainPanel .add (m_table , BorderLayout .CENTER );
195
173
outputPanel .add (newtableCBPanel );
@@ -562,4 +540,27 @@ protected final void clearErrorHighlight() {
562
540
m_scriptPanel .revalidate ();
563
541
m_scriptPanel .repaint ();
564
542
}
543
+
544
+ protected JButton createButtonForRowsMoving (String title ,
545
+ Function <int [], int []> mover ) {
546
+ JButton button = new JButton (title );
547
+ button .addActionListener (new ActionListener () {
548
+ public void actionPerformed (final ActionEvent e ) {
549
+ int [] selectedRows = m_table .getSelectedRows ();
550
+ logger .debug ("selectedRows = " + selectedRows );
551
+
552
+ if (selectedRows .length == 0 ) {
553
+ return ;
554
+ }
555
+
556
+ int [] selection = mover .apply (selectedRows );
557
+
558
+ m_table .addRowSelectionInterval (
559
+ selection [0 ],
560
+ selection [selection .length - 1 ]);
561
+ }
562
+ });
563
+
564
+ return button ;
565
+ }
565
566
}
0 commit comments