Search in sources :

Example 1 with OutFlowVariableField

use of org.knime.core.node.util.dialog.field.OutFlowVariableField 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 OutFlowVariableField

use of org.knime.core.node.util.dialog.field.OutFlowVariableField in project knime-core by knime.

the class AddOutFieldDialog method takeOverSettings.

/**
 * Save settings in field m_result.
 */
@SuppressWarnings("rawtypes")
private AbstractField takeOverSettings() {
    if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
        OutColumnField outCol = new OutColumnField();
        boolean isReplacing = m_replace.isSelected();
        outCol.setReplaceExisting(isReplacing);
        String colName = isReplacing ? ((DataColumnSpec) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
        outCol.setKnimeName(colName);
        DataType elemType = (DataType) m_knimeType.getSelectedItem();
        boolean isCollection = m_isArray.isSelected();
        DataType dataType = isCollection ? ListCell.getCollectionType(elemType) : elemType;
        TypeProvider typeProvider = TypeProvider.getDefault();
        if (!typeProvider.getColumnTypes().contains(elemType)) {
            elemType = new StringCell("").getType();
            isCollection = false;
        }
        outCol.setKnimeType(dataType);
        return outCol;
    } else {
        // flow variable
        OutFlowVariableField outVar = m_defineDefaultValue ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
        boolean isReplacing = m_replace.isSelected();
        outVar.setReplaceExisting(isReplacing);
        String colName = isReplacing ? ((FlowVariable) m_replacedKnimeName.getSelectedItem()).getName() : m_knimeName.getText();
        outVar.setKnimeName(colName);
        FlowVariable.Type type = (FlowVariable.Type) m_knimeType.getSelectedItem();
        outVar.setKnimeType(type);
        if (m_defineDefaultValue) {
            DefaultOutFlowVariableField dFVar = (DefaultOutFlowVariableField) outVar;
            switch(type) {
                case INTEGER:
                    dFVar.setDefaultValue(Integer.parseInt(m_defaultValue.getText()));
                    break;
                case DOUBLE:
                    dFVar.setDefaultValue(Double.parseDouble(m_defaultValue.getText()));
                    break;
                default:
                    dFVar.setDefaultValue(m_defaultValue.getText());
            }
        }
        return outVar;
    }
}
Also used : FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) DataType(org.knime.core.data.DataType) OutColumnField(org.knime.core.node.util.dialog.field.OutColumnField) StringCell(org.knime.core.data.def.StringCell) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) OutFlowVariableField(org.knime.core.node.util.dialog.field.OutFlowVariableField) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) DataType(org.knime.core.data.DataType) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 3 with OutFlowVariableField

use of org.knime.core.node.util.dialog.field.OutFlowVariableField in project knime-core by knime.

the class OutFieldsTable method getOutVarFields.

/**
 * Get the field definitions representing output flow variables.
 *
 * @return fields representing output flow variables
 */
public OutFlowVariableList getOutVarFields() {
    OutFlowVariableList outVars = new OutFlowVariableList(m_defineDefaultValues);
    for (int r = 0; r < m_model.getRowCount(); r++) {
        if (!m_model.validateValues(r)) {
            // there are errors in this row
            continue;
        }
        Object fieldTypeValue = getFieldType(r);
        if (null == fieldTypeValue) {
            continue;
        }
        boolean isFlowVar = fieldTypeValue.equals(FieldType.FlowVariable);
        if (isFlowVar) {
            OutFlowVariableField outVar = m_defineDefaultValues ? new DefaultOutFlowVariableField() : new OutFlowVariableField();
            outVar.setReplaceExisting((Boolean) m_model.getValueAt(r, Column.REPLACE_EXISTING));
            Object colColValue = m_model.getValueAt(r, Column.COLUMN);
            if (colColValue instanceof FlowVariable) {
                FlowVariable flowVar = (FlowVariable) colColValue;
                outVar.setKnimeName(flowVar.getName());
            } else if (colColValue instanceof String) {
                outVar.setKnimeName(colColValue.toString());
            } else {
                continue;
            }
            Object dataTypeValue = m_model.getValueAt(r, Column.DATA_TYPE);
            if (dataTypeValue instanceof Type) {
                Type type = (Type) dataTypeValue;
                outVar.setKnimeType(type);
            } else {
                continue;
            }
            if (m_defineDefaultValues) {
                DefaultOutFlowVariableField dOVar = (DefaultOutFlowVariableField) outVar;
                Object defaultValue = m_model.getValueAt(r, Column.DEFAULT_VALUE);
                switch((Type) dataTypeValue) {
                    case INTEGER:
                        int defInt = defaultValue instanceof String ? Integer.parseInt((String) defaultValue) : (Integer) defaultValue;
                        dOVar.setDefaultValue(defInt);
                        break;
                    case DOUBLE:
                        double defDouble = defaultValue instanceof String ? Double.parseDouble((String) defaultValue) : (Double) defaultValue;
                        dOVar.setDefaultValue(defDouble);
                        break;
                    default:
                        dOVar.setDefaultValue((String) defaultValue);
                }
            }
            outVars.add(outVar);
        }
    }
    return outVars;
}
Also used : FieldType(org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType) Type(org.knime.core.node.workflow.FlowVariable.Type) DataType(org.knime.core.data.DataType) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) OutFlowVariableField(org.knime.core.node.util.dialog.field.OutFlowVariableField) DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) EventObject(java.util.EventObject) OutFlowVariableList(org.knime.core.node.util.dialog.field.FieldList.OutFlowVariableList) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

FieldType (org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType)3 DefaultOutFlowVariableField (org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField)3 OutFlowVariableField (org.knime.core.node.util.dialog.field.OutFlowVariableField)3 EventObject (java.util.EventObject)2 DataType (org.knime.core.data.DataType)2 OutColumnField (org.knime.core.node.util.dialog.field.OutColumnField)2 FlowVariable (org.knime.core.node.workflow.FlowVariable)2 Component (java.awt.Component)1 MouseEvent (java.awt.event.MouseEvent)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JCheckBox (javax.swing.JCheckBox)1 JTable (javax.swing.JTable)1 StringCell (org.knime.core.data.def.StringCell)1 OutFlowVariableList (org.knime.core.node.util.dialog.field.FieldList.OutFlowVariableList)1 Type (org.knime.core.node.workflow.FlowVariable.Type)1