use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class RuleEngineFilter2PortsNodeModel method parseRules.
/**
* Parses all rules in the from the table (assuming {@link #rules()} is safe to call, like
* {@link #createStreamableOperator(PartitionInfo, PortObjectSpec[])} or
* {@link #execute(BufferedDataTable[], ExecutionContext)} was called before).
*
* @param spec the spec of the table on which the rules are applied.
* @param nodeType The type of the node from this method is called.
* @return a list of parsed rules
* @throws ParseException if a rule cannot be parsed
* @since 2.12
*/
@Override
protected List<Rule> parseRules(final DataTableSpec spec, final RuleNodeSettings nodeType) throws ParseException {
ArrayList<Rule> rules = new ArrayList<Rule>();
final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
// SimpleRuleParser ruleParser = new SimpleRuleParser(spec, availableFlowVariables);
RuleFactory factory = RuleFactory.getInstance(nodeType).cloned();
factory.disableMissingComparisons();
factory.disableNaNComparisons();
int line = 0;
for (String s : rules()) {
++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 KnimeCompletionProvider method setFlowVariables.
/**
* Set flow variables that should be shown in the code completion box.
*
* @param variables flow variables
*/
public void setFlowVariables(final Iterable<FlowVariable> variables) {
if (m_flowVariableCompletions.size() > 0) {
for (Completion c : m_flowVariableCompletions) {
removeCompletion(c);
}
}
m_flowVariableCompletions.clear();
for (FlowVariable var : variables) {
String typeChar;
switch(var.getType()) {
case DOUBLE:
typeChar = "D";
break;
case INTEGER:
typeChar = "I";
break;
case STRING:
typeChar = "S";
break;
default:
return;
}
m_flowVariableCompletions.add(new BasicCompletion(this, "$${" + typeChar + var.getName() + /*.replace("\\", "\\\\").replace("}", "\\}")*/
"}$$", var.getType().toString(), "The flow variable " + var.getName() + "."));
}
addCompletions(m_flowVariableCompletions);
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class NodeOutputView method updateVariableTable.
/*
* Put info about workflow variables into table.
*/
private void updateVariableTable(final NodeContainer nc) {
assert Display.getCurrent().getThread() == Thread.currentThread();
// display swt table
((StackLayout) m_stackPanel.getLayout()).topControl = m_table;
m_stackPanel.layout();
// Initialize table
m_table.removeAll();
for (TableColumn tc : m_table.getColumns()) {
tc.dispose();
}
String[] titles = { "Variable", "Value" };
for (int i = 0; i < titles.length; i++) {
TableColumn column = new TableColumn(m_table, SWT.NONE);
column.setText(titles[i]);
}
// retrieve variables
Collection<FlowVariable> fvs;
if ((nc instanceof SingleNodeContainer) || nc.getNrOutPorts() > 0) {
// for normal nodes port 0 is available (hidden variable OutPort!)
FlowObjectStack fos = nc.getOutPort(0).getFlowObjectStack();
if (fos != null) {
fvs = fos.getAvailableFlowVariables(org.knime.core.node.workflow.FlowVariable.Type.values()).values();
} else {
fvs = null;
}
m_info.setText("Node Variables");
} else {
// no output port on metanode - display workflow variables
fvs = ((WorkflowManager) nc).getWorkflowVariables();
m_info.setText("Metanode Variables");
}
if (fvs != null) {
// update content
for (FlowVariable fv : fvs) {
TableItem item = new TableItem(m_table, SWT.NONE);
item.setText(0, fv.getName());
item.setText(1, fv.getValueAsString());
}
}
for (int i = 0; i < m_table.getColumnCount(); i++) {
m_table.getColumn(i).pack();
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class StringManipulationVariableNodeModel method calculate.
/**
* @throws CompilationFailedException
* @throws InstantiationException
* @throws Exception
*/
private void calculate() throws InvalidSettingsException, CompilationFailedException, InstantiationException {
if (m_settings == null || m_settings.getExpression() == null) {
throw new InvalidSettingsException("No expression has been set.");
}
JavaScriptingSettings settings = m_settings.createJavaScriptingSettings();
settings.setInputAndCompile(new DataTableSpec());
// calculate the result
ColumnCalculator cc = new ColumnCalculator(settings, this);
DataCell calculate = null;
try {
calculate = cc.calculate(new DefaultRow(new RowKey(""), new DataCell[] {}));
} catch (NoSuchElementException e) {
throw new InvalidSettingsException(e.getMessage());
}
String newVariableName;
Map<String, FlowVariable> inputFlowVariables = getAvailableInputFlowVariables();
if (m_settings.isReplace()) {
newVariableName = m_settings.getColName();
CheckUtils.checkSettingNotNull(inputFlowVariables.get(newVariableName), "Can't replace input variable '%s' -- it does not exist in the input", newVariableName);
} else {
newVariableName = new UniqueNameGenerator(inputFlowVariables.keySet()).newName(m_settings.getColName());
}
// convert and push result as flow variable
CheckUtils.checkSetting(!calculate.isMissing(), "Calculation returned missing value");
Class<? extends DataCell> cellType = calculate.getClass();
if (cellType.equals(IntCell.class)) {
pushFlowVariableInt(newVariableName, ((IntCell) calculate).getIntValue());
} else if (cellType.equals(DoubleCell.class)) {
pushFlowVariableDouble(newVariableName, ((DoubleCell) calculate).getDoubleValue());
} else if (cellType.equals(StringCell.class)) {
pushFlowVariableString(newVariableName, ((StringCell) calculate).getStringValue());
} else {
throw new RuntimeException("Invalid variable class: " + cellType);
}
}
use of org.knime.core.node.workflow.FlowVariable in project knime-core by knime.
the class FlowVariableList method setFlowVariables.
/**
* Set the flow variables to display.
* @param flowVars the flow variables.
*/
public void setFlowVariables(final Collection<FlowVariable> flowVars) {
Collection<FlowVariable> sortedFlowVars = new TreeSet<>(new Comparator<FlowVariable>() {
@Override
public int compare(final FlowVariable o1, final FlowVariable o2) {
return o1.getName().compareTo(o2.getName());
}
});
sortedFlowVars.addAll(flowVars);
DefaultListModel fvListModel = (DefaultListModel) getModel();
fvListModel.removeAllElements();
for (FlowVariable v : sortedFlowVars) {
fvListModel.addElement(v);
}
}
Aggregations