Search in sources :

Example 61 with FlowVariable

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

the class OutFieldsTable method createAddButtonListener.

/**
 * {@inheritDoc}
 */
@Override
protected ActionListener createAddButtonListener() {
    return new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            DataColumnSpec defaultColTarget = null;
            if (null != m_spec) {
                Set<String> cols = new HashSet<>();
                for (int r = 0; r < m_model.getRowCount(); r++) {
                    Object value = m_model.getValueAt(r, Column.COLUMN);
                    if (value instanceof DataColumnSpec) {
                        cols.add(((DataColumnSpec) value).getName());
                    }
                }
                defaultColTarget = null;
                for (DataColumnSpec colSpec : m_spec) {
                    if (null == defaultColTarget) {
                        defaultColTarget = colSpec;
                    }
                    if (!cols.contains(colSpec.getName())) {
                        // Add a row and fill it
                        boolean rowAdded = addRow(colSpec);
                        if (rowAdded) {
                            firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
                        }
                        return;
                    }
                }
            }
            FlowVariable defaultVarTarget = null;
            if (null != m_flowVars) {
                Set<String> flowVars = new HashSet<>();
                for (int r = 0; r < m_model.getRowCount(); r++) {
                    Object value = m_model.getValueAt(r, Column.COLUMN);
                    if (value instanceof FlowVariable) {
                        flowVars.add(((FlowVariable) value).getName());
                    }
                }
                defaultVarTarget = null;
                for (FlowVariable flowVar : m_flowVars.values()) {
                    // created.
                    if (OutFieldsTableModel.verifyNameOfFlowVariable(flowVar.getName())) {
                        if (null == defaultVarTarget) {
                            defaultVarTarget = flowVar;
                        }
                        if (!flowVars.contains(flowVar.getName())) {
                            // Add a row and fill it
                            boolean rowAdded = addRow(flowVar);
                            if (rowAdded) {
                                firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
                            }
                            return;
                        }
                    }
                }
            }
            boolean rowAdded = false;
            if (null != defaultColTarget) {
                rowAdded = addRow(defaultColTarget);
            } else if (null != defaultVarTarget) {
                rowAdded = addRow(defaultVarTarget);
            } else {
                rowAdded = addRow("var", Type.STRING);
            }
            if (rowAdded) {
                firePropertyChange(PROP_FIELD_ADDED, m_model.getRowCount() - 1, m_model.getRowCount());
            }
        }
    };
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) EventObject(java.util.EventObject) HashSet(java.util.HashSet) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 62 with FlowVariable

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

the class OutFieldsTable method addRow.

/**
 * Adds a row using the values of the given output variable.
 *
 * @param outVar the output variable definition
 * @return true when the row was added successfully
 */
public boolean addRow(final OutFlowVariableField outVar) {
    int r = m_model.getRowCount();
    m_model.addRow();
    m_model.setValueAt(outVar.getReplaceExisting(), r, Column.REPLACE_EXISTING);
    if (!m_flowVarsOnly) {
        m_model.setValueAt(FieldType.FlowVariable, r, Column.FIELD_TYPE);
    }
    String name = outVar.getKnimeName();
    FlowVariable flowVar = m_flowVars.get(name);
    Object value = null != flowVar ? flowVar : name;
    m_model.setValueAt(value, r, Column.COLUMN);
    m_model.setValueAt(outVar.getKnimeType(), r, Column.DATA_TYPE);
    if (!m_flowVarsOnly) {
        m_model.setValueAt(false, r, Column.IS_COLLECTION);
    }
    if (m_defineDefaultValues && outVar instanceof DefaultOutFlowVariableField) {
        DefaultOutFlowVariableField doV = (DefaultOutFlowVariableField) outVar;
        m_model.setValueAt(doV.getDefaultValue(), r, Column.DEFAULT_VALUE);
    }
    return true;
}
Also used : DefaultOutFlowVariableField(org.knime.core.node.util.dialog.field.DefaultOutFlowVariableField) EventObject(java.util.EventObject) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 63 with FlowVariable

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

the class AppendVariableToTableSettings method loadSettingsFrom.

/**
 * Load settings.
 *
 * @param settings to load
 * @param scopeVariableMap map of keys to scope variables
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final Map<String, FlowVariable> scopeVariableMap) {
    m_variablesOfInterest.clear();
    m_includeAll = settings.getBoolean("all", false);
    NodeSettingsRO sub = null;
    try {
        sub = settings.getNodeSettings("variables");
    } catch (InvalidSettingsException e) {
    // no op
    }
    if (sub != null) {
        final Set<String> keySet = sub.keySet();
        for (String key : keySet) {
            NodeSettingsRO sub2;
            try {
                sub2 = sub.getNodeSettings(key);
            } catch (InvalidSettingsException e) {
                continue;
            }
            String name = sub2.getString("name", null);
            String typeS = sub2.getString("type", null);
            if (name == null || typeS == null) {
                continue;
            }
            FlowVariable.Type type;
            try {
                type = FlowVariable.Type.valueOf(typeS);
            } catch (IllegalArgumentException iae) {
                continue;
            }
            m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 64 with FlowVariable

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

the class VariableToTableSettings method loadSettingsFrom.

/**
 * Load settings.
 *
 * @param settings to load
 * @param scopeVariableMap nap of keys to scope variables
 */
public void loadSettingsFrom(final NodeSettingsRO settings, final Map<String, FlowVariable> scopeVariableMap) {
    m_variablesOfInterest.clear();
    m_includeAll = settings.getBoolean("all", false);
    NodeSettingsRO sub = null;
    try {
        sub = settings.getNodeSettings("variables");
    } catch (InvalidSettingsException e) {
    // no op
    }
    if (sub != null) {
        final Set<String> keySet = sub.keySet();
        for (String key : keySet) {
            NodeSettingsRO sub2;
            try {
                sub2 = sub.getNodeSettings(key);
            } catch (InvalidSettingsException e) {
                continue;
            }
            String name = sub2.getString("name", null);
            String typeS = sub2.getString("type", null);
            if (name == null || typeS == null) {
                continue;
            }
            FlowVariable.Type type;
            try {
                type = FlowVariable.Type.valueOf(typeS);
            } catch (IllegalArgumentException iae) {
                continue;
            }
            m_variablesOfInterest.add(new Pair<String, FlowVariable.Type>(name, type));
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 65 with FlowVariable

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

the class AppendVariableToTableNodeModel method getAllVariables.

private List<Pair<String, FlowVariable.Type>> getAllVariables() {
    Map<String, FlowVariable> currentVars = getAvailableFlowVariables();
    List<Pair<String, FlowVariable.Type>> variables;
    variables = new ArrayList<Pair<String, FlowVariable.Type>>();
    for (FlowVariable v : currentVars.values()) {
        variables.add(new Pair<String, FlowVariable.Type>(v.getName(), v.getType()));
    }
    return variables;
}
Also used : PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) FlowVariable(org.knime.core.node.workflow.FlowVariable) Pair(org.knime.core.util.Pair)

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