Search in sources :

Example 51 with WorkflowManager

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

the class SandboxedNodeCreator method copyExistingTablesIntoSandboxContainer.

/**
 * Copies the tables (port and internal) into the context of the corresponding node in the targetWFM. The execution
 * result must fit to the passed node container.
 *
 * @param execResult the object holding the result of the sourceNC. If the sourceNC is a workflow, this must hold
 *            all results of all contained nodes.
 * @param sourceNC the node that produced the execution result.
 * @param targetNC the context into which the tables are copied into
 * @param progressMon For progress information
 * @param copyDataIntoNewContext as per {@link #setCopyData(boolean)}
 * @throws CanceledExecutionException
 * @throws IOException
 */
public static void copyExistingTablesIntoSandboxContainer(final NodeContainerExecutionResult execResult, final NodeContainer sourceNC, final NodeContainer targetNC, final ExecutionMonitor progressMon, final boolean copyDataIntoNewContext) throws CanceledExecutionException, IOException {
    assert targetNC.getNrOutPorts() == sourceNC.getNrOutPorts();
    if (execResult instanceof NativeNodeContainerExecutionResult) {
        NativeNodeContainerExecutionResult sncResult = (NativeNodeContainerExecutionResult) execResult;
        // execResult and node types must match
        assert sourceNC instanceof NativeNodeContainer;
        assert targetNC instanceof NativeNodeContainer;
        // data is to copy ... get the correct execution context
        ExecutionContext targetExec = copyDataIntoNewContext ? ((SingleNodeContainer) targetNC).createExecutionContext() : null;
        NodeExecutionResult ner = sncResult.getNodeExecutionResult();
        // TODO this copy process has to take place in a different place
        // though it needs the final execution context for correct copy
        // of BDT objects
        PortObject[] resultTables = new PortObject[targetNC.getNrOutPorts()];
        int copyCount = resultTables.length;
        // copy also the internally held tables (such as for instance
        // the table in the table view) -- use the copy of the outports
        // if they match (likely they don't)
        PortObject[] oldInternTables = ner.getInternalHeldPortObjects();
        PortObject[] newInternTables = null;
        if (oldInternTables != null) {
            newInternTables = new PortObject[oldInternTables.length];
            copyCount += newInternTables.length;
        }
        // skip flow variable output
        for (int i = 0; i < resultTables.length; i++) {
            ExecutionMonitor sub = progressMon.createSubProgress(1.0 / copyCount);
            progressMon.setMessage("Port " + i);
            PortObject o = ner.getPortObject(i);
            PortObject newPO = copyPortObject(o, sub, targetExec);
            if (newInternTables != null) {
                for (int j = 0; j < oldInternTables.length; j++) {
                    if (oldInternTables[j] == o) {
                        newInternTables[j] = newPO;
                    }
                }
            }
            sub.setProgress(1.0);
            resultTables[i] = newPO;
        }
        if (newInternTables != null) {
            for (int i = 0; i < newInternTables.length; i++) {
                ExecutionMonitor sub = progressMon.createSubProgress(1.0 / copyCount);
                progressMon.setMessage("Internal Table " + i);
                if (newInternTables[i] == null) {
                    PortObject oldT = oldInternTables[i];
                    PortObject newT = copyPortObject(oldT, sub, targetExec);
                    newInternTables[i] = newT;
                }
                sub.setProgress(1.0);
            }
        }
        if (oldInternTables != null) {
            ner.setInternalHeldPortObjects(newInternTables);
        }
        ner.setPortObjects(resultTables);
    } else if (execResult instanceof WorkflowExecutionResult) {
        WorkflowExecutionResult wfmResult = (WorkflowExecutionResult) execResult;
        // exec result and node types must match
        WorkflowManager targetWFM = (WorkflowManager) targetNC;
        WorkflowManager sourceWFM = (WorkflowManager) sourceNC;
        copyIntoSandboxContainerRecursive(sourceWFM, targetWFM, wfmResult, progressMon, copyDataIntoNewContext);
    } else if (execResult instanceof SubnodeContainerExecutionResult) {
        SubnodeContainerExecutionResult subResult = (SubnodeContainerExecutionResult) execResult;
        WorkflowExecutionResult wfmResult = subResult.getWorkflowExecutionResult();
        WorkflowManager targetWFM = ((SubNodeContainer) targetNC).getWorkflowManager();
        WorkflowManager sourceWFM = ((SubNodeContainer) sourceNC).getWorkflowManager();
        copyIntoSandboxContainerRecursive(sourceWFM, targetWFM, wfmResult, progressMon, copyDataIntoNewContext);
    } else {
        throw new IllegalStateException("Unsupported node result type: " + execResult.getClass().getSimpleName());
    }
}
Also used : NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 52 with WorkflowManager

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

the class SandboxedNodeCreator method getFlowVariablesOnPort.

/**
 * Checks which flow variables are available on a port by looking on the output port connected to this input port.
 *
 * @param portIdx input port of the {@link NodeContainer} {@link #m_nc}
 * @return the flow variables available at this port
 */
private List<FlowVariable> getFlowVariablesOnPort(final int portIdx) {
    WorkflowManager wfm = m_nc.getParent();
    Optional<Stream<FlowVariable>> nodeInputFlowVariables = wfm.getNodeInputFlowVariables(m_nc.getID(), portIdx);
    if (nodeInputFlowVariables.isPresent()) {
        List<FlowVariable> result = nodeInputFlowVariables.get().filter(fv -> !fv.isGlobalConstant()).collect(Collectors.toList());
        // getNodeInputFlowVariables returns top down, make sure iterations on list return oldest entry first
        // (will be pushed onto node stack using an iterator)
        Collections.reverse(result);
        return result;
    }
    return Collections.emptyList();
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ReferencedFile(org.knime.core.internal.ReferencedFile) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NativeNodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NativeNodeContainerExecutionResult) NodeContainer(org.knime.core.node.workflow.NodeContainer) Map(java.util.Map) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) PortObjectInNodeFactory(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeFactory) PortType(org.knime.core.node.port.PortType) LockFailedException(org.knime.core.util.LockFailedException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) Collection(java.util.Collection) ConnectionID(org.knime.core.node.workflow.ConnectionID) WorkflowCreationHelper(org.knime.core.node.workflow.WorkflowCreationHelper) Collectors(java.util.stream.Collectors) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) Optional(java.util.Optional) CredentialsStore(org.knime.core.node.workflow.CredentialsStore) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) NodeContainerExecutionResult(org.knime.core.node.workflow.execresult.NodeContainerExecutionResult) IntStream(java.util.stream.IntStream) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeExecutionJobManagerPool(org.knime.core.node.util.NodeExecutionJobManagerPool) FlowVariable(org.knime.core.node.workflow.FlowVariable) NodeSettings(org.knime.core.node.NodeSettings) BDTInNodeFactory(org.knime.core.node.exec.dataexchange.in.BDTInNodeFactory) ArrayList(java.util.ArrayList) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExecutionContext(org.knime.core.node.ExecutionContext) NodeExecutionJobManager(org.knime.core.node.workflow.NodeExecutionJobManager) NodeLogger(org.knime.core.node.NodeLogger) WorkflowExecutionResult(org.knime.core.node.workflow.execresult.WorkflowExecutionResult) NodeFactory(org.knime.core.node.NodeFactory) NodeInPort(org.knime.core.node.workflow.NodeInPort) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowCopyContent(org.knime.core.node.workflow.WorkflowCopyContent) File(java.io.File) PortObjectRepository(org.knime.core.node.exec.dataexchange.PortObjectRepository) NodeExecutionResult(org.knime.core.node.workflow.execresult.NodeExecutionResult) NodeID(org.knime.core.node.workflow.NodeID) FileUtil(org.knime.core.util.FileUtil) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) SubnodeContainerExecutionResult(org.knime.core.node.workflow.execresult.SubnodeContainerExecutionResult) Collections(java.util.Collections) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Stream(java.util.stream.Stream) IntStream(java.util.stream.IntStream) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 53 with WorkflowManager

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

the class SandboxedNodeCreator method deepCopyFilesInWorkflowDir.

/**
 * Deep copies data and drop folders contained in the source directory to the target directory.
 * @param source Source node
 * @param targetParent Target node's parent
 */
private static void deepCopyFilesInWorkflowDir(final NodeContainer source, final WorkflowManager targetParent) {
    NodeContainer target = targetParent.getNodeContainer(targetParent.getID().createChild(source.getID().getIndex()));
    ReferencedFile sourceDirRef = source.getNodeContainerDirectory();
    ReferencedFile targetDirRef = target.getNodeContainerDirectory();
    if (sourceDirRef == null) {
        // The source node has never been saved, there are no files to copy
        return;
    }
    File sourceDir = sourceDirRef.getFile();
    File targetDir = targetDirRef.getFile();
    for (String magicFolderName : MAGIC_DATA_FOLDERS) {
        File dataSourceDir = new File(sourceDir, magicFolderName);
        if (dataSourceDir.isDirectory()) {
            File dataTargetDir = new File(targetDir, magicFolderName);
            try {
                FileUtils.copyDirectory(dataSourceDir, dataTargetDir);
                LOGGER.debugWithFormat("Copied directory \"%s\" to \"%s\"", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath());
            } catch (IOException ex) {
                LOGGER.error(String.format("Could not copy directory \"%s\" to \"%s\": %s", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath(), ex.getMessage()), ex);
            }
        }
    }
    Collection<NodeContainer> childrenList = Collections.emptyList();
    WorkflowManager childTargetParent = null;
    if (source instanceof WorkflowManager) {
        childrenList = ((WorkflowManager) source).getNodeContainers();
        childTargetParent = (WorkflowManager) target;
    } else if (source instanceof SubNodeContainer) {
        childrenList = ((SubNodeContainer) source).getWorkflowManager().getNodeContainers();
        childTargetParent = ((SubNodeContainer) target).getWorkflowManager();
    }
    for (NodeContainer child : childrenList) {
        deepCopyFilesInWorkflowDir(child, childTargetParent);
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 54 with WorkflowManager

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

the class NodeLogger method getLogObject.

/**
 * @param message the logging message
 * @return a KNIMELogMessage that not only contains the log message but also the information about the workflow
 * and node that belong to the log message if applicable
 */
private Object getLogObject(final Object message) {
    if (!LOG_NODE_ID && !LOG_IN_WF_DIR && !LOG_WF_DIR) {
        return message;
    }
    final NodeContext context = NodeContext.getContext();
    NodeID nodeID = null;
    String nodeName = null;
    File workflowDir = null;
    if (context != null) {
        if (LOG_NODE_ID) {
            // retrieve and store the node id only if the user has requested to log it
            final NodeContainer nodeContainer = context.getNodeContainer();
            if (nodeContainer != null) {
                nodeID = nodeContainer.getID();
                nodeName = nodeContainer.getName();
            }
        }
        if (LOG_IN_WF_DIR || LOG_WF_DIR) {
            final WorkflowManager workflowManager = context.getWorkflowManager();
            if (workflowManager != null) {
                final WorkflowContext workflowContext = workflowManager.getContext();
                if (workflowContext != null) {
                    workflowDir = workflowContext.getCurrentLocation();
                }
            }
        }
    }
    return new KNIMELogMessage(nodeID, nodeName, workflowDir, message);
}
Also used : NodeContext(org.knime.core.node.workflow.NodeContext) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) NodeID(org.knime.core.node.workflow.NodeID) NodeContainer(org.knime.core.node.workflow.NodeContainer) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 55 with WorkflowManager

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

the class WorkflowContextMenuProvider method buildContextMenu.

/**
 * {@inheritDoc}
 */
@Override
public void buildContextMenu(final IMenuManager manager) {
    final String FLOW_VAR_PORT_GRP = "Flow Variable Ports";
    // add the groups (grouped by separators) in their order first
    manager.add(new Separator(IWorkbenchActionConstants.GROUP_APP));
    manager.add(new Separator(FLOW_VAR_PORT_GRP));
    GEFActionConstants.addStandardActionGroups(manager);
    IAction action;
    action = m_actionRegistry.getAction("cut");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("copy");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction(PasteActionContextMenu.ID);
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("undo");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("redo");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("delete");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    // Add (some) available actions from the registry to the context menu
    // manager
    // openDialog
    action = m_actionRegistry.getAction(OpenDialogAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // execute
    action = m_actionRegistry.getAction(ExecuteAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // execute and open first view
    action = m_actionRegistry.getAction(ExecuteAndOpenViewAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // cancel execution
    action = m_actionRegistry.getAction(CancelAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // show some menu items on LoopEndNodes only
    List parts = m_viewer.getSelectedEditParts();
    if (parts.size() == 1) {
        EditPart p = (EditPart) parts.get(0);
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI container = (NodeContainerUI) ((NodeContainerEditPart) p).getModel();
            if (container instanceof SingleNodeContainerUI) {
                SingleNodeContainerUI snc = (SingleNodeContainerUI) container;
                Wrapper.unwrapOptional(snc, SingleNodeContainer.class).ifPresent(sncImpl -> {
                    if (sncImpl.isModelCompatibleTo(LoopEndNode.class)) {
                        // pause loop execution
                        IAction loopAction;
                        loopAction = m_actionRegistry.getAction(PauseLoopExecutionAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                        // step loop execution
                        loopAction = m_actionRegistry.getAction(StepLoopAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                        // resume loop execution
                        loopAction = m_actionRegistry.getAction(ResumeLoopAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                    }
                });
            }
        }
    }
    // reset
    action = m_actionRegistry.getAction(ResetAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // set name and description
    action = m_actionRegistry.getAction(SetNodeDescriptionAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // add workflow annotation
    action = m_actionRegistry.getAction(AddAnnotationAction.ID);
    AddAnnotationAction aaa = (AddAnnotationAction) action;
    aaa.setLocation(m_lastLocation.x, m_lastLocation.y);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // collapse metanodes
    action = m_actionRegistry.getAction(CollapseMetaNodeAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    action = m_actionRegistry.getAction(EncapsulateSubNodeAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // insert "select loop" if loop nodes are selected
    boolean addSelectLoop = true;
    for (Object p : parts) {
        if (!(p instanceof NodeContainerEditPart)) {
            addSelectLoop = false;
            break;
        }
        NodeContainerUI nc = ((NodeContainerEditPart) p).getNodeContainer();
        if (!(nc instanceof SingleNodeContainerUI)) {
            addSelectLoop = false;
            break;
        }
        if (!((SingleNodeContainerUI) nc).isMemberOfScope()) {
            addSelectLoop = false;
            break;
        }
    }
    if (addSelectLoop) {
        action = m_actionRegistry.getAction(SelectLoopAction.ID);
        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
        ((AbstractNodeAction) action).update();
    }
    IMenuManager metanodeMenuMgr = null;
    IMenuManager subnodeMenuMgr = null;
    IMenuManager subnodeViewMgr = null;
    // depending on the current selection: add the actions for the port
    // views and the node views
    // also check whether this node part is a meta-node
    // if so offer the "edit meta-node" option
    // all these feature are only offered if exactly 1 part is selected
    parts = m_viewer.getSelectedEditParts();
    // by now, we only support one part...
    if (parts.size() == 1) {
        EditPart p = (EditPart) parts.get(0);
        if (p instanceof WorkflowInPortBarEditPart) {
            WorkflowInPortBarEditPart root = (WorkflowInPortBarEditPart) p;
            manager.add(new Separator("outPortViews"));
            for (Object o : p.getChildren()) {
                EditPart child = (EditPart) o;
                if (child instanceof WorkflowInPortEditPart && ((WorkflowInPortEditPart) child).isSelected()) {
                    final WorkflowManager wm = Wrapper.unwrapWFM(((WorkflowPortBar) root.getModel()).getWorkflowManager());
                    action = new OpenWorkflowPortViewAction(wm, ((WorkflowInPortEditPart) child).getIndex(), wm.getNrInPorts());
                    manager.appendToGroup("outPortViews", action);
                    ((WorkflowInPortEditPart) child).setSelected(false);
                }
            }
        }
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI container = null;
            container = (NodeContainerUI) ((NodeContainerEditPart) p).getModel();
            if (!(container instanceof WorkflowManagerUI)) {
                action = m_actionRegistry.getAction(ToggleFlowVarPortsAction.ID);
                manager.appendToGroup(FLOW_VAR_PORT_GRP, action);
                ((AbstractNodeAction) action).update();
            }
            // add for node views option if applicable
            int numNodeViews = container.getNrViews();
            for (int i = 0; i < numNodeViews; i++) {
                action = new OpenViewAction(unwrapNC(container), i);
                manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
            }
            // add interactive view options
            if (container.hasInteractiveView()) {
                action = new OpenInteractiveViewAction(unwrapNC(container));
                manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
            } else {
                // TODO for subnodes move to submenu?
                if (wraps(container, NativeNodeContainer.class)) {
                    InteractiveWebViewsResult interactiveWebViewsResult = unwrapNC(container).getInteractiveWebViews();
                    for (int i = 0; i < interactiveWebViewsResult.size(); i++) {
                        action = new OpenInteractiveWebViewAction(unwrapNC(container), interactiveWebViewsResult.get(i));
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
                    }
                }
            }
            if (container instanceof WorkflowManagerUI) {
                metanodeMenuMgr = getMetaNodeMenuManager(metanodeMenuMgr, manager);
                // OPEN META NODE
                action = new OpenSubworkflowEditorAction((NodeContainerEditPart) p);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                // EXPAND META NODE
                action = m_actionRegistry.getAction(ExpandMetaNodeAction.ID);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                ((AbstractNodeAction) action).update();
                // RECONFIGURE META NODE
                if (parts.size() == 1) {
                    action = m_actionRegistry.getAction(MetaNodeReconfigureAction.ID);
                    metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                    ((AbstractNodeAction) action).update();
                }
                // WRAP
                action = m_actionRegistry.getAction(ConvertMetaNodeToSubNodeAction.ID);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                ((AbstractNodeAction) action).update();
            }
            // SUBNODE
            if (container instanceof SubNodeContainerUI) {
                subnodeMenuMgr = getSubNodeMenuManager(subnodeMenuMgr, manager);
                // OPEN SUBNODE
                action = new OpenSubNodeEditorAction((NodeContainerEditPart) p);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                // EXPAND SUBNODE
                action = m_actionRegistry.getAction(ExpandSubNodeAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                // RECONFIGURE SUBNODE
                action = m_actionRegistry.getAction(SubNodeReconfigureAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                // UNWRAP
                action = m_actionRegistry.getAction(ConvertSubNodeToMetaNodeAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                if (wraps(container, SubNodeContainer.class)) {
                    InteractiveWebViewsResult interactiveWebViewsResult = unwrapNC(container).getInteractiveWebViews();
                    if (interactiveWebViewsResult.size() > 0) {
                        subnodeViewMgr = getSingleSubNodeViewsMenuManager(subnodeViewMgr, subnodeMenuMgr);
                        for (int i = 0; i < interactiveWebViewsResult.size(); i++) {
                            action = new OpenInteractiveWebViewAction(unwrapNC(container), interactiveWebViewsResult.get(i));
                            subnodeViewMgr.appendToGroup(GROUP_SUBNODE_VIEWS, action);
                        }
                    }
                    action = new OpenSubnodeWebViewAction(Wrapper.unwrap(container, SubNodeContainer.class));
                    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
                }
            }
            // add port views
            manager.add(new Separator("outPortViews"));
            int numOutPorts = container.getNrOutPorts();
            for (int i = 0; i < numOutPorts; i++) {
                if (i == 0 && !(container instanceof WorkflowManagerUI)) {
                    // skip the implicit flow var ports on "normal" nodes
                    continue;
                }
                if (wraps(container, NodeContainer.class)) {
                    action = new OpenPortViewAction(unwrapNC(container), i, numOutPorts);
                    manager.appendToGroup("outPortViews", action);
                }
            }
        }
    }
    boolean addMetaNodeActions = false;
    boolean addSubNodeActions = false;
    for (Object p : parts) {
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI model = ((NodeContainerEditPart) p).getNodeContainer();
            if (model instanceof WorkflowManagerUI) {
                addMetaNodeActions = true;
            } else if (model instanceof SubNodeContainerUI) {
                addSubNodeActions = true;
            }
        }
    }
    if (addMetaNodeActions) {
        metanodeMenuMgr = getMetaNodeMenuManager(metanodeMenuMgr, manager);
        // SAVE AS TEMPLATE
        action = m_actionRegistry.getAction(SaveAsMetaNodeTemplateAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHECK UPDATE
        action = m_actionRegistry.getAction(CheckUpdateMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // DISCONNECT
        action = m_actionRegistry.getAction(DisconnectMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LINK TYPE
        action = m_actionRegistry.getAction(ChangeMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // REVEAL TEMPLATE
        action = m_actionRegistry.getAction(RevealMetaNodeTemplateAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LOCK
        if (Boolean.getBoolean(KNIMEConstants.PROPERTY_SHOW_METANODE_LOCK_ACTION)) {
            action = m_actionRegistry.getAction(LockMetaNodeAction.ID);
            metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
            ((AbstractNodeAction) action).update();
        }
    }
    if (addSubNodeActions) {
        subnodeMenuMgr = getSubNodeMenuManager(subnodeMenuMgr, manager);
        // SAVE AS TEMPLATE (SUBNODE)
        action = m_actionRegistry.getAction(SaveAsSubNodeTemplateAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHECK UPDATE (SUBNODE)
        action = m_actionRegistry.getAction(CheckUpdateMetaNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // DISCONNECT LINK (SUBNODE)
        action = m_actionRegistry.getAction(DisconnectSubNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHANGE LINK (SUBNODE)
        action = m_actionRegistry.getAction(ChangeSubNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // REVEAL TEMPLATE (SUBNODE)
        action = m_actionRegistry.getAction(RevealSubNodeTemplateAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LOCK SUBNODE
        if (Boolean.getBoolean(KNIMEConstants.PROPERTY_SHOW_METANODE_LOCK_ACTION)) {
            action = m_actionRegistry.getAction(LockSubNodeAction.ID);
            subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
            ((AbstractNodeAction) action).update();
        }
    }
    manager.updateAll(true);
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ExecuteAndOpenViewAction(org.knime.workbench.editor2.actions.ExecuteAndOpenViewAction) OpenViewAction(org.knime.workbench.editor2.actions.OpenViewAction) OpenInteractiveWebViewAction(org.knime.workbench.editor2.actions.OpenInteractiveWebViewAction) AddAnnotationAction(org.knime.workbench.editor2.actions.AddAnnotationAction) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) OpenPortViewAction(org.knime.workbench.editor2.actions.OpenPortViewAction) AbstractNodeAction(org.knime.workbench.editor2.actions.AbstractNodeAction) OpenSubNodeEditorAction(org.knime.workbench.editor2.actions.OpenSubNodeEditorAction) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IAction(org.eclipse.jface.action.IAction) OpenSubworkflowEditorAction(org.knime.workbench.editor2.actions.OpenSubworkflowEditorAction) UpdateAction(org.eclipse.gef.ui.actions.UpdateAction) OpenInteractiveViewAction(org.knime.workbench.editor2.actions.OpenInteractiveViewAction) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) Point(org.eclipse.swt.graphics.Point) OpenSubnodeWebViewAction(org.knime.workbench.editor2.actions.OpenSubnodeWebViewAction) OpenWorkflowPortViewAction(org.knime.workbench.editor2.actions.OpenWorkflowPortViewAction) IMenuManager(org.eclipse.jface.action.IMenuManager) InteractiveWebViewsResult(org.knime.core.node.workflow.action.InteractiveWebViewsResult) Separator(org.eclipse.jface.action.Separator)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)88 NodeID (org.knime.core.node.workflow.NodeID)31 NodeContainer (org.knime.core.node.workflow.NodeContainer)20 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)12 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)12 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)10 ArrayList (java.util.ArrayList)9 MessageBox (org.eclipse.swt.widgets.MessageBox)9 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 IOException (java.io.IOException)8 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)8 Map (java.util.Map)7 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)7 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)7 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)7 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)7 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)6