@@ -45,10 +45,12 @@ object RubyScriptNodeDialog {
4545
4646 private val TEMPLATE_COLUMN_NAME = " i%d_%s "
4747
48- private var logger : NodeLogger = NodeLogger .getLogger(classOf [RubyScriptNodeDialog ])
48+ private var logger : NodeLogger =
49+ NodeLogger .getLogger(classOf [RubyScriptNodeDialog ])
4950}
5051
51- class RubyScriptNodeDialog (private var factory : RubyScriptNodeFactory ) extends NodeDialogPane () {
52+ class RubyScriptNodeDialog (private var factory : RubyScriptNodeFactory )
53+ extends NodeDialogPane () {
5254
5355 private var scriptPanel : JPanel = _
5456
@@ -83,7 +85,8 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
8385
8486 def actionPerformed (e : ActionEvent ) {
8587 var name : String = null
86- val model = table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
88+ val model = table.getModel
89+ .asInstanceOf [ScriptNodeOutputColumnsTableModel ]
8790 val columns = model.getDataTableColumnNames
8891 var found : Boolean = false
8992 do {
@@ -107,11 +110,10 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
107110 if (selectedRows.length == 0 ) {
108111 return
109112 }
110- var i = selectedRows.length - 1
111- while (i >= 0 ) {
113+ for (i <- selectedRows.length - 1 to 0 ) {
112114 logger.debug(" removal " + i + " : removing row " + selectedRows(i))
113- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].removeRow(selectedRows(i))
114- i -= 1
115+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
116+ .removeRow(selectedRows(i))
115117 }
116118 }
117119 })
@@ -121,10 +123,10 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
121123 def actionPerformed (e : ActionEvent ) {
122124 val selectedRows = table.getSelectedRows
123125 logger.debug(" selectedRows = " + selectedRows)
124- if (selectedRows.length == 0 ) {
125- return
126+ if (selectedRows.length > 0 ) {
127+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
128+ .moveRowsUp(selectedRows)
126129 }
127- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].moveRowsUp(selectedRows)
128130 }
129131 })
130132 val downButton = new JButton (" Down" )
@@ -133,10 +135,10 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
133135 def actionPerformed (e : ActionEvent ) {
134136 val selectedRows = table.getSelectedRows
135137 logger.debug(" selectedRows = " + selectedRows)
136- if (selectedRows.length == 0 ) {
137- return
138+ if (selectedRows.length > 0 ) {
139+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
140+ .moveRowsDown(selectedRows)
138141 }
139- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].moveRowsDown(selectedRows)
140142 }
141143 })
142144
@@ -193,7 +195,8 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
193195 private var fileChooser : JFileChooser = new JFileChooser ()
194196
195197 def actionPerformed (e : ActionEvent ) {
196- val returnVal = fileChooser.showOpenDialog(e.getSource.asInstanceOf [Component ])
198+ val returnVal = fileChooser.showOpenDialog(
199+ e.getSource.asInstanceOf [Component ])
197200 if (returnVal != JFileChooser .APPROVE_OPTION ) {
198201 return
199202 }
@@ -220,22 +223,27 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
220223 scriptButtonPanel.add(scriptButton)
221224 val scriptMainPanel = new JPanel (new BorderLayout ())
222225 scriptMainPanel.add(new JLabel (" Script: " ), BorderLayout .NORTH )
223- var splitPane = new JSplitPane (JSplitPane .VERTICAL_SPLIT , spScript, spErrorMessage)
226+ var splitPane =
227+ new JSplitPane (JSplitPane .VERTICAL_SPLIT , spScript, spErrorMessage)
224228 scriptMainPanel.add(splitPane, BorderLayout .CENTER )
225229 val num = factory.getModel.getInputPortRoles.length
226230 columnTables = Array .ofDim[JTable ](num)
227231 val inputColumnsPanel = new JPanel ()
228- inputColumnsPanel.setLayout(new BoxLayout (inputColumnsPanel, BoxLayout .PAGE_AXIS ))
232+ inputColumnsPanel.setLayout(
233+ new BoxLayout (inputColumnsPanel, BoxLayout .PAGE_AXIS ))
229234 if (num > 0 ) inputColumnsPanel.setMinimumSize(new Dimension (20 , 150 ))
230235 for (i <- 0 until num) {
231236 inputColumnsPanel.add(addColumnPane(" Input[%d] columns: " .format(i), i))
232237 }
233238 val flowVariablesPanel = addFlowVariablesPane(" Flow variables: " )
234- splitPane = new JSplitPane (JSplitPane .VERTICAL_SPLIT , inputColumnsPanel, flowVariablesPanel)
235- splitPane.setDividerLocation(splitPane.getSize().height - splitPane.getInsets().bottom - splitPane.getDividerSize - 50 )
239+ splitPane = new JSplitPane (JSplitPane .VERTICAL_SPLIT ,
240+ inputColumnsPanel, flowVariablesPanel)
241+ splitPane.setDividerLocation(splitPane.getSize().height -
242+ splitPane.getInsets().bottom - splitPane.getDividerSize - 50 )
236243 scriptPanel.add(scriptButtonPanel, BorderLayout .PAGE_START )
237244 scriptPanel.add(scriptMainPanel, BorderLayout .CENTER )
238- val config_and_sript = new JSplitPane (JSplitPane .HORIZONTAL_SPLIT , splitPane, scriptPanel)
245+ val config_and_sript = new JSplitPane (JSplitPane .HORIZONTAL_SPLIT ,
246+ splitPane, scriptPanel)
239247 config_and_sript.setDividerLocation(200 )
240248 addTab(" Script" , config_and_sript, false )
241249 }
@@ -262,9 +270,13 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
262270 if (row >= 0 ) {
263271 var name = table.getModel.getValueAt(row, 0 ).toString
264272 if (name.length > 0 ) {
265- name = name.replaceAll(" [^\\ p{Alnum}]" , " _" ).replaceAll(" \\ _+" , " _" )
266- if (name.charAt(name.length - 1 ) == '_' ) name = name.substring(0 , name.length - 1 )
267- scriptTextArea.insert(TEMPLATE_COLUMN_NAME .format(m_index, name), scriptTextArea.getCaretPosition)
273+ name = name.replaceAll(" [^\\ p{Alnum}]" , " _" )
274+ .replaceAll(" \\ _+" , " _" )
275+ if (name.charAt(name.length - 1 ) == '_' )
276+ name = name.substring(0 , name.length - 1 )
277+ scriptTextArea.insert(
278+ TEMPLATE_COLUMN_NAME .format(m_index, name),
279+ scriptTextArea.getCaretPosition)
268280 }
269281 }
270282 }
@@ -286,7 +298,8 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
286298 private def updateColumnTable (specs : Array [DataTableSpec ]) {
287299 if (specs != null ) {
288300 for (i <- 0 until specs.length) {
289- val model = (m_columnTables(i).getModel).asInstanceOf [ScriptNodeOutputColumnsTableModel ]
301+ val model = (columnTables(i).getModel)
302+ .asInstanceOf [ScriptNodeOutputColumnsTableModel ]
290303 model.clearRows()
291304 var item = specs(i).iterator()
292305 while (item.hasNext) {
@@ -315,16 +328,19 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
315328 val p = event.getPoint
316329 val row = table.rowAtPoint(p)
317330 if (row >= 0 ) {
318- scriptTextArea.insert(String .format(TEMPLATE_FLOW_VAR , table.getModel.getValueAt(row, 0 ).toString), scriptTextArea.getCaretPosition)
331+ scriptTextArea.insert(String .format(TEMPLATE_FLOW_VAR ,
332+ table.getModel.getValueAt(row, 0 ).toString),
333+ scriptTextArea.getCaretPosition)
319334 }
320335 }
321336 }
322337 })
323338 val flow_variables = factory.getModel.getAvailableFlowVariables
324339 var i = flow_variables.values.iterator()
325340 while (i.hasNext) {
326- val `var` = i.next()
327- (table.getModel).asInstanceOf [ScriptNodeOutputColumnsTableModel ].addRow(`var`.getName, `var`.getStringValue)
341+ val varDescr = i.next()
342+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
343+ .addRow(varDescr.getName, varDescr.getStringValue)
328344 }
329345 val scrollPane = new JScrollPane (table)
330346 table.setFillsViewportHeight(true )
@@ -333,11 +349,10 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
333349 flowVariablesPanel
334350 }
335351
336- override protected def loadSettingsFrom (settings : NodeSettingsRO , specs : Array [DataTableSpec ]) {
337- var script = settings.getString(RubyScriptNodeModel .SCRIPT , null )
338- if (script == null ) {
339- script = " "
340- }
352+ override protected def loadSettingsFrom (settings : NodeSettingsRO ,
353+ specs : Array [DataTableSpec ]) {
354+ var script = Option (settings.getString(RubyScriptNodeModel .SCRIPT , null ))
355+ .getOrElse(" " )
341356 scriptTextArea.setText(script)
342357 clearErrorHighlight()
343358 val error = factory.getModel.getErrorData
@@ -357,14 +372,19 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
357372 }
358373 val appendCols = settings.getBoolean(RubyScriptNodeModel .APPEND_COLS , true )
359374 doAppendInputColumns.setSelected(appendCols)
360- val dataTableColumnNames = settings.getStringArray(RubyScriptNodeModel .COLUMN_NAMES , Array .ofDim[String ](0 ):_* )
361- val dataTableColumnTypes = settings.getStringArray(RubyScriptNodeModel .COLUMN_TYPES , Array .ofDim[String ](0 ):_* )
375+ val dataTableColumnNames =
376+ settings.getStringArray(RubyScriptNodeModel .COLUMN_NAMES ,
377+ Array [String ]():_* )
378+ val dataTableColumnTypes =
379+ settings.getStringArray(RubyScriptNodeModel .COLUMN_TYPES ,
380+ Array [String ](): _* )
362381 table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].clearRows()
363382 if (dataTableColumnNames == null ) {
364383 return
365384 }
366385 for (i <- 0 until dataTableColumnNames.length) {
367- table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].addRow(dataTableColumnNames(i), dataTableColumnTypes(i))
386+ table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ]
387+ .addRow(dataTableColumnNames(i), dataTableColumnTypes(i))
368388 }
369389 updateColumnTable(specs)
370390 }
@@ -377,15 +397,18 @@ class RubyScriptNodeDialog (private var factory: RubyScriptNodeFactory) extends
377397 editor.stopCellEditing()
378398 }
379399 val scriptSetting = scriptTextArea.getText
380- if (scriptSetting == null || " " == scriptSetting) {
400+ if (scriptSetting == null || scriptSetting.isEmpty() ) {
381401 throw new InvalidSettingsException (" Please specify a script to be run." )
382402 }
383403 settings.addString(RubyScriptNodeModel .SCRIPT , scriptTextArea.getText)
384- settings.addBoolean(RubyScriptNodeModel .APPEND_COLS , doAppendInputColumns.isSelected)
385- val columnNames = table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].getDataTableColumnNames
386- settings.addStringArray(RubyScriptNodeModel .COLUMN_NAMES , columnNames:_* )
387- val columnTypes = table.getModel.asInstanceOf [ScriptNodeOutputColumnsTableModel ].getDataTableColumnTypes
388- settings.addStringArray(RubyScriptNodeModel .COLUMN_TYPES , columnTypes:_* )
404+ settings.addBoolean(RubyScriptNodeModel .APPEND_COLS ,
405+ doAppendInputColumns.isSelected)
406+ val columnNames = table.getModel
407+ .asInstanceOf [ScriptNodeOutputColumnsTableModel ].getDataTableColumnNames
408+ settings.addStringArray(RubyScriptNodeModel .COLUMN_NAMES , columnNames : _* )
409+ val columnTypes = table.getModel
410+ .asInstanceOf [ScriptNodeOutputColumnsTableModel ].getDataTableColumnTypes
411+ settings.addStringArray(RubyScriptNodeModel .COLUMN_TYPES , columnTypes : _* )
389412 }
390413
391414 protected def clearErrorHighlight () {
0 commit comments