Search in sources :

Example 6 with Type

use of org.knime.core.node.workflow.FlowVariable.Type in project knime-core by knime.

the class JavaSnippetNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepo = new FlowVariableRepository(getAvailableInputFlowVariables());
    BufferedDataTable output = m_snippet.execute(inData[0], flowVarRepo, exec);
    for (FlowVariable var : flowVarRepo.getModified()) {
        Type type = var.getType();
        if (type.equals(Type.INTEGER)) {
            pushFlowVariableInt(var.getName(), var.getIntValue());
        } else if (type.equals(Type.DOUBLE)) {
            pushFlowVariableDouble(var.getName(), var.getDoubleValue());
        } else {
            // case: type.equals(Type.STRING)
            pushFlowVariableString(var.getName(), var.getStringValue());
        }
    }
    return new BufferedDataTable[] { output };
}
Also used : Type(org.knime.core.node.workflow.FlowVariable.Type) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) BufferedDataTable(org.knime.core.node.BufferedDataTable) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 7 with Type

use of org.knime.core.node.workflow.FlowVariable.Type 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 OutVarList getOutVarFields() {
    OutVarList outVars = new OutVarList();
    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) {
            OutVar outVar = new OutVar();
            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.setFlowVarType(type);
            } else {
                continue;
            }
            outVar.setJavaName((String) m_model.getValueAt(r, Column.JAVA_FIELD));
            Object javaTypeObject = m_model.getValueAt(r, Column.JAVA_TYPE);
            if (javaTypeObject instanceof Class) {
                outVar.setJavaType((Class) javaTypeObject);
            } else {
                continue;
            }
            outVars.add(outVar);
        }
    }
    return outVars;
}
Also used : FieldType(org.knime.base.node.jsnippet.util.field.JavaField.FieldType) Type(org.knime.core.node.workflow.FlowVariable.Type) DataType(org.knime.core.data.DataType) OutVarList(org.knime.base.node.jsnippet.util.JavaFieldList.OutVarList) OutVar(org.knime.base.node.jsnippet.util.field.OutVar) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 8 with Type

use of org.knime.core.node.workflow.FlowVariable.Type 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)

Example 9 with Type

use of org.knime.core.node.workflow.FlowVariable.Type in project knime-core by knime.

the class FlowObjectStack method getVariableDefinition.

private static final Pair<String, Type> getVariableDefinition(final String propKey) {
    String varName;
    Type varType;
    if (propKey.startsWith("knime.constant.double.")) {
        varName = propKey.substring("knime.constant.double.".length());
        varType = Type.DOUBLE;
    } else if (propKey.startsWith("knime.constant.integer.")) {
        varName = propKey.substring("knime.constant.integer.".length());
        varType = Type.INTEGER;
    } else if (propKey.startsWith("knime.constant.string.")) {
        varName = propKey.substring("knime.constant.string.".length());
        varType = Type.STRING;
    } else {
        return null;
    }
    if (varName.length() == 0) {
        LOGGER.warn("Ignoring constant defintion \"" + propKey + "\": " + "missing suffix, e.g. \"" + propKey + "somename\"");
        return null;
    }
    return new Pair<String, Type>(varName, varType);
}
Also used : IntType(org.knime.core.node.workflow.VariableType.IntType) DoubleType(org.knime.core.node.workflow.VariableType.DoubleType) StringType(org.knime.core.node.workflow.VariableType.StringType) Type(org.knime.core.node.workflow.FlowVariable.Type) Pair(org.knime.core.util.Pair)

Example 10 with Type

use of org.knime.core.node.workflow.FlowVariable.Type in project knime-core by knime.

the class FlowObjectStackView method update.

/**
 * Updates the view to display the given stack.
 * @param stack Whose values are to be displayed.
 */
public void update(final FlowObjectStack stack) {
    final FontMetrics fontMetrics = m_table.getFontMetrics(m_table.getFont());
    List<Object[]> values;
    // relative width of each column - make important columns wider
    int[] colRelativeWidth = new int[4];
    for (int i = 0; i < colRelativeWidth.length; i++) {
        colRelativeWidth[i] = SwingUtilities.computeStringWidth(fontMetrics, COLUMN_NAMES[i]);
    }
    if (stack != null) {
        values = new ArrayList<Object[]>();
        int loopCount = 0;
        int counter = 0;
        Set<Pair<String, Type>> duplicateElementsSet = new HashSet<Pair<String, Type>>();
        for (FlowObject s : stack) {
            Object[] obj = new Object[4];
            obj[0] = Integer.valueOf(counter);
            obj[1] = s.getOwner();
            if (s instanceof FlowVariable) {
                FlowVariable v = (FlowVariable) s;
                final Pair<String, Type> key = new Pair<String, Type>(v.getName(), v.getType());
                if (!duplicateElementsSet.add(key)) {
                    continue;
                }
                obj[2] = s;
                obj[3] = v.getValueAsString();
            } else if (s instanceof FlowLoopContext) {
                duplicateElementsSet.clear();
                if (!((FlowLoopContext) s).isInactiveScope()) {
                    obj[2] = "Loop (" + (loopCount++) + ")";
                    obj[3] = null;
                } else {
                    obj[2] = "Inactive Loop Mark";
                    obj[3] = null;
                }
            } else if (s instanceof InnerFlowLoopExecuteMarker) {
                obj[2] = "Loop-Execute";
                obj[3] = null;
            } else if (s instanceof FlowScopeContext) {
                obj[2] = s.toString() + (((FlowScopeContext) s).isInactiveScope() ? " (inactive)" : "");
                obj[3] = null;
            } else {
                obj[2] = "unknown:" + s.toString();
                obj[3] = null;
            }
            values.add(obj);
            for (int i = 0; i < colRelativeWidth.length; i++) {
                String representation;
                if (obj[i] instanceof FlowVariable) {
                    representation = "ICON" + ((FlowVariable) obj[i]).getName();
                } else {
                    representation = Objects.toString(obj[i], "");
                }
                colRelativeWidth[i] = Math.max(colRelativeWidth[i], SwingUtilities.computeStringWidth(fontMetrics, representation));
            }
        }
    } else {
        values = Collections.emptyList();
    }
    final DefaultTableModel model = (DefaultTableModel) m_table.getModel();
    model.setDataVector(values.toArray(new Object[values.size()][]), COLUMN_NAMES);
    final TableColumnModel columnModel = m_table.getColumnModel();
    for (int i = 0; i < colRelativeWidth.length; i++) {
        columnModel.getColumn(i).setPreferredWidth(colRelativeWidth[i]);
    }
    m_table.setCellSelectionEnabled(true);
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumnModel(javax.swing.table.TableColumnModel) Type(org.knime.core.node.workflow.FlowVariable.Type) FontMetrics(java.awt.FontMetrics) Pair(org.knime.core.util.Pair) HashSet(java.util.HashSet)

Aggregations

Type (org.knime.core.node.workflow.FlowVariable.Type)10 FlowVariable (org.knime.core.node.workflow.FlowVariable)7 DataType (org.knime.core.data.DataType)5 FieldType (org.knime.base.node.jsnippet.util.field.JavaField.FieldType)3 JavaToDataCellConverterFactory (org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory)3 Optional (java.util.Optional)2 TypeConverter (org.knime.base.node.jsnippet.type.flowvar.TypeConverter)2 FlowVariableRepository (org.knime.base.node.jsnippet.util.FlowVariableRepository)2 OutVarList (org.knime.base.node.jsnippet.util.JavaFieldList.OutVarList)2 OutVar (org.knime.base.node.jsnippet.util.field.OutVar)2 Pair (org.knime.core.util.Pair)2 FontMetrics (java.awt.FontMetrics)1 Closeable (java.io.Closeable)1 Array (java.lang.reflect.Array)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EventObject (java.util.EventObject)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1