Search in sources :

Example 1 with Scope

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

the class WorkflowVariablesEditDialog method createDialogArea.

/**
 * {@inheritDoc}
 */
@Override
protected Control createDialogArea(final Composite parent) {
    parent.getShell().setText("Add/Edit Workflow Variable");
    Composite twoColComp = new Composite(parent, SWT.NONE);
    twoColComp.setLayout(new GridLayout(3, true));
    GridData horizontalFill = new GridData(SWT.FILL, SWT.CENTER, true, false);
    horizontalFill.horizontalSpan = 2;
    // first row: node settings name
    Label varNameLabel = new Label(twoColComp, SWT.NONE);
    varNameLabel.setText("Variable name: ");
    m_varNameCtrl = new Text(twoColComp, SWT.BORDER);
    m_varNameCtrl.setLayoutData(horizontalFill);
    // add validation (at least some basic "text length > 0)
    m_varNameCtrl.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent arg0) {
            String text = m_varNameCtrl.getText();
            for (Scope s : FlowVariable.Scope.values()) {
                if (!Scope.Flow.equals(s) && text.startsWith(s.getPrefix())) {
                    showError("Flow variables must not start with \"" + s.getPrefix() + "\"!");
                    m_varNameCtrl.setText("");
                }
            }
        }
    });
    // second row: parameter type
    Label typeLabel = new Label(twoColComp, SWT.NONE);
    typeLabel.setText("Variable Type:");
    m_typeSelectionCtrl = new Combo(twoColComp, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (FlowVariable.Type t : Arrays.asList(Type.DOUBLE, Type.INTEGER, Type.STRING)) {
        m_typeSelectionCtrl.add(t.name());
    }
    m_typeSelectionCtrl.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent arg0) {
            m_type = FlowVariable.Type.valueOf(m_typeSelectionCtrl.getItem(m_typeSelectionCtrl.getSelectionIndex()));
        }
    });
    m_typeSelectionCtrl.setLayoutData(horizontalFill);
    m_typeSelectionCtrl.select(0);
    // third row: data set parameter name
    Label defaultValueLabel = new Label(twoColComp, SWT.NONE);
    defaultValueLabel.setText("Default value: ");
    m_varDefaultValueCtrl = new Text(twoColComp, SWT.BORDER);
    m_varDefaultValueCtrl.setLayoutData(horizontalFill);
    return twoColComp;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Type(org.knime.core.node.workflow.FlowVariable.Type) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Scope(org.knime.core.node.workflow.FlowVariable.Scope) 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)

Aggregations

ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 FlowVariable (org.knime.core.node.workflow.FlowVariable)1 Scope (org.knime.core.node.workflow.FlowVariable.Scope)1 Type (org.knime.core.node.workflow.FlowVariable.Type)1