@@ -121,30 +121,39 @@ class RubyScriptNodeDialog(private var factory: RubyScriptNodeFactory)
121121 }
122122 }
123123 })
124- val upButton = new JButton (" Up" )
125- upButton.addActionListener(new ActionListener () {
126124
127- def actionPerformed (e : ActionEvent ) {
128- val selectedRows = table.getSelectedRows
129- logger.debug(" selectedRows = " + selectedRows)
130- if (selectedRows.length > 0 ) {
131- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
132- .moveRowsUp(selectedRows)
133- }
134- }
135- })
136- val downButton = new JButton (" Down" )
137- downButton.addActionListener(new ActionListener () {
125+ table = new JTable ()
126+ table.putClientProperty(" terminateEditOnFocusLost" , true )
127+ table.setAutoscrolls(true )
128+ val model = new ScriptNodeOutputColumnsTableModel ()
129+ model.addColumn(" Column name" )
130+ model.addColumn(" Column type" )
131+ model.addRow(" script output " + columnCounter, " String" )
132+ columnCounter += 1
133+ table.setModel(model)
138134
139- def actionPerformed (e : ActionEvent ) {
140- val selectedRows = table.getSelectedRows
141- logger.debug(" selectedRows = " + selectedRows)
142- if (selectedRows.length > 0 ) {
143- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
144- .moveRowsDown(selectedRows)
135+ def createButtonForRowsMoving (title : String , func : (Array [Int ]) => (Int , Int )): JButton = {
136+ val result = new JButton (title)
137+ result.addActionListener(new ActionListener () {
138+
139+ def actionPerformed (e : ActionEvent ) {
140+ val selectedRows = table.getSelectedRows
141+ logger.debug(" selectedRows = " + selectedRows)
142+ if (selectedRows.length > 0 ) {
143+ val position = func(selectedRows)
144+ table.setRowSelectionInterval(position._1, position._2)
145+ }
145146 }
146- }
147- })
147+ })
148+ result
149+ }
150+
151+ val upButton = createButtonForRowsMoving(
152+ " Up" ,
153+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].moveRowsUp)
154+ val downButton = createButtonForRowsMoving(
155+ " Down" ,
156+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].moveRowsDown)
148157
149158 Array (addButton, removeButton, Box .createHorizontalStrut(40 ),
150159 upButton, downButton).foreach(outputButtonPanel.add)
@@ -154,15 +163,7 @@ class RubyScriptNodeDialog(private var factory: RubyScriptNodeFactory)
154163// outputButtonPanel.add(Box.createHorizontalStrut(40))
155164// outputButtonPanel.add(upButton)
156165// outputButtonPanel.add(downButton)
157- table = new JTable ()
158- table.putClientProperty(" terminateEditOnFocusLost" , true )
159- table.setAutoscrolls(true )
160- val model = new ScriptNodeOutputColumnsTableModel ()
161- model.addColumn(" Column name" )
162- model.addColumn(" Column type" )
163- model.addRow(" script output " + columnCounter, " String" )
164- columnCounter += 1
165- table.setModel(model)
166+
166167 outputMainPanel.add(table.getTableHeader, BorderLayout .PAGE_START )
167168 outputMainPanel.add(table, BorderLayout .CENTER )
168169 outputPanel.add(newtableCBPanel)
0 commit comments