Search in sources :

Example 1 with OutFlowVariableList

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

EventObject (java.util.EventObject)1 DataType (org.knime.core.data.DataType)1 FieldType (org.knime.core.node.util.dialog.OutFieldsTableModel.FieldType)1 DefaultOutFlowVariableField (org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField)1 OutFlowVariableList (org.knime.core.node.util.dialog.field.FieldList.OutFlowVariableList)1 OutFlowVariableField (org.knime.core.node.util.dialog.field.OutFlowVariableField)1 FlowVariable (org.knime.core.node.workflow.FlowVariable)1 Type (org.knime.core.node.workflow.FlowVariable.Type)1