use of org.knime.core.node.workflow.FlowObjectStack 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.FlowObjectStack in project knime-core by knime.
the class Node method createNodeExecutionResult.
/**
* Creates an execution result containing all calculated values in a
* execution. The returned value is suitable to be used in
* {@link #loadDataAndInternals(
* NodeContentPersistor, ExecutionMonitor, LoadResult)}.
* If this node is not executed, it will assign null values to the fields
* in the returned execution result.
* @param exec For progress information.
* @return A new execution result containing the values being calculated.
* @throws CanceledExecutionException If canceled
*/
public NodeExecutionResult createNodeExecutionResult(final ExecutionMonitor exec) throws CanceledExecutionException {
NodeExecutionResult result = new NodeExecutionResult();
result.setWarningMessage(m_model.getWarningMessage());
if (hasContent()) {
File internTempDir;
try {
internTempDir = FileUtil.createTempDir("knime_node_internDir");
exec.setMessage("Saving internals");
saveInternals(internTempDir, exec.createSubProgress(0.0));
result.setNodeInternDir(new ReferencedFile(internTempDir));
} catch (IOException ioe) {
LOGGER.error("Unable to save internals", ioe);
}
}
if (m_internalHeldPortObjects != null) {
PortObject[] internalHeldPortObjects = Arrays.copyOf(m_internalHeldPortObjects, m_internalHeldPortObjects.length);
result.setInternalHeldPortObjects(internalHeldPortObjects);
}
PortObject[] pos = new PortObject[getNrOutPorts()];
PortObjectSpec[] poSpecs = new PortObjectSpec[getNrOutPorts()];
for (int i = 0; i < pos.length; i++) {
PortObject po = getOutputObject(i);
if (po != null) {
pos[i] = po;
poSpecs[i] = po.getSpec();
}
}
result.setPortObjects(pos);
result.setPortObjectSpecs(poSpecs);
// Add the outgoing flow variables to the execution result
FlowObjectStack outgoingStack = m_model.getOutgoingFlowObjectStack();
List<FlowVariable> nodeFlowVars = outgoingStack.getAvailableFlowVariables().values().stream().filter(f -> f.getScope().equals(FlowVariable.Scope.Flow)).collect(Collectors.toList());
// the bottom most element should remain at the bottom of the stack
Collections.reverse(nodeFlowVars);
result.setFlowVariables(nodeFlowVars);
return result;
}
use of org.knime.core.node.workflow.FlowObjectStack in project knime-core by knime.
the class Node method getDialogPaneWithSettings.
/**
* @param inSpecs The input specs, which will be forwarded to the dialog's
* {@link NodeDialogPane#loadSettingsFrom(NodeSettingsRO,
* PortObjectSpec[])}.
* @param settings The current settings of this node. The settings object
* will also contain the settings of the outer SNC.
* @param isWriteProtected Whether write protected, see
* {@link org.knime.core.node.workflow.WorkflowManager#isWriteProtected()}.
* @return The dialog pane which holds all the settings' components. In
* addition this method loads the settings from the model into the
* dialog pane.
* @throws NotConfigurableException if the dialog cannot be opened because
* of real invalid settings or if any preconditions are not
* fulfilled, e.g. no predecessor node, no nominal column in
* input table, etc.
* @throws IllegalStateException If node has no dialog.
* @see #hasDialog()
* @since 2.6
*/
public NodeDialogPane getDialogPaneWithSettings(final PortObjectSpec[] inSpecs, final PortObject[] inData, final NodeSettingsRO settings, final boolean isWriteProtected) throws NotConfigurableException {
NodeDialogPane dialogPane = getDialogPane();
PortObjectSpec[] corrInSpecs = new PortObjectSpec[inSpecs.length - 1];
PortObject[] corrInData = new PortObject[inData.length - 1];
for (int i = 1; i < inSpecs.length; i++) {
if (inSpecs[i] instanceof InactiveBranchPortObjectSpec) {
if (!isInactiveBranchConsumer()) {
throw new NotConfigurableException("Cannot configure nodes in inactive branches.");
}
}
PortType t = getInputType(i);
if (!t.acceptsPortObjectSpec(inSpecs[i]) && !(inSpecs[i] instanceof InactiveBranchPortObjectSpec)) {
// table(!) connection)
throw new NotConfigurableException("Invalid incoming port object spec \"" + inSpecs[i].getClass().getSimpleName() + "\", expected \"" + t.getPortObjectSpecClass().getSimpleName() + "\"");
} else if (inSpecs[i] == null && BufferedDataTable.TYPE.equals(t) && !t.isOptional()) {
corrInSpecs[i - 1] = new DataTableSpec();
} else {
corrInSpecs[i - 1] = inSpecs[i];
corrInData[i - 1] = inData[i];
}
}
// the sub node virtual input node shows in its dialog all flow variables that are available to the rest
// of the subnode. It's the only case where the flow variables shown in the dialog are not the ones available
// to the node model class ...
final FlowObjectStack flowObjectStack = m_model instanceof VirtualSubNodeInputNodeModel ? ((VirtualSubNodeInputNodeModel) m_model).getSubNodeContainerFlowObjectStack() : getFlowObjectStack();
dialogPane.internalLoadSettingsFrom(settings, corrInSpecs, corrInData, flowObjectStack, getCredentialsProvider(), isWriteProtected);
if (m_model instanceof ValueControlledNode && dialogPane instanceof ValueControlledDialogPane) {
NodeSettings currentValue = new NodeSettings("currentValue");
try {
((ValueControlledNode) m_model).saveCurrentValue(currentValue);
((ValueControlledDialogPane) dialogPane).loadCurrentValue(currentValue);
} catch (Exception ise) {
final String msg = "Could not load current value into dialog: " + ise.getMessage();
if (ise instanceof InvalidSettingsException) {
LOGGER.warn(msg, ise);
} else {
LOGGER.coding(msg, ise);
}
}
}
return dialogPane;
}
use of org.knime.core.node.workflow.FlowObjectStack in project knime-core by knime.
the class Node method cleanOutPorts.
/**
* Sets output objects to null.
* @param isLoopRestart If true, does not clear tables that are part
* of the internally held tables (loop start nodes implements the
* {@link BufferedDataTableHolder} interface). This can only be true
* between two loop iterations.
* @noreference This method is not intended to be referenced by clients.
*/
public void cleanOutPorts(final boolean isLoopRestart) {
if (isLoopRestart) {
// just as an assertion
FlowObjectStack inStack = getFlowObjectStack();
FlowLoopContext flc = inStack.peek(FlowLoopContext.class);
if (flc != null && flc.isInactiveScope()) {
LOGGER.coding("Encountered an inactive FlowLoopContext in a loop restart.");
// continue with historically "correct" solution:
flc = inStack.peekScopeContext(FlowLoopContext.class, false);
}
if (flc == null && !this.isModelCompatibleTo(LoopStartNode.class)) {
LOGGER.coding("Encountered a loop restart action but there is" + " no loop context on the flow object stack (node " + getName() + ")");
}
}
LOGGER.debug("clean output ports.");
Set<BufferedDataTable> disposableTables = new LinkedHashSet<BufferedDataTable>();
for (int i = 0; i < m_outputs.length; i++) {
PortObject portObject = m_outputs[i].object;
if (portObject instanceof BufferedDataTable) {
final BufferedDataTable table = (BufferedDataTable) portObject;
table.collectTableAndReferencesOwnedBy(this, disposableTables);
}
m_outputs[i].spec = null;
m_outputs[i].object = null;
m_outputs[i].summary = null;
}
if (m_internalHeldPortObjects != null) {
Set<BufferedDataTable> internalTableSet = collectTableAndReferences(m_internalHeldPortObjects);
// internal table reference that must not be cleared).
if (isLoopRestart) {
disposableTables.removeAll(internalTableSet);
} else {
disposableTables.addAll(internalTableSet);
m_internalHeldPortObjects = null;
}
}
for (BufferedDataTable disposable : disposableTables) {
disposable.clearSingle(this);
}
// clear temporary tables that have been created during execute
for (ContainerTable t : m_localTempTables) {
t.clear();
}
m_localTempTables.clear();
}
use of org.knime.core.node.workflow.FlowObjectStack in project knime-core by knime.
the class ConfigEditTreeRenderer method setValue.
/**
* Called whenever a new value is to be renderer, updates underlying
* component.
* @param tree The associated tree (get the flow object stack from.)
* @param value to be renderer, typically a <code>ConfigEditTreeNode</code>
*/
public void setValue(final JTree tree, final Object value) {
ConfigEditTreeNode node;
if (value instanceof ConfigEditTreeNode) {
node = (ConfigEditTreeNode) value;
m_active = node.isLeaf() ? m_panelFull : m_panelPlain;
} else {
node = null;
m_active = m_panelPlain;
}
FlowObjectStack stack = null;
if (tree instanceof ConfigEditJTree) {
stack = ((ConfigEditJTree) tree).getFlowObjectStack();
}
m_active.setFlowObjectStack(stack);
m_active.setTreeNode(node);
setLeafIcon(m_active.getIcon());
setOpenIcon(m_active.getIcon());
setClosedIcon(m_active.getIcon());
setToolTipText(m_active.getToolTipText());
}
Aggregations