Skip to content

Commit 3d32bb1

Browse files
committed
GUI: added possibility of output table's rows move up/down
1 parent fb645ef commit 3d32bb1

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.Iterator;
2222
import java.util.Map;
2323

24-
import javax.swing.AbstractAction;
24+
import javax.swing.Box;
2525
import javax.swing.BoxLayout;
2626
import javax.swing.DefaultCellEditor;
2727
import javax.swing.JButton;
@@ -100,10 +100,8 @@ private final void createColumnSelectionTab() {
100100
m_appendColsCB = new JCheckBox("Append columns to input table spec");
101101
newtableCBPanel.add(m_appendColsCB, BorderLayout.WEST);
102102

103-
JButton addButton = new JButton(new AbstractAction() {
104-
105-
private static final long serialVersionUID = -743704737927962277L;
106-
103+
JButton addButton = new JButton("Add Output Column");
104+
addButton.addActionListener( new ActionListener() {
107105
public void actionPerformed(final ActionEvent e) {
108106
String name;
109107
ScriptNodeOutputColumnsTableModel model = ((ScriptNodeOutputColumnsTableModel) m_table
@@ -126,12 +124,9 @@ public void actionPerformed(final ActionEvent e) {
126124
model.addRow(name, "String");
127125
}
128126
});
129-
addButton.setText("Add Output Column");
130-
131-
JButton removeButton = new JButton(new AbstractAction() {
132-
133-
private static final long serialVersionUID = 743704737927962277L;
134127

128+
JButton removeButton = new JButton("Remove Output Column");
129+
removeButton.addActionListener( new ActionListener() {
135130
public void actionPerformed(final ActionEvent e) {
136131
int[] selectedRows = m_table.getSelectedRows();
137132
logger.debug("selectedRows = " + selectedRows);
@@ -148,10 +143,41 @@ public void actionPerformed(final ActionEvent e) {
148143
}
149144
}
150145
});
151-
removeButton.setText("Remove Output Column");
146+
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+
});
152175

153176
outputButtonPanel.add(addButton);
154177
outputButtonPanel.add(removeButton);
178+
outputButtonPanel.add(Box.createHorizontalStrut(40));
179+
outputButtonPanel.add(upButton);
180+
outputButtonPanel.add(downButton);
155181

156182
m_table = new JTable();
157183
m_table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
@@ -211,9 +237,8 @@ private final void createScriptTab() {
211237
JPanel scriptButtonPanel = new JPanel();
212238

213239
// script load button
214-
JButton scriptButton = new JButton(new AbstractAction() {
215-
216-
private static final long serialVersionUID = 6097485154386131768L;
240+
JButton scriptButton = new JButton("Load Script from File");
241+
scriptButton.addActionListener( new ActionListener() {
217242
private JFileChooser fileChooser = new JFileChooser();
218243

219244
public void actionPerformed(final ActionEvent e) {
@@ -252,7 +277,6 @@ public void actionPerformed(final ActionEvent e) {
252277
clearErrorHighlight();
253278
}
254279
});
255-
scriptButton.setText("Load Script from File");
256280
scriptButtonPanel.add(scriptButton);
257281

258282
JPanel scriptMainPanel = new JPanel(new BorderLayout());
@@ -273,7 +297,9 @@ public void actionPerformed(final ActionEvent e) {
273297

274298
JPanel inputColumnsPanel = new JPanel();
275299
inputColumnsPanel.setLayout(new BoxLayout(inputColumnsPanel, BoxLayout.PAGE_AXIS));
276-
inputColumnsPanel.setMinimumSize(new Dimension(20, 150));
300+
301+
if (num > 0)
302+
inputColumnsPanel.setMinimumSize(new Dimension(20, 150));
277303

278304
for (int i = 0; i < num; i++) {
279305
inputColumnsPanel.add(addColumnPane(

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final boolean isCellEditable(int row, int col) {
3232
return !m_readOnly;
3333
}
3434

35-
public final void setReadOnly(boolean readOnly){
35+
public final void setReadOnly(boolean readOnly) {
3636
m_readOnly = readOnly;
3737
}
3838

@@ -87,4 +87,20 @@ private String[] getDataTableValues(final int colIndex) {
8787
public final void clearRows() {
8888
data = new ArrayList<ArrayList<Object>>();
8989
}
90+
91+
public final void moveRowsUp(int[] rows) {
92+
for (int j = 0; j < rows.length; j++) {
93+
if (rows[j] != 0)
94+
Collections.swap(data, rows[j], rows[j] - 1);
95+
}
96+
fireTableDataChanged();
97+
}
98+
99+
public final void moveRowsDown(int[] rows) {
100+
for (int j = rows.length - 1; j >= 0; j--) {
101+
if (rows[j] != data.size() - 1)
102+
Collections.swap(data, rows[j], rows[j] + 1);
103+
}
104+
fireTableDataChanged();
105+
}
90106
}

0 commit comments

Comments
 (0)