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();
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations