Search in sources :

Example 51 with FlowVariable

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

the class VariableLoopEndNodeModel method getCompatibleDataCell.

/**
 * Creates and returns an instance of <code>DataCell</code>. The cell
 * is of a compatible type according to the type of the given flow var
 * and the value of the cell is equal to the value of the flow var.
 *
 * @param var The flow variable to create a data cell for (with compatible
 * type and equal value).
 * @return an instance of <code>DataCell</code> with compatible type to the
 * given flow var and equal value.
 * @throws InvalidSettingsException If given flow var is of any
 * unsupported type.
 */
private static DataCell getCompatibleDataCell(final FlowVariable var) throws InvalidSettingsException {
    DataCell cell;
    FlowVariable.Type flowType = var.getType();
    switch(flowType) {
        case DOUBLE:
            cell = new DoubleCell(var.getDoubleValue());
            break;
        case INTEGER:
            cell = new IntCell(var.getIntValue());
            break;
        case STRING:
            cell = new StringCell(var.getStringValue());
            break;
        default:
            throw new InvalidSettingsException("Unsupported variable type: " + flowType);
    }
    return cell;
}
Also used : StringCell(org.knime.core.data.def.StringCell) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) FlowVariable(org.knime.core.node.workflow.FlowVariable) IntCell(org.knime.core.data.def.IntCell)

Example 52 with FlowVariable

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

the class VariableLoopEndNodeModel method createDataTableSpec.

/**
 * Creates and returns a new instance of <code>DataTableSpec</code>. The
 * spec consists of one column for each specified and available flow
 * variable. If any specified variable is not available an exception will
 * be thrown.
 * @return A new instance of <code>DataTableSpec</code>. The spec consists
 * of one column for each specified and available flow variable.
 * @throws InvalidSettingsException If any specified flow variable is not
 * available.
 */
private DataTableSpec createDataTableSpec() throws InvalidSettingsException {
    // get available flow vars and selected vars
    Map<String, FlowVariable> availableFlowVars = getAvailableFlowVariables();
    // for now take all variable names
    String[] flowVarNames = m_selection.applyTo(availableFlowVars).getIncludes();
    DataColumnSpec[] colSpecs = new DataColumnSpec[0];
    // create for each  specified flow variable a column spec, if available
    if (flowVarNames != null && flowVarNames.length > 0) {
        colSpecs = new DataColumnSpec[flowVarNames.length];
        for (int i = 0; i < flowVarNames.length; i++) {
            String varName = flowVarNames[i];
            FlowVariable var = availableFlowVars.get(varName);
            // if flow var is available create col spec for var type
            if (var != null) {
                colSpecs[i] = new DataColumnSpecCreator(varName, getCompatibleDataType(var.getType())).createSpec();
            // if specified flow var is not available fail
            } else {
                throw new InvalidSettingsException("Specified flow variable " + varName + " is not available!");
            }
        }
    }
    return new DataTableSpec(colSpecs);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 53 with FlowVariable

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

the class VirtualSubNodeInputNodeModel method pushFlowVariables.

/**
 * @throws Exception
 */
private void pushFlowVariables() throws InvalidSettingsException {
    String prefix = m_configuration.getFlowVariablePrefix() == null ? "" : m_configuration.getFlowVariablePrefix();
    FlowVariableFilterConfiguration filterConfiguration = m_configuration.getFilterConfiguration();
    Map<String, FlowVariable> availableVariables = getSubNodeContainerFlowObjectStack().getAvailableFlowVariables(Type.values());
    FilterResult filtered = filterConfiguration.applyTo(availableVariables);
    for (String include : filtered.getIncludes()) {
        FlowVariable f = availableVariables.get(include);
        switch(f.getScope()) {
            case Global:
                // ignore global flow vars
                continue;
            case Flow:
            case Local:
            default:
        }
        final String name = prefix + f.getName();
        Node.invokePushFlowVariable(this, f.withNewName(name));
    }
}
Also used : FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) FlowVariableFilterConfiguration(org.knime.core.node.util.filter.variable.FlowVariableFilterConfiguration) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 54 with FlowVariable

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

the class FlowVariableTableCellRenderer method getTableCellRendererComponent.

/**
 * {@inheritDoc}
 */
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (value instanceof FlowVariable) {
        FlowVariable v = (FlowVariable) value;
        Icon icon;
        setText(v.getName());
        String curValue;
        switch(v.getType()) {
            case DOUBLE:
                icon = FlowVariableListCellRenderer.FLOW_VAR_DOUBLE_ICON;
                curValue = Double.toString(v.getDoubleValue());
                break;
            case INTEGER:
                icon = FlowVariableListCellRenderer.FLOW_VAR_INT_ICON;
                curValue = Integer.toString(v.getIntValue());
                break;
            case STRING:
                icon = FlowVariableListCellRenderer.FLOW_VAR_STRING_ICON;
                curValue = v.getStringValue();
                break;
            default:
                icon = DataValue.UTILITY.getIcon();
                curValue = v.toString();
        }
        setIcon(icon);
        StringBuilder b = new StringBuilder(v.getName());
        b.append(" (");
        if (v.getName().startsWith("knime.")) {
            // constant
            b.append("constant: ");
        } else {
            b.append("current value: ");
        }
        b.append(curValue);
        b.append(")");
        setToolTipText(b.toString());
    } else {
        setIcon(null);
        setToolTipText(null);
    }
    return c;
}
Also used : Icon(javax.swing.Icon) Component(java.awt.Component) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 55 with FlowVariable

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

the class FlowVariableListCellRenderer method getListCellRendererComponent.

/**
 * {@inheritDoc}
 */
@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
    Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    FlowVariable flowVariable = null;
    if (value instanceof FlowVariable) {
        flowVariable = (FlowVariable) value;
    } else if (value instanceof FlowVariableCell) {
        // Added for bug 4601 to display missing flow variables
        FlowVariableCell flowVariableCell = (FlowVariableCell) value;
        if (flowVariableCell.isValid()) {
            // Display as normal flow variable
            flowVariable = flowVariableCell.getFlowVariable();
        } else {
            // Display missing variable by known name and with missing icon and red border
            setText(flowVariableCell.getName());
            setIcon(FLOW_VAR_INVALID_ICON);
            setToolTipText(null);
            setBorder(BorderFactory.createLineBorder(Color.red));
        }
    } else {
        // Value is neither flow variable nor flow variable cell, do nothing
        setToolTipText(null);
    }
    // If flow variable was found either directly as value or inside flow variable cell
    if (flowVariable != null) {
        FlowVariable v = flowVariable;
        Icon icon;
        setText(v.getName());
        String curValue;
        switch(v.getType()) {
            case DOUBLE:
                icon = FLOW_VAR_DOUBLE_ICON;
                curValue = Double.toString(v.getDoubleValue());
                break;
            case INTEGER:
                icon = FLOW_VAR_INT_ICON;
                curValue = Integer.toString(v.getIntValue());
                break;
            case STRING:
                icon = FLOW_VAR_STRING_ICON;
                curValue = v.getStringValue();
                break;
            default:
                icon = DataValue.UTILITY.getIcon();
                curValue = v.toString();
        }
        setIcon(icon);
        StringBuilder b = new StringBuilder(v.getName());
        b.append(" (");
        if (v.getName().startsWith("knime.")) {
            // constant
            b.append("constant: ");
        } else {
            b.append("current value: ");
        }
        b.append(curValue);
        b.append(")");
        setToolTipText(b.toString());
    }
    return c;
}
Also used : ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) Component(java.awt.Component) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

FlowVariable (org.knime.core.node.workflow.FlowVariable)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)24 DataColumnSpec (org.knime.core.data.DataColumnSpec)14 DataType (org.knime.core.data.DataType)13 DataTableSpec (org.knime.core.data.DataTableSpec)11 ArrayList (java.util.ArrayList)10 PortType (org.knime.core.node.port.PortType)8 DefaultListModel (javax.swing.DefaultListModel)7 Type (org.knime.core.node.workflow.FlowVariable.Type)7 IOException (java.io.IOException)6 Map (java.util.Map)6 PortObject (org.knime.core.node.port.PortObject)6 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 OutVar (org.knime.base.node.jsnippet.util.field.OutVar)5 BufferedDataTable (org.knime.core.node.BufferedDataTable)5 URL (java.net.URL)4 ParseException (java.text.ParseException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4