Search in sources :

Example 71 with FlowVariable

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

the class WorkflowVariablesDialog method addWorkflowVariable.

private void addWorkflowVariable() {
    WorkflowVariablesEditDialog dialog = new WorkflowVariablesEditDialog();
    if (dialog.open() == Window.CANCEL) {
        // if the user has canceled the dialog there is nothing left to do
        return;
    }
    FlowVariable var = dialog.getScopeVariable();
    if (var == null) {
        // variables was not created
        return;
    }
    // do not add it do WFM directly -> this is done when closing the dialog
    if (!m_table.add(var)) {
        MessageDialog.openWarning(getShell(), "Variable already exists", " A variable with the same name and type already exists. " + "Edit this one if you want to change the value.");
    } else {
        m_table.getViewer().refresh();
    }
    getShell().forceFocus();
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 72 with FlowVariable

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

the class WorkflowVariablesDialog method createDialogArea.

/**
 * Creates and returns the contents of this dialog with or without edit,
 * add and remove buttons.
 * @param parent the parent composite
 * @param hideButtons true to hide the button bar, false to show it
 * @return the control
 * @since 2.6
 */
public Control createDialogArea(final Composite parent, final boolean hideButtons) {
    m_buttonsHidden = hideButtons;
    parent.getShell().setText("Workflow Variable Administration");
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    // composite contains:
    // first row (new composite):
    Composite tableAndBtnsComp = new Composite(composite, SWT.NONE);
    tableAndBtnsComp.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableAndBtnsComp.setLayout(new GridLayout(2, false));
    // first column: table
    Composite tableComp = new Composite(tableAndBtnsComp, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = true;
    tableComp.setLayout(new FillLayout());
    tableComp.setLayoutData(gridData);
    m_table = new WorkflowVariableTable(tableComp);
    for (FlowVariable var : m_workflow.getWorkflowVariables()) {
        m_table.add(var);
    }
    m_table.getViewer().refresh();
    m_table.getViewer().addDoubleClickListener(new IDoubleClickListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            Table table = m_table.getViewer().getTable();
            int index = table.getSelectionIndex();
            // we only get a double-click event for existing items
            FlowVariable var = m_table.get(index);
            editWorkflowVariable(var, index);
        }
    });
    if (!hideButtons) {
        // second column: 3 buttons
        Composite btnsComp = new Composite(tableAndBtnsComp, SWT.NONE);
        btnsComp.setLayout(new GridLayout(1, false));
        gridData = new GridData();
        gridData.verticalAlignment = GridData.VERTICAL_ALIGN_CENTER;
        btnsComp.setLayoutData(gridData);
        m_addVarBtn = new Button(btnsComp, SWT.PUSH);
        m_addVarBtn.setText("Add");
        m_addVarBtn.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent arg0) {
                widgetSelected(arg0);
            }

            @Override
            public void widgetSelected(final SelectionEvent arg0) {
                addWorkflowVariable();
            }
        });
        gridData = new GridData();
        gridData.widthHint = 80;
        m_addVarBtn.setLayoutData(gridData);
        m_editVarBtn = new Button(btnsComp, SWT.PUSH);
        m_editVarBtn.setText("Edit");
        m_editVarBtn.setLayoutData(gridData);
        m_editVarBtn.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent arg0) {
                widgetSelected(arg0);
            }

            @Override
            public void widgetSelected(final SelectionEvent arg0) {
                int selectionIdx = m_table.getViewer().getTable().getSelectionIndex();
                if (selectionIdx < 0) {
                    MessageDialog.openWarning(getShell(), "Empty selection", "Please select the parameter you want to edit.");
                    return;
                }
                FlowVariable selectedVar = m_table.get(selectionIdx);
                editWorkflowVariable(selectedVar, selectionIdx);
            }
        });
        m_removeVarBtn = new Button(btnsComp, SWT.PUSH);
        m_removeVarBtn.setText("Remove");
        m_removeVarBtn.setLayoutData(gridData);
        m_removeVarBtn.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetDefaultSelected(final SelectionEvent arg0) {
                widgetSelected(arg0);
            }

            @Override
            public void widgetSelected(final SelectionEvent arg0) {
                int idx = m_table.getViewer().getTable().getSelectionIndex();
                if (idx < 0) {
                    MessageDialog.openWarning(getShell(), "Empty selection", "Please select the parameter you want to remove.");
                    return;
                }
                FlowVariable selectedParam = (FlowVariable) ((IStructuredSelection) m_table.getViewer().getSelection()).getFirstElement();
                removeWorkflowVariable(selectedParam);
            }
        });
    }
    // second row: the warning label (in case the edit buttons are disabled
    // due to executing workflow...)
    m_warningLabel = new Label(composite, SWT.NONE);
    m_warningLabel.setText("");
    m_warningLabel.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
    m_warningLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    return composite;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FlowVariable(org.knime.core.node.workflow.FlowVariable) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 73 with FlowVariable

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

the class WorkflowVariablesDialog method hasChanges.

private boolean hasChanges() {
    List<FlowVariable> wfmList = m_workflow.getWorkflowVariables();
    List<FlowVariable> dialogList = m_table.getVariables();
    // different number of elements -> must contain changes
    if (wfmList.size() != dialogList.size()) {
        return true;
    }
    boolean hasChanges = false;
    for (FlowVariable v : dialogList) {
        int idx = wfmList.indexOf(v);
        if (idx >= 0) {
            hasChanges |= hasValueChanged(v, wfmList.get(idx));
        } else {
            // we have some changes
            return true;
        }
    }
    return hasChanges;
}
Also used : FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 74 with FlowVariable

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

the class RuleEngineVariable2PortsNodeModel method parseRules.

/**
 * Parses all rules from {@code rulesTable}.
 *
 * @param rulesTable The input rules table.
 * @return a list of parsed rules
 * @throws ParseException if a rule cannot be parsed
 * @throws InvalidSettingsException Missing values in outcomes are not supported.
 */
protected List<Rule> parseRules(final BufferedDataTable rulesTable) throws ParseException, InvalidSettingsException {
    ArrayList<Rule> rules = new ArrayList<Rule>();
    final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
    final RuleFactory factory = RuleFactory.getInstance(RuleNodeSettings.VariableRule).cloned();
    factory.disableNaNComparisons();
    final DataTableSpec spec = new DataTableSpec();
    int line = 0;
    for (String s : rules(rulesTable, m_settings, RuleNodeSettings.VariableRule)) {
        ++line;
        try {
            final Rule rule = factory.parse(s, spec, availableFlowVariables);
            if (rule.getCondition().isEnabled()) {
                rules.add(rule);
            }
        } catch (ParseException e) {
            throw Util.addContext(e, s, line);
        }
    }
    return rules;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RuleFactory(org.knime.base.node.rules.engine.RuleFactory) ArrayList(java.util.ArrayList) Rule(org.knime.base.node.rules.engine.Rule) ParseException(java.text.ParseException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 75 with FlowVariable

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

the class JSnippetPanel method onSelectionInVariableList.

/**
 * Method that is being called by listener when an object in the variable list has been selected.
 *
 * @param selected The selected object.
 * @since 3.6
 */
protected void onSelectionInVariableList(final Object selected) {
    if (selected instanceof FlowVariable) {
        FlowVariable v = (FlowVariable) selected;
        String typeChar;
        switch(v.getType()) {
            case DOUBLE:
                typeChar = "D";
                break;
            case INTEGER:
                typeChar = "I";
                break;
            case STRING:
                typeChar = "S";
                break;
            default:
                return;
        }
        String enter = m_completionProvider.escapeFlowVariableName(typeChar + v.getName());
        m_expEdit.replaceSelection(enter);
        m_flowVarsList.clearSelection();
        m_expEdit.requestFocus();
    }
}
Also used : 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