Search in sources :

Example 1 with ShapeSelectionComboBoxRenderer

use of org.knime.core.data.property.ShapeSelectionComboBoxRenderer in project knime-core by knime.

the class ShapeManagerNodeDialogPane method columnChanged.

private void columnChanged(final String column) {
    final LinkedHashMap<DataCell, Shape> domMap = m_map.get(column);
    TableModel tableModel = new DefaultTableModel() {

        private final DataCell[] m_valueNames = new DataCell[domMap.size()];

        {
            int row = 0;
            for (DataCell cell : domMap.keySet()) {
                m_valueNames[row] = cell;
                row++;
            }
        }

        @Override
        public String getColumnName(final int columnIdx) {
            if (columnIdx == 1) {
                return "Shapes";
            } else {
                return "Values of " + column;
            }
        }

        @Override
        public boolean isCellEditable(final int row, final int columnIdx) {
            return (columnIdx == 1);
        }

        @Override
        public int getRowCount() {
            return domMap.size();
        }

        @Override
        public int getColumnCount() {
            return 2;
        }

        @Override
        public Class<?> getColumnClass(final int columnIndex) {
            if (columnIndex == 1) {
                return Shape.class;
            } else {
                return DataCell.class;
            }
        }

        @Override
        public Object getValueAt(final int row, final int columnIndex) {
            if (columnIndex == 1) {
                return domMap.get(m_valueNames[row]);
            } else {
                return m_valueNames[row];
            }
        }

        @Override
        public void setValueAt(final Object aValue, final int row, final int columnIdx) {
            assert aValue instanceof Shape;
            assert columnIdx == 1;
            domMap.put(m_valueNames[row], (Shape) aValue);
        }
    };
    m_valueTable.setModel(tableModel);
    m_valueTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(new ShapeSelectionComboBox()));
    m_valueTable.getColumnModel().getColumn(1).setCellRenderer(new ShapeSelectionComboBoxRenderer());
}
Also used : Shape(org.knime.core.data.property.ShapeFactory.Shape) ShapeSelectionComboBox(org.knime.core.data.property.ShapeSelectionComboBox) DefaultTableModel(javax.swing.table.DefaultTableModel) DataCell(org.knime.core.data.DataCell) ShapeSelectionComboBoxRenderer(org.knime.core.data.property.ShapeSelectionComboBoxRenderer) TableModel(javax.swing.table.TableModel) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)1 DefaultTableModel (javax.swing.table.DefaultTableModel)1 TableModel (javax.swing.table.TableModel)1 DataCell (org.knime.core.data.DataCell)1 Shape (org.knime.core.data.property.ShapeFactory.Shape)1 ShapeSelectionComboBox (org.knime.core.data.property.ShapeSelectionComboBox)1 ShapeSelectionComboBoxRenderer (org.knime.core.data.property.ShapeSelectionComboBoxRenderer)1