Search in sources :

Example 56 with WorkflowManager

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

the class CancelAction method runOnNodes.

/**
 * This cancels all the selected nodes. Note that this is all controlled by
 * the WorkflowManager object of the currently open editor.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    LOGGER.debug("Creating cancel job for " + nodeParts.length + " node(s)...");
    WorkflowManager manager = getManager();
    for (NodeContainerEditPart p : nodeParts) {
        manager.cancelExecution(Wrapper.unwrapNC(p.getNodeContainer()));
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 57 with WorkflowManager

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

the class ChangeMetaNodeLinkAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    WorkflowManager metaNode = Wrapper.unwrapWFM(nodeParts[0].getNodeContainer());
    if (Role.Link.equals(metaNode.getTemplateInformation().getRole())) {
        WorkflowManager wfm = metaNode;
        while (!wfm.isProject()) {
            wfm = wfm.getParent();
        }
        URI targetURI = metaNode.getTemplateInformation().getSourceURI();
        LinkType linkType = LinkType.None;
        try {
            if (ResolverUtil.isMountpointRelativeURL(targetURI)) {
                linkType = LinkType.MountpointRelative;
            } else if (ResolverUtil.isWorkflowRelativeURL(targetURI)) {
                linkType = LinkType.WorkflowRelative;
            } else {
                linkType = LinkType.Absolute;
            }
        } catch (IOException e) {
            LOGGER.error("Unable to resolve current link to template " + targetURI + ": " + e.getMessage(), e);
            return;
        }
        String msg = "This is a linked (read-only) Metanode. Only the link type can be changed.\n";
        msg += "Please select the new type of the link to the metanode template.\n";
        msg += "(current type: " + linkType + ", current link: " + targetURI + ")\n";
        msg += "The origin of the template will not be changed - just the way it is referenced.";
        LinkPrompt dlg = new LinkPrompt(getEditor().getSite().getShell(), msg, linkType);
        dlg.open();
        if (dlg.getReturnCode() == Window.CANCEL) {
            return;
        }
        LinkType newLinkType = dlg.getLinkType();
        if (linkType.equals(newLinkType)) {
            LOGGER.info("Link type not changes as selected type equals existing type " + targetURI);
            return;
        }
        // as the workflow is local and the template in the same mountID, it should resolve to a file
        URI newURI = null;
        NodeContext.pushContext(metaNode);
        try {
            File targetFile = ResolverUtil.resolveURItoLocalFile(targetURI);
            LocalExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.fromLocalFile(targetFile);
            newURI = AbstractContentProvider.createMetanodeLinkUri(metaNode, targetfs, newLinkType);
        } catch (IOException e) {
            LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (URISyntaxException e) {
            LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } catch (CoreException e) {
            LOGGER.error("Unable to resolve metanode template URI " + targetURI + ": " + e.getMessage(), e);
            return;
        } finally {
            NodeContext.removeLastContext();
        }
        ChangeMetaNodeLinkCommand cmd = new ChangeMetaNodeLinkCommand(wfm, metaNode, targetURI, newURI);
        getCommandStack().execute(cmd);
    } else {
        throw new IllegalStateException("Can only change the type of a template link if the metanode is actually linked to a template - " + metaNode + " is not.");
    }
}
Also used : ChangeMetaNodeLinkCommand(org.knime.workbench.editor2.commands.ChangeMetaNodeLinkCommand) CoreException(org.eclipse.core.runtime.CoreException) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LinkType(org.knime.workbench.explorer.view.AbstractContentProvider.LinkType) URI(java.net.URI) File(java.io.File)

Example 58 with WorkflowManager

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

the class ConvertMetaNodeToSubNodeAction method runOnNodes.

/**
 * Expand metanode!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    try {
        WorkflowManager manager = getManager();
        WorkflowManager metaNode = Wrapper.unwrapWFM(nodeParts[0].getNodeContainer());
        if (!metaNode.unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // before we do anything, let's see if the convert will reset the metanode
        if (manager.canResetNode(metaNode.getID())) {
            // yes: ask if we can reset, otherwise bail
            MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
            mb.setMessage("Executed Nodes inside Metanode will be reset - are you sure?");
            mb.setText("Reset Executed Nodes");
            int dialogreturn = mb.open();
            if (dialogreturn == SWT.CANCEL) {
                return;
            }
            // perform reset
            if (manager.canResetNode(metaNode.getID())) {
                manager.resetAndConfigureNode(metaNode.getID());
            }
        }
        ConvertMetaNodeToSubNodeCommand cmnc = new ConvertMetaNodeToSubNodeCommand(manager, metaNode.getID());
        execute(cmnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Sorry, converting Metanode failed: " + e.getMessage());
        mb.setText("Convert failed");
        mb.open();
    }
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : ConvertMetaNodeToSubNodeCommand(org.knime.workbench.editor2.commands.ConvertMetaNodeToSubNodeCommand) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 59 with WorkflowManager

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

the class ExecuteAllAction method runOnNodes.

/**
 * This starts an execution job for all executable nodes. Note that this is
 * all controlled by the WorkflowManager object of the currently open
 * editor. The passed nodeParts are not needed here, as not only the
 * selected parts are executed but all executable nodes.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    WorkflowManager wm = getManager();
    wm.executeAll();
    try {
        // Give focus to the editor again. Otherwise the actions (selection)
        // is not updated correctly.
        getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
    } catch (Exception e) {
    // ignore
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 60 with WorkflowManager

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

the class NodeConnectionContainerDeleteAction method createDeleteCommand.

/**
 * Create one command to remove the selected objects.
 *
 * @param objects The objects to be deleted.
 * @return The command to remove the selected objects.
 */
@Override
public Command createDeleteCommand(final List objects) {
    if (objects.isEmpty()) {
        return null;
    }
    if (!(objects.get(0) instanceof EditPart)) {
        return null;
    }
    VerifyingCompoundCommand compoundCmd = new VerifyingCompoundCommand(GEFMessages.DeleteAction_ActionDeleteCommandName);
    // will contain nodes -- just used for marking
    NodeContainerEditPart[] nodeParts = AbstractNodeAction.filterObjects(NodeContainerEditPart.class, objects);
    Optional<WorkflowManager> manager = ((WorkflowEditor) getWorkbenchPart()).getWorkflowManager();
    if (manager.isPresent()) {
        DeleteCommand cmd = new DeleteCommand(objects, manager.get());
        int nodeCount = cmd.getNodeCount();
        int connCount = cmd.getConnectionCount();
        int annoCount = cmd.getAnnotationCount();
        StringBuilder dialogText = new StringBuilder("Do you really want to delete ");
        if (nodeCount > 0) {
            dialogText.append(nodeCount).append(" node");
            dialogText.append(nodeCount > 1 ? "s" : "");
            if (annoCount > 0 && connCount > 0) {
                dialogText.append(" , ");
            } else if (annoCount > 0 || connCount > 0) {
                dialogText.append(" and ");
            }
        }
        if (connCount > 0) {
            dialogText.append(connCount).append(" connection");
            dialogText.append(connCount > 1 ? "s" : "");
            dialogText.append(annoCount > 0 ? " and " : "");
        }
        if (annoCount > 0) {
            dialogText.append(annoCount).append(" annotation");
            dialogText.append(annoCount > 1 ? "s" : "");
        }
        dialogText.append("?");
        compoundCmd.setDialogDisplayText(dialogText.toString());
        // set the parts into the compound command (for unmarking after cancel)
        compoundCmd.setNodeParts(Arrays.asList(nodeParts));
        compoundCmd.add(cmd);
    }
    return compoundCmd;
}
Also used : VerifyingCompoundCommand(org.knime.workbench.editor2.commands.VerifyingCompoundCommand) WorkflowEditor(org.knime.workbench.editor2.WorkflowEditor) DeleteCommand(org.knime.workbench.editor2.commands.DeleteCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart)

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