2121import java .util .Iterator ;
2222import java .util .Map ;
2323
24+ import java .util .function .*;
25+
2426import javax .swing .Box ;
2527import javax .swing .BoxLayout ;
2628import javax .swing .DefaultCellEditor ;
@@ -144,41 +146,6 @@ public void actionPerformed(final ActionEvent e) {
144146 }
145147 });
146148
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-
182149 m_table = new JTable ();
183150 m_table .putClientProperty ("terminateEditOnFocusLost" , Boolean .TRUE );
184151
@@ -190,6 +157,17 @@ public void actionPerformed(final ActionEvent e) {
190157 m_counter ++;
191158 m_table .setModel (model );
192159
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+
193171 outputMainPanel .add (m_table .getTableHeader (), BorderLayout .PAGE_START );
194172 outputMainPanel .add (m_table , BorderLayout .CENTER );
195173 outputPanel .add (newtableCBPanel );
@@ -562,4 +540,27 @@ protected final void clearErrorHighlight() {
562540 m_scriptPanel .revalidate ();
563541 m_scriptPanel .repaint ();
564542 }
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+ }
565566}
0 commit comments