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
}
}
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.");
}
}
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
}
}
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
}
}
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;
}
Aggregations