Search in sources :

Example 1 with FlowObjectStack

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();
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point) FlowVariable(org.knime.core.node.workflow.FlowVariable) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Example 2 with FlowObjectStack

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;
}
Also used : WizardNode(org.knime.core.node.wizard.WizardNode) ScopeEndNode(org.knime.core.node.workflow.ScopeEndNode) NodeType(org.knime.core.node.NodeFactory.NodeType) Arrays(java.util.Arrays) BufferedInputStream(java.io.BufferedInputStream) NodeMessageEvent(org.knime.core.node.workflow.NodeMessageEvent) ReferencedFile(org.knime.core.internal.ReferencedFile) FileStoreUtil(org.knime.core.data.filestore.FileStoreUtil) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) InteractiveNode(org.knime.core.node.interactive.InteractiveNode) StringUtils(org.apache.commons.lang3.StringUtils) ExecutionEnvironment(org.knime.core.node.workflow.ExecutionEnvironment) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) FlowTryCatchContext(org.knime.core.node.workflow.FlowTryCatchContext) ContainerTable(org.knime.core.data.container.ContainerTable) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortType(org.knime.core.node.port.PortType) PrintWriter(java.io.PrintWriter) PortObjectZipOutputStream(org.knime.core.node.port.PortObjectZipOutputStream) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) InterruptibleNodeModel(org.knime.core.node.interrupt.InterruptibleNodeModel) List(java.util.List) HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) InteractiveNodeFactoryExtension(org.knime.core.node.interactive.InteractiveNodeFactoryExtension) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) PortObjectZipInputStream(org.knime.core.node.port.PortObjectZipInputStream) NodeMessage(org.knime.core.node.workflow.NodeMessage) Rectangle(java.awt.Rectangle) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) NodeMessageListener(org.knime.core.node.workflow.NodeMessageListener) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ValueControlledDialogPane(org.knime.core.node.dialog.ValueControlledDialogPane) DataTableSpec(org.knime.core.data.DataTableSpec) LoopEndNode(org.knime.core.node.workflow.LoopEndNode) NodeExecutionJobManagerPool(org.knime.core.node.util.NodeExecutionJobManagerPool) FlowVariable(org.knime.core.node.workflow.FlowVariable) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) SplitType(org.knime.core.node.workflow.NodeContainer.NodeContainerSettings.SplitType) AtomicReference(java.util.concurrent.atomic.AtomicReference) PortObjectSpecZipInputStream(org.knime.core.node.port.PortObjectSpecZipInputStream) HashSet(java.util.HashSet) PortTypeRegistry(org.knime.core.node.port.PortTypeRegistry) CredentialsProvider(org.knime.core.node.workflow.CredentialsProvider) PortUtil(org.knime.core.node.port.PortUtil) ViewUtils(org.knime.core.node.util.ViewUtils) LoadResult(org.knime.core.node.workflow.WorkflowPersistor.LoadResult) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) LinkedHashSet(java.util.LinkedHashSet) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) ScopeStartNode(org.knime.core.node.workflow.ScopeStartNode) StringWriter(java.io.StringWriter) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) InteractiveView(org.knime.core.node.interactive.InteractiveView) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowScopeContext(org.knime.core.node.workflow.FlowScopeContext) IOException(java.io.IOException) InactiveBranchConsumer(org.knime.core.node.port.inactive.InactiveBranchConsumer) FileInputStream(java.io.FileInputStream) PortObjectSpecZipOutputStream(org.knime.core.node.port.PortObjectSpecZipOutputStream) WizardNodeFactoryExtension(org.knime.core.node.wizard.WizardNodeFactoryExtension) NodeContext(org.knime.core.node.workflow.NodeContext) File(java.io.File) ViewContent(org.knime.core.node.interactive.ViewContent) Element(org.w3c.dom.Element) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) LoopStartNode(org.knime.core.node.workflow.LoopStartNode) NodeID(org.knime.core.node.workflow.NodeID) DataContainerException(org.knime.core.data.container.DataContainerException) FileUtil(org.knime.core.util.FileUtil) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) ValueControlledNode(org.knime.core.node.dialog.ValueControlledNode) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) FlowLoopContext(org.knime.core.node.workflow.FlowLoopContext) Collections(java.util.Collections) InputStream(java.io.InputStream) PortObjectHolder(org.knime.core.node.port.PortObjectHolder) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 3 with FlowObjectStack

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;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) IOException(java.io.IOException) DataContainerException(org.knime.core.data.container.DataContainerException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) InactiveBranchPortObjectSpec(org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec) ValueControlledDialogPane(org.knime.core.node.dialog.ValueControlledDialogPane) ValueControlledNode(org.knime.core.node.dialog.ValueControlledNode) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortType(org.knime.core.node.port.PortType)

Example 4 with FlowObjectStack

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();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack) FlowLoopContext(org.knime.core.node.workflow.FlowLoopContext) PortObject(org.knime.core.node.port.PortObject) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) ContainerTable(org.knime.core.data.container.ContainerTable)

Example 5 with FlowObjectStack

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());
}
Also used : ConfigEditTreeNode(org.knime.core.node.config.ConfigEditTreeModel.ConfigEditTreeNode) FlowObjectStack(org.knime.core.node.workflow.FlowObjectStack)

Aggregations

FlowObjectStack (org.knime.core.node.workflow.FlowObjectStack)7 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)4 PortObject (org.knime.core.node.port.PortObject)4 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)4 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)4 FlowVariable (org.knime.core.node.workflow.FlowVariable)4 DataContainerException (org.knime.core.data.container.DataContainerException)3 FlowLoopContext (org.knime.core.node.workflow.FlowLoopContext)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 LinkedHashSet (java.util.LinkedHashSet)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 ContainerTable (org.knime.core.data.container.ContainerTable)2 ValueControlledDialogPane (org.knime.core.node.dialog.ValueControlledDialogPane)2 ValueControlledNode (org.knime.core.node.dialog.ValueControlledNode)2 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)2 PortType (org.knime.core.node.port.PortType)2 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)2 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)2