Search in sources :

Example 16 with FlowVariable

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

the class WorkflowVariablesDialog method editWorkflowVariable.

private void editWorkflowVariable(final FlowVariable selectedVar, final int selectionIdx) {
    if (selectedVar.isGlobalConstant()) {
        MessageDialog.openError(getParentShell(), "Global Constant", selectedVar.getName() + " is a global constant " + "and cannot be modified!");
        return;
    }
    WorkflowVariablesEditDialog dialog = new WorkflowVariablesEditDialog();
    dialog.create();
    dialog.loadFrom(selectedVar);
    if (dialog.open() == Window.CANCEL) {
        // if the user has canceled the dialog there is nothing left to do
        return;
    }
    // else replace it...
    FlowVariable var = dialog.getScopeVariable();
    if (var != null) {
        m_table.replace(selectionIdx, var);
        m_table.getViewer().refresh();
    }
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 17 with FlowVariable

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

the class WorkflowVariablesDialog method replaceWorkflowVariables.

private void replaceWorkflowVariables(final boolean skipReset) {
    List<FlowVariable> toBeRemoved = new ArrayList<FlowVariable>();
    toBeRemoved.addAll(m_workflow.getWorkflowVariables());
    toBeRemoved.removeAll(m_table.getVariables());
    for (FlowVariable v : toBeRemoved) {
        m_workflow.removeWorkflowVariable(v.getName());
    }
    // replace
    FlowVariable[] vars = new FlowVariable[m_table.getVariables().size()];
    m_workflow.addWorkflowVariables(skipReset, m_table.getVariables().toArray(vars));
}
Also used : ArrayList(java.util.ArrayList) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 18 with FlowVariable

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

the class WorkflowVariablesEditDialog method okPressed.

/**
 * {@inheritDoc}
 */
@Override
protected void okPressed() {
    String varName = m_varNameCtrl.getText().trim();
    if (varName.isEmpty()) {
        String msg = "Variable name must not be empty!";
        showError(msg);
        throw new OperationCanceledException(msg);
    }
    String value = m_varDefaultValueCtrl.getText().trim();
    if (value.isEmpty()) {
        String msg = "A default value must be entered!";
        showError(msg);
        throw new OperationCanceledException(msg);
    }
    int selectionIdx = m_typeSelectionCtrl.getSelectionIndex();
    if (selectionIdx < 0) {
        String msg = "No type selected for variable " + varName;
        showError(msg);
        throw new IllegalArgumentException(msg);
    }
    String typeString = m_typeSelectionCtrl.getItem(selectionIdx);
    m_type = FlowVariable.Type.valueOf(typeString);
    if (FlowVariable.Type.DOUBLE.equals(m_type)) {
        try {
            m_variable = new FlowVariable(varName, Double.parseDouble(value));
        } catch (NumberFormatException nfe) {
            m_variable = null;
            String msg = "Invalid default value " + value + " for variable " + varName + "!";
            showError(msg);
            throw new OperationCanceledException(msg);
        }
    } else if (FlowVariable.Type.STRING.equals(m_type)) {
        m_variable = new FlowVariable(varName, value);
    } else if (FlowVariable.Type.INTEGER.equals(m_type)) {
        try {
            m_variable = new FlowVariable(varName, Integer.parseInt(value));
        } catch (NumberFormatException nfe) {
            m_variable = null;
            String msg = "Invalid default value " + value + " for variable " + varName + "!";
            showError(msg);
            throw new OperationCanceledException(msg);
        }
    }
    super.okPressed();
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 19 with FlowVariable

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

the class AppendToTableNodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
    Map<String, FlowVariable> scopeVars = getAvailableFlowVariables();
    AppendVariableToTableSettings sets = new AppendVariableToTableSettings();
    sets.loadSettingsFrom(settings, scopeVars);
    DefaultListModel model = (DefaultListModel) m_list.getModel();
    model.removeAllElements();
    int[] selIndices = new int[sets.getVariablesOfInterest().size()];
    int current = 0;
    int pointer = 0;
    for (FlowVariable v : scopeVars.values()) {
        model.addElement(v);
        if (sets.getVariablesOfInterest().contains(new Pair<String, FlowVariable.Type>(v.getName(), v.getType()))) {
            selIndices[pointer++] = current;
        }
        current += 1;
    }
    selIndices = Arrays.copyOf(selIndices, pointer);
    m_list.setSelectedIndices(selIndices);
    m_all.setSelected(sets.getIncludeAll());
}
Also used : DefaultListModel(javax.swing.DefaultListModel) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 20 with FlowVariable

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

the class VariableFileReaderNodeSettings method createSettingsFrom.

/**
 * Creates a clone from this object replacing the dataURL location by the
 * value from stack.
 *
 * @param stack the map containing all currently available variables and
 *            their values
 * @return a copy of this settings object with the file location replaced by
 *         the value of the variable
 * @throws InvalidSettingsException if the variable is not on the stack
 * @throws MalformedURLException if the value of the variable is not a valid
 *             URL
 */
VariableFileReaderNodeSettings createSettingsFrom(final Map<String, FlowVariable> stack) throws MalformedURLException, InvalidSettingsException {
    VariableFileReaderNodeSettings result = new VariableFileReaderNodeSettings(this);
    FlowVariable var = stack.get(m_variableName);
    if (var == null) {
        throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not on the stack.");
    }
    if (!var.getType().equals(FlowVariable.Type.STRING)) {
        throw new InvalidSettingsException("Selected file location variable (" + m_variableName + ") is not of type string.");
    }
    if (var.getStringValue() == null || var.getStringValue().isEmpty()) {
        throw new InvalidSettingsException("File location variable (" + m_variableName + ") is not set. Execute predecessor.");
    }
    URL loc = FileReaderNodeDialog.textToURL(var.getStringValue());
    result.setDataFileLocationAndUpdateTableName(loc);
    return result;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URL(java.net.URL) 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