Search in sources :

Example 11 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 OutVar 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.getFlowVarType(), r, Column.DATA_TYPE);
    if (!m_flowVarsOnly) {
        m_model.setValueAt(false, r, Column.IS_COLLECTION);
    }
    m_model.setValueAt(outVar.getJavaName(), r, Column.JAVA_FIELD);
    m_model.setValueAt(outVar.getJavaType(), r, Column.JAVA_TYPE);
    return true;
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 12 with FlowVariable

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

the class FlowVariableRepository method getValueOfType.

/**
 * Get value of a flow variable. The type of the returned object is equal
 * to the given className.
 * @param name the name of the flow variable
 * @param className the type of the returned object
 * @return the value of the flow variable
 */
@SuppressWarnings("rawtypes")
public Object getValueOfType(final String name, final Class className) {
    FlowVariable flowVar = getFlowVariable(name);
    if (null == flowVar) {
        throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
    }
    TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
    return converter.getValue(flowVar, className);
}
Also used : TypeConverter(org.knime.base.node.jsnippet.type.flowvar.TypeConverter) FlowVariable(org.knime.core.node.workflow.FlowVariable) FlowVariableException(org.knime.base.node.jsnippet.expression.FlowVariableException)

Example 13 with FlowVariable

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

the class FlowVariableRepository method isOfType.

/**
 * Returns true when getValueOfType(String, Class) does not throw
 * an TypeException when called with the given flow variable and the given
 * class name.
 * @param name the name of the flow variable
 * @param className the type
 * @return true when flow variable is of type.
 */
@SuppressWarnings("rawtypes")
public boolean isOfType(final String name, final Class className) {
    FlowVariable flowVar = getFlowVariable(name);
    if (null == flowVar) {
        throw new FlowVariableException("The flow variable with name \"" + name + "\" does not exist.");
    }
    TypeConverter converter = TypeProvider.getDefault().getTypeConverter(flowVar.getType());
    return converter.canProvideJavaType(className);
}
Also used : TypeConverter(org.knime.base.node.jsnippet.type.flowvar.TypeConverter) FlowVariable(org.knime.core.node.workflow.FlowVariable) FlowVariableException(org.knime.base.node.jsnippet.expression.FlowVariableException)

Example 14 with FlowVariable

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

the class StringManipulationNodeDialog method createStringManipulationPanel.

/**
 * @return the controls for the string manipulation node
 * @since 3.3
 */
public Component createStringManipulationPanel() {
    m_snippetPanel = new JSnippetPanel(StringManipulatorProvider.getDefault(), createCompletionProvider(), !m_isOnlyVariables);
    m_newNameField = new JTextField(10);
    String radioButtonName;
    String radioButtonToolTip;
    radioButtonName = "Append " + WordUtils.capitalize(m_columnOrVariable) + ": ";
    radioButtonToolTip = "Appends a new " + m_columnOrVariable + " to the input with a given name.";
    m_appendRadio = new JRadioButton(radioButtonName);
    m_appendRadio.setToolTipText(radioButtonToolTip);
    radioButtonName = "Replace " + WordUtils.capitalize(m_columnOrVariable) + ": ";
    if (m_isOnlyVariables) {
        radioButtonToolTip = "Replaces the " + m_columnOrVariable + " if the type stays the same.";
    } else {
        radioButtonToolTip = "Replaces the " + m_columnOrVariable + " and changes the " + m_columnOrVariable + " type accordingly.";
    }
    m_replaceRadio = new JRadioButton(radioButtonName);
    m_replaceRadio.setToolTipText(radioButtonToolTip);
    if (m_isOnlyVariables) {
        // show all variables
        m_replaceVariableCombo = new JComboBox<FlowVariable>(new DefaultComboBoxModel<FlowVariable>());
        m_replaceVariableCombo.setRenderer(new FlowVariableListCellRenderer());
    } else {
        // show all columns
        m_replaceColumnCombo = new ColumnSelectionPanel((Border) null, DataValue.class);
        m_replaceColumnCombo.setRequired(false);
    }
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(m_appendRadio);
    buttonGroup.add(m_replaceRadio);
    ActionListener actionListener = new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            if (m_isOnlyVariables) {
                m_replaceVariableCombo.setEnabled(m_replaceRadio.isSelected());
            } else {
                m_replaceColumnCombo.setEnabled(m_replaceRadio.isSelected());
            }
            m_newNameField.setEnabled(m_appendRadio.isSelected());
        }
    };
    m_appendRadio.addActionListener(actionListener);
    m_replaceRadio.addActionListener(actionListener);
    m_compileOnCloseChecker = new JCheckBox("Syntax check on close");
    m_compileOnCloseChecker.setToolTipText("Checks the syntax of the expression on close.");
    m_insertMissingAsNullChecker = new JCheckBox("Insert Missing As Null");
    m_insertMissingAsNullChecker.setToolTipText("If unselected, missing values in the input will produce a missing cell result");
    return createPanel();
}
Also used : JRadioButton(javax.swing.JRadioButton) DataValue(org.knime.core.data.DataValue) ActionEvent(java.awt.event.ActionEvent) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ColumnSelectionPanel(org.knime.core.node.util.ColumnSelectionPanel) JSnippetPanel(org.knime.base.node.util.JSnippetPanel) Border(javax.swing.border.Border) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 15 with FlowVariable

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

the class StringManipulationNodeDialog method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    DataTableSpec spec;
    if (m_isOnlyVariables) {
        spec = new DataTableSpec();
    } else {
        spec = (DataTableSpec) specs[0];
    }
    StringManipulationSettings s = new StringManipulationSettings();
    s.loadSettingsInDialog(settings, spec);
    String exp = s.getExpression();
    String defaultNewName = "new " + m_columnOrVariable;
    String newName = s.getColName();
    boolean isReplace = s.isReplace();
    boolean isTestCompilation = s.isTestCompilationOnDialogClose();
    boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
    m_newNameField.setText("");
    final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
    if (m_isOnlyVariables) {
        DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
        cmbModel.removeAllElements();
        for (FlowVariable v : availableFlowVariables.values()) {
            switch(v.getScope()) {
                case Flow:
                    cmbModel.addElement(v);
                    break;
                default:
            }
        }
        if (availableFlowVariables.containsValue(newName)) {
            m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
        }
    } else {
        // 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);
        }
    }
    m_currentSpec = spec;
    // whether there are variables or columns available
    // -- which of two depends on the customizer
    boolean fieldsAvailable;
    if (m_isOnlyVariables) {
        fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
    } else {
        fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
    }
    m_replaceRadio.setEnabled(fieldsAvailable);
    if (isReplace && fieldsAvailable) {
        m_replaceRadio.doClick();
    } else {
        m_appendRadio.doClick();
        String newNameString = (newName != null ? newName : defaultNewName);
        m_newNameField.setText(newNameString);
    }
    m_snippetPanel.update(exp, spec, availableFlowVariables);
    m_compileOnCloseChecker.setSelected(isTestCompilation);
    m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) 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