Search in sources :

Example 1 with FieldType

use of org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType in project knime-core by knime.

the class OutFieldsTable method updateData.

/**
 * Set the table data.
 *
 * @param fields the fields
 * @param spec the input spec
 * @param flowVars the flow variables
 */
public void updateData(final FieldCollection fields, final DataTableSpec spec, final Map<String, FlowVariable> flowVars) {
    m_spec = spec;
    m_flowVars = flowVars;
    m_model.clear();
    for (int r = 0; r < fields.getOutColumnList().size(); r++) {
        OutColumnField field = fields.getOutColumnList().get(r);
        addRow(field);
    }
    for (int r = 0; r < fields.getOutFlowVariableList().size(); r++) {
        OutFlowVariableField field = fields.getOutFlowVariableList().get(r);
        addRow(field);
    }
    JTable table = getTable();
    table.getColumnModel().getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellRenderer(new BooleanRenderer());
    table.getColumnModel().getColumn(m_model.getIndex(Column.REPLACE_EXISTING)).setCellEditor(new DefaultCellEditor(new JCheckBox()));
    if (!m_flowVarsOnly) {
        table.getColumnModel().getColumn(m_model.getIndex(Column.FIELD_TYPE)).setCellEditor(createFieldTypeCellEditor());
    }
    table.getColumnModel().getColumn(m_model.getIndex(Column.COLUMN)).setCellRenderer(new InputTableCellRenderer());
    table.getColumnModel().getColumn(m_model.getIndex(Column.COLUMN)).setCellEditor(new InputTableCellEditor(this, m_spec, m_flowVars));
    table.getColumnModel().getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellRenderer(new DataTypeTableCellRenderer());
    table.getColumnModel().getColumn(m_model.getIndex(Column.DATA_TYPE)).setCellEditor(new DataTypeTableCellEditor(this, m_spec, m_flowVars));
    if (!m_flowVarsOnly) {
        table.getColumnModel().getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellRenderer(new BooleanRenderer() {

            /**
             * {@inheritDoc}
             */
            @Override
            public Component getTableCellRendererComponent(final JTable fooTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
                Component comp = super.getTableCellRendererComponent(fooTable, value, isSelected, hasFocus, row, column);
                FieldType fieldType = getFieldType(row);
                comp.setEnabled(fieldType.equals(FieldType.Column));
                return comp;
            }
        });
        table.getColumnModel().getColumn(m_model.getIndex(Column.IS_COLLECTION)).setCellEditor(new DefaultCellEditor(new JCheckBox()) {

            /**
             * {@inheritDoc}
             */
            @Override
            public boolean isCellEditable(final EventObject anEvent) {
                int row = getTable().rowAtPoint(((MouseEvent) anEvent).getPoint());
                FieldType fieldType = getFieldType(row);
                return fieldType.equals(FieldType.Column);
            }
        });
    }
    if (m_defineDefaultValues) {
        table.getColumnModel().getColumn(m_model.getIndex(Column.DEFAULT_VALUE)).setCellRenderer(new DefaultFieldTableCellRenderer());
    }
}
Also used : OutColumnField(org.knime.core.node.util.dialog.field.OutColumnField) MouseEvent(java.awt.event.MouseEvent) EventObject(java.util.EventObject) DefaultCellEditor(javax.swing.DefaultCellEditor) FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) JCheckBox(javax.swing.JCheckBox) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) OutFlowVariableField(org.knime.core.node.util.dialog.field.OutFlowVariableField) JTable(javax.swing.JTable) EventObject(java.util.EventObject) Component(java.awt.Component)

Example 2 with FieldType

use of org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType in project knime-core by knime.

the class OutFieldsTable method createFieldTypeCellEditor.

// CELL EDITORS
/**
 * Create cell editor for for the input columns / flow variables.
 * @return an editor for the type field
 */
protected TableCellEditor createFieldTypeCellEditor() {
    JComboBox<FieldType> comboBox = new JComboBox<FieldType>();
    comboBox.addItem(FieldType.Column);
    comboBox.addItem(FieldType.FlowVariable);
    DefaultCellEditor editor = new DefaultCellEditor(comboBox);
    editor.setClickCountToStart(2);
    return editor;
}
Also used : JComboBox(javax.swing.JComboBox) FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

DefaultCellEditor (javax.swing.DefaultCellEditor)2 FieldType (org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType)2 Component (java.awt.Component)1 MouseEvent (java.awt.event.MouseEvent)1 EventObject (java.util.EventObject)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JTable (javax.swing.JTable)1 DefaultOutFlowVariableField (org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField)1 OutColumnField (org.knime.core.node.util.dialog.field.OutColumnField)1 OutFlowVariableField (org.knime.core.node.util.dialog.field.OutFlowVariableField)1