Skip to content

Commit a0374c3

Browse files
committed
Some of code refactoring
1 parent 2315d55 commit a0374c3

2 files changed

Lines changed: 136 additions & 115 deletions

File tree

RubyScript/src/org/knime/ext/jruby/RubyScriptNodeDialog.java

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@
4545
public class RubyScriptNodeDialog extends NodeDialogPane {
4646
private static NodeLogger logger = NodeLogger
4747
.getLogger(RubyScriptNodeDialog.class);
48+
49+
private JPanel m_scriptPanel;
4850
//private JTextArea scriptTextArea = new JTextArea();
49-
private RSyntaxTextArea m_scriptTextArea = new RSyntaxTextArea();
51+
private RSyntaxTextArea m_scriptTextArea;
5052

51-
private JTextArea m_errorMessage = new JTextArea();
52-
private JScrollPane m_sp_errorMessage = new JScrollPane(m_errorMessage);
53+
private JTextArea m_errorMessage;
54+
private JScrollPane m_sp_errorMessage;
5355

54-
private JTable table;
55-
private int counter = 1;
56+
private JTable m_table;
57+
private int m_counter = 1;
5658
private JCheckBox m_appendColsCB;
5759
private RubyScriptNodeFactory m_factory;
5860

@@ -69,6 +71,10 @@ protected RubyScriptNodeDialog(RubyScriptNodeFactory factory) {
6971
//Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
7072
//scriptTextArea.setFont(font);
7173

74+
m_errorMessage = new JTextArea();
75+
m_sp_errorMessage = new JScrollPane(m_errorMessage);
76+
77+
m_scriptTextArea = new RSyntaxTextArea();
7278
m_scriptTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_RUBY);
7379
m_scriptTextArea.setCodeFoldingEnabled(true);
7480
m_scriptTextArea.setAntiAliasingEnabled(true);
@@ -93,9 +99,9 @@ protected RubyScriptNodeDialog(RubyScriptNodeFactory factory) {
9399
private static final long serialVersionUID = -743704737927962277L;
94100

95101
public void actionPerformed(final ActionEvent e) {
96-
((ScriptNodeOutputColumnsTableModel) table.getModel()).addRow(
97-
"script output " + counter, "String");
98-
counter++;
102+
((ScriptNodeOutputColumnsTableModel) m_table.getModel()).addRow(
103+
"script output " + m_counter, "String");
104+
m_counter++;
99105
}
100106
});
101107
addButton.setText("Add Output Column");
@@ -105,7 +111,7 @@ public void actionPerformed(final ActionEvent e) {
105111
private static final long serialVersionUID = 743704737927962277L;
106112

107113
public void actionPerformed(final ActionEvent e) {
108-
int[] selectedRows = table.getSelectedRows();
114+
int[] selectedRows = m_table.getSelectedRows();
109115
logger.debug("selectedRows = " + selectedRows);
110116

111117
if (selectedRows.length == 0) {
@@ -115,7 +121,7 @@ public void actionPerformed(final ActionEvent e) {
115121
for (int i = selectedRows.length - 1; i >= 0; i--) {
116122
logger.debug(" removal " + i + ": removing row "
117123
+ selectedRows[i]);
118-
((ScriptNodeOutputColumnsTableModel) table.getModel())
124+
((ScriptNodeOutputColumnsTableModel) m_table.getModel())
119125
.removeRow(selectedRows[i]);
120126
}
121127
}
@@ -125,24 +131,24 @@ public void actionPerformed(final ActionEvent e) {
125131
outputButtonPanel.add(addButton);
126132
outputButtonPanel.add(removeButton);
127133

128-
table = new JTable();
129-
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
134+
m_table = new JTable();
135+
m_table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
130136

131-
table.setAutoscrolls(true);
137+
m_table.setAutoscrolls(true);
132138
ScriptNodeOutputColumnsTableModel model = new ScriptNodeOutputColumnsTableModel();
133139
model.addColumn("Column name");
134140
model.addColumn("Column type");
135-
model.addRow("script output " + counter, "String");
136-
counter++;
137-
table.setModel(model);
141+
model.addRow("script output " + m_counter, "String");
142+
m_counter++;
143+
m_table.setModel(model);
138144

139-
outputMainPanel.add(table.getTableHeader(), BorderLayout.PAGE_START);
140-
outputMainPanel.add(table, BorderLayout.CENTER);
145+
outputMainPanel.add(m_table.getTableHeader(), BorderLayout.PAGE_START);
146+
outputMainPanel.add(m_table, BorderLayout.CENTER);
141147
outputPanel.add(newtableCBPanel);
142148
outputPanel.add(outputButtonPanel);
143149
outputPanel.add(outputMainPanel);
144150

145-
TableColumn typeColumn = table.getColumnModel().getColumn(1);
151+
TableColumn typeColumn = m_table.getColumnModel().getColumn(1);
146152
JComboBox<String> typeSelector = new JComboBox<String>();
147153
typeSelector.addItem("String");
148154
typeSelector.addItem("Integer");
@@ -152,7 +158,7 @@ public void actionPerformed(final ActionEvent e) {
152158
typeColumn.setCellEditor(new DefaultCellEditor(typeSelector));
153159

154160
// construct the panel for script loading/authoring
155-
JPanel scriptPanel = new JPanel(new BorderLayout());
161+
m_scriptPanel = new JPanel(new BorderLayout());
156162

157163
JPanel scriptButtonPanel = new JPanel();
158164
JButton scriptButton = new JButton(new AbstractAction() {
@@ -193,8 +199,7 @@ public void actionPerformed(final ActionEvent e) {
193199

194200
m_scriptTextArea.setText(buffer.toString());
195201

196-
m_scriptTextArea.removeAllLineHighlights();
197-
m_sp_errorMessage.setVisible(false);
202+
clearErrorHighlight();
198203
}
199204
});
200205
scriptButton.setText("Load Script from File");
@@ -213,11 +218,11 @@ public void actionPerformed(final ActionEvent e) {
213218
spScript, m_sp_errorMessage);
214219
scriptMainPanel.add(splitPane, BorderLayout.CENTER);
215220

216-
scriptPanel.add(scriptButtonPanel, BorderLayout.PAGE_START);
217-
scriptPanel.add(scriptMainPanel, BorderLayout.CENTER);
221+
m_scriptPanel.add(scriptButtonPanel, BorderLayout.PAGE_START);
222+
m_scriptPanel.add(scriptMainPanel, BorderLayout.CENTER);
218223

219224
addTab("Script Output", outputPanel);
220-
addTab("Script", scriptPanel);
225+
addTab("Script", m_scriptPanel);
221226
}
222227

223228
/**
@@ -231,9 +236,7 @@ protected final void loadSettingsFrom(final NodeSettingsRO settings,
231236
}
232237
m_scriptTextArea.setText(script);
233238

234-
m_scriptTextArea.removeAllLineHighlights();
235-
m_sp_errorMessage.setVisible(false);
236-
m_errorMessage.setText("");
239+
clearErrorHighlight();
237240
RubyScriptNodeModel.ScriptError error = m_factory.getModel().getErrorData();
238241
if ( error.lineNum != -1 ) {
239242
try {
@@ -260,14 +263,14 @@ protected final void loadSettingsFrom(final NodeSettingsRO settings,
260263
String[] dataTableColumnTypes = settings.getStringArray(
261264
RubyScriptNodeModel.COLUMN_TYPES, new String[0]);
262265

263-
((ScriptNodeOutputColumnsTableModel) table.getModel()).clearRows();
266+
((ScriptNodeOutputColumnsTableModel) m_table.getModel()).clearRows();
264267

265268
if (dataTableColumnNames == null) {
266269
return;
267270
}
268271

269272
for (int i = 0; i < dataTableColumnNames.length; i++) {
270-
((ScriptNodeOutputColumnsTableModel) table.getModel()).addRow(
273+
((ScriptNodeOutputColumnsTableModel) m_table.getModel()).addRow(
271274
dataTableColumnNames[i], dataTableColumnTypes[i]);
272275
}
273276
}
@@ -279,11 +282,11 @@ protected final void saveSettingsTo(final NodeSettingsWO settings)
279282
throws InvalidSettingsException {
280283
// work around a jtable cell value persistence problem
281284
// by explicitly stopping editing if a cell is currently in edit mode
282-
int editingRow = table.getEditingRow();
283-
int editingColumn = table.getEditingColumn();
285+
int editingRow = m_table.getEditingRow();
286+
int editingColumn = m_table.getEditingColumn();
284287

285288
if (editingRow != -1 && editingColumn != -1) {
286-
TableCellEditor editor = table.getCellEditor(editingRow,
289+
TableCellEditor editor = m_table.getCellEditor(editingRow,
287290
editingColumn);
288291
editor.stopCellEditing();
289292
}
@@ -298,13 +301,23 @@ protected final void saveSettingsTo(final NodeSettingsWO settings)
298301

299302
settings.addBoolean(RubyScriptNodeModel.APPEND_COLS,
300303
m_appendColsCB.isSelected());
301-
String[] columnNames = ((ScriptNodeOutputColumnsTableModel) table
304+
String[] columnNames = ((ScriptNodeOutputColumnsTableModel) m_table
302305
.getModel()).getDataTableColumnNames();
303306
settings.addStringArray(RubyScriptNodeModel.COLUMN_NAMES, columnNames);
304307

305-
String[] columnTypes = ((ScriptNodeOutputColumnsTableModel) table
308+
String[] columnTypes = ((ScriptNodeOutputColumnsTableModel) m_table
306309
.getModel()).getDataTableColumnTypes();
307310
settings.addStringArray(RubyScriptNodeModel.COLUMN_TYPES, columnTypes);
308311
}
309312

313+
/**
314+
* Delete highlight in the script pane and hide error window
315+
*/
316+
protected final void clearErrorHighlight() {
317+
m_scriptTextArea.removeAllLineHighlights();
318+
m_sp_errorMessage.setVisible(false);
319+
m_errorMessage.setText("");
320+
m_scriptPanel.revalidate();
321+
m_scriptPanel.repaint();
322+
}
310323
}

0 commit comments

Comments
 (0)