Search in sources :

Example 81 with FlowVariable

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

the class JavaScriptingPanel method loadSettingsFrom.

/**
 * Load settings from arg.
 * @param s To load from.
 * @param spec The input spec.
 */
public void loadSettingsFrom(final JavaScriptingSettings s, final DataTableSpec spec) {
    String exp = s.getExpression();
    String header = s.getHeader();
    String rType = s.getReturnType().getName();
    boolean isArrayReturn = s.isArrayReturn();
    String defaultNewName = m_customizer.getOutputIsVariable() ? "new variable" : "new column";
    String newName = s.getColName();
    boolean isReplace = s.isReplace();
    boolean isTestCompilation = s.isTestCompilationOnDialogClose();
    boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
    m_currentVersion = s.getExpressionVersion();
    m_newNameField.setText("");
    // will select newColName only if it is in the spec list
    try {
        m_replaceColumnCombo.update(spec, newName);
    } catch (NotConfigurableException e1) {
        NodeLogger.getLogger(getClass()).coding("Combo box throws " + "exception although content is not required", e1);
    }
    DefaultComboBoxModel cmbModel = (DefaultComboBoxModel) m_replaceVariableCombo.getModel();
    cmbModel.removeAllElements();
    final Map<String, FlowVariable> availableFlowVariables = m_varProvider.getAvailableFlowVariables();
    for (FlowVariable v : availableFlowVariables.values()) {
        switch(v.getScope()) {
            case Flow:
                cmbModel.addElement(v);
                break;
            default:
        }
    }
    if (isReplace && availableFlowVariables.containsKey(newName)) {
        m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
    }
    m_currentSpec = spec;
    // whether there are variables or columns available
    // -- which of two depends on the customizer
    boolean fieldsAvailable;
    if (m_customizer.getOutputIsVariable()) {
        fieldsAvailable = m_replaceVariableCombo.getModel().getSize() > 0;
    } else {
        fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
    }
    if (isReplace && fieldsAvailable) {
        m_replaceRadio.doClick();
    } else {
        m_appendRadio.doClick();
        String newNameString = (newName != null ? newName : defaultNewName);
        m_newNameField.setText(newNameString);
    }
    m_replaceRadio.setEnabled(fieldsAvailable);
    m_headerEdit.setText(header);
    m_expEdit.setText(exp);
    m_expEdit.requestFocus();
    ButtonModel firstButton = null;
    for (Enumeration<?> e = m_returnTypeButtonGroup.getElements(); e.hasMoreElements(); ) {
        AbstractButton b = (AbstractButton) e.nextElement();
        if (firstButton == null) {
            firstButton = b.getModel();
        }
        if (b.getActionCommand().equals(rType)) {
            m_returnTypeButtonGroup.setSelected(b.getModel(), true);
        }
    }
    if (m_returnTypeButtonGroup.getSelection() == null) {
        m_returnTypeButtonGroup.setSelected(firstButton, true);
    }
    m_isArrayReturnChecker.setSelected(isArrayReturn);
    DefaultListModel listModel = (DefaultListModel) m_colList.getModel();
    listModel.removeAllElements();
    if (m_currentVersion == Expression.VERSION_1X) {
        listModel.addElement(Expression.ROWKEY);
        listModel.addElement(Expression.ROWNUMBER);
    } else {
        listModel.addElement(Expression.ROWID);
        listModel.addElement(Expression.ROWINDEX);
        listModel.addElement(Expression.ROWCOUNT);
    }
    for (int i = 0; i < spec.getNumColumns(); i++) {
        DataColumnSpec colSpec = spec.getColumnSpec(i);
        listModel.addElement(colSpec);
    }
    DefaultListModel fvListModel = (DefaultListModel) m_flowVarsList.getModel();
    fvListModel.removeAllElements();
    for (FlowVariable v : availableFlowVariables.values()) {
        fvListModel.addElement(v);
    }
    m_compileOnCloseChecker.setSelected(isTestCompilation);
    m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) AbstractButton(javax.swing.AbstractButton) DataColumnSpec(org.knime.core.data.DataColumnSpec) DefaultListModel(javax.swing.DefaultListModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) ButtonModel(javax.swing.ButtonModel) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 82 with FlowVariable

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

the class JavaSnippet method configure.

/**
 * Create the outspec of the java snippet node. This method is typically used in the configure of a node.
 *
 * @param spec the spec of the data table at the inport
 * @param flowVariableRepository the flow variables at the inport
 * @return the spec at the output
 * @throws InvalidSettingsException when settings are inconsistent with the spec or the flow variables at the inport
 */
public DataTableSpec configure(final DataTableSpec spec, final FlowVariableRepository flowVariableRepository) throws InvalidSettingsException {
    DataTableSpec outSpec = createRearranger(spec, flowVariableRepository, -1, null).createSpec();
    // default values
    for (OutVar outVar : m_fields.getOutVarFields()) {
        FlowVariable flowVar = null;
        if (outVar.getFlowVarType().equals(org.knime.core.node.workflow.FlowVariable.Type.INTEGER)) {
            flowVar = new FlowVariable(outVar.getKnimeName(), -1);
        } else if (outVar.getFlowVarType().equals(org.knime.core.node.workflow.FlowVariable.Type.DOUBLE)) {
            flowVar = new FlowVariable(outVar.getKnimeName(), -1.0);
        } else {
            flowVar = new FlowVariable(outVar.getKnimeName(), "");
        }
        flowVariableRepository.put(flowVar);
    }
    return outSpec;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) OutVar(org.knime.base.node.jsnippet.util.field.OutVar) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 83 with FlowVariable

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

the class JavaEditVarNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
    ValidationReport report = m_snippet.validateSettings(new DataTableSpec(), flowVarRepository);
    if (report.hasWarnings()) {
        setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
    }
    if (report.hasErrors()) {
        throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
    }
    m_snippet.configure(new DataTableSpec(), flowVarRepository);
    for (FlowVariable flowVar : flowVarRepository.getModified()) {
        if (flowVar.getType().equals(Type.INTEGER)) {
            pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
        } else if (flowVar.getType().equals(Type.DOUBLE)) {
            pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
        } else {
            pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
        }
    }
    // execute if execute on config flag is set
    if (!m_settings.isRunOnExecute()) {
        performExecute(null);
    }
    return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 84 with FlowVariable

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

the class JavaSnippetNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    m_snippet.setSettings(m_settings);
    FlowVariableRepository flowVarRepository = new FlowVariableRepository(getAvailableInputFlowVariables());
    // The following method also compile-checks the code and checks for missing converter factories
    ValidationReport report = m_snippet.validateSettings(inSpecs[0], flowVarRepository);
    if (report.hasWarnings()) {
        setWarningMessage(StringUtils.join(report.getWarnings(), "\n"));
    }
    if (report.hasErrors()) {
        throw new InvalidSettingsException(StringUtils.join(report.getErrors(), "\n"));
    }
    DataTableSpec outSpec = m_snippet.configure(inSpecs[0], flowVarRepository);
    for (FlowVariable flowVar : flowVarRepository.getModified()) {
        if (flowVar.getType().equals(Type.INTEGER)) {
            pushFlowVariableInt(flowVar.getName(), flowVar.getIntValue());
        } else if (flowVar.getType().equals(Type.DOUBLE)) {
            pushFlowVariableDouble(flowVar.getName(), flowVar.getDoubleValue());
        } else {
            pushFlowVariableString(flowVar.getName(), flowVar.getStringValue());
        }
    }
    return new DataTableSpec[] { outSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) FlowVariableRepository(org.knime.base.node.jsnippet.util.FlowVariableRepository) ValidationReport(org.knime.base.node.jsnippet.util.ValidationReport) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 85 with FlowVariable

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

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