use of org.knime.core.node.util.DataColumnSpecTableCellRenderer in project knime-core by knime.
the class RankNodeDialog method initRankTableBox.
private Box initRankTableBox() {
Box columnTableBox = Box.createVerticalBox();
columnTableBox.setBorder(new TitledBorder("Ranking Attributes"));
m_rankTableModel = new DefaultTableModel(new String[] { "Attribute", "Order" }, 0);
DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
m_rankJTable = new JTable(m_rankTableModel, columnModel);
m_rankJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
m_rankJTable.setCellSelectionEnabled(false);
m_rankJTable.setColumnSelectionAllowed(false);
m_rankJTable.getTableHeader().setReorderingAllowed(false);
m_rankJTable.setRowSelectionAllowed(true);
TableColumn colColumn = new TableColumn();
colColumn.setHeaderValue("Column");
colColumn.setCellRenderer(new DataColumnSpecTableCellRenderer());
m_rankColEditorModel = new DefaultComboBoxModel<DataColumnSpec>();
m_rankColEditor = new JComboBox<DataColumnSpec>(m_rankColEditorModel);
m_rankColEditor.setRenderer(new DataColumnSpecListCellRenderer());
m_rankColEditor.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
// TODO Auto-generated method stub
if (!m_availableEdited) {
DataColumnSpec colSpec = (DataColumnSpec) e.getItem();
int state = e.getStateChange();
if (state == ItemEvent.SELECTED && m_rankJTable.isEditing()) {
m_availableCols.remove(colSpec);
removeItemGroupColEditor(colSpec);
// removeItemRankColEditor(colSpec);
m_rankCols.add(colSpec);
} else if (state == ItemEvent.DESELECTED && m_rankJTable.isEditing()) {
m_rankCols.remove(colSpec);
if (!m_rankCols.contains(colSpec)) {
add2AvailableList(colSpec);
addItemGroupColEditor(colSpec);
}
}
}
}
});
colColumn.setCellEditor(new DefaultCellEditor(m_rankColEditor));
TableColumn orderColumn = new TableColumn(1);
orderColumn.setHeaderValue("Order");
// combo box for order column
JComboBox<String> orderColumnEditor = new JComboBox<String>();
orderColumnEditor.addItem("Ascending");
orderColumnEditor.addItem("Descending");
orderColumn.setCellEditor(new DefaultCellEditor(orderColumnEditor));
columnModel.addColumn(colColumn);
columnModel.addColumn(orderColumn);
JScrollPane scrollPane = new JScrollPane(m_rankJTable);
scrollPane.setPreferredSize(m_rankJTable.getPreferredSize());
columnTableBox.add(scrollPane);
columnTableBox.setSize(scrollPane.getSize());
return columnTableBox;
}
use of org.knime.core.node.util.DataColumnSpecTableCellRenderer in project knime-core by knime.
the class RankNodeDialog method initGroupTableBox.
private Box initGroupTableBox() {
Box groupTableBox = Box.createVerticalBox();
groupTableBox.setBorder(new TitledBorder("Grouping Attributes"));
m_groupTableModel = new DefaultTableModel(new String[] { "Attribute" }, 0);
m_groupJTable = new JTable(m_groupTableModel);
m_groupJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn column = m_groupJTable.getColumn("Attribute");
column.setCellRenderer(new DataColumnSpecTableCellRenderer());
m_groupColEditorModel = new DefaultComboBoxModel<DataColumnSpec>();
m_groupColEditor = new JComboBox<DataColumnSpec>(m_groupColEditorModel);
m_groupColEditor.setRenderer(new DataColumnSpecListCellRenderer());
m_groupColEditor.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(final ItemEvent e) {
if (!m_availableEdited) {
DataColumnSpec colSpec = (DataColumnSpec) e.getItem();
int state = e.getStateChange();
if (state == ItemEvent.SELECTED && m_groupJTable.isEditing()) {
m_availableCols.remove(colSpec);
removeItemRankColEditor(colSpec);
m_groupCols.add(colSpec);
} else if (state == ItemEvent.DESELECTED && m_groupJTable.isEditing()) {
m_groupCols.remove(colSpec);
if (!m_groupCols.contains(colSpec)) {
add2AvailableList(colSpec);
addItemRankColEditor(colSpec);
}
}
}
}
});
column.setCellEditor(new DefaultCellEditor(m_groupColEditor));
JScrollPane scrollPane = new JScrollPane(m_groupJTable);
scrollPane.setMinimumSize(m_rankJTable.getPreferredSize());
scrollPane.setPreferredSize(m_rankJTable.getPreferredSize());
groupTableBox.add(new JScrollPane(scrollPane));
return groupTableBox;
}
Aggregations