use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class ChangeEditorUIAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
EditorUISettingsDialog dlg = new EditorUISettingsDialog(Display.getCurrent().getActiveShell(), getEditor().getCurrentEditorSettings());
if (dlg.open() == Window.OK) {
// store settings with the workflow (workflow is marked dirty)
getEditor().markDirty();
getEditor().applyEditorSettings(dlg.getSettings());
getEditor().getWorkflowManager().get().setEditorUIInformation(dlg.getSettings());
// refresh workflow editor
// TODO this doesn't work - it doesn't refresh the ConnectionContainerEditParts
// WorkflowRootEditPart editorPart = (WorkflowRootEditPart)
// provider.getRootEditPart().getChildren().get(0);
// editorPart.refresh();
// workaround to refresh all connection container edit parts
getEditor().getWorkflowManager().get().getConnectionContainers().forEach(cc -> cc.setUIInfo(cc.getUIInfo()));
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class WorkflowEditPartFactory method createEditPart.
/**
* Creates the referring edit parts for the following parts of the model.
* <ul>
* <li>{@link WorkflowManager}: either {@link WorkflowRootEditPart} or {@link NodeContainerEditPart} (depending on
* the currently displayed level)</li>
* <li>{@link SingleNodeContainer}: {@link NodeContainerEditPart}</li>
* <li>{@link NodeInPort}: {@link NodeInPortEditPart}</li>
* <li>{@link NodeOutPort}: {@link NodeOutPortEditPart}</li>
* <li>{@link ConnectionContainer}: {@link ConnectionContainerEditPart}</li>
* <li>{@link WorkflowInPort}: {@link WorkflowInPortEditPart}</li>
* <li>{@link WorkflowOutPort}: {@link WorkflowOutPortEditPart}</li>
* </ul>
*
* The {@link WorkflowRootEditPart} has its {@link NodeContainer}s and its {@link WorkflowInPort}s and
* {@link WorkflowOutPort}s as model children. The {@link NodeContainerEditPart} has its {@link NodePort}s as its
* children.
*
* @see WorkflowRootEditPart#getModelChildren()
* @see NodeContainerEditPart#getModelChildren()
*
* @throws IllegalArgumentException if any other object is passed
*
* {@inheritDoc}
*/
@Override
public EditPart createEditPart(final EditPart context, final Object model) {
// instantiated here
// correct type in the if statement
// model at the end of method
EditPart part = null;
if (model instanceof WorkflowManagerUI) {
// this is out "root" workflow manager
if (m_isTop) {
// all following objects of type WorkflowManager are treated as
// metanodes and displayed as NodeContainers
m_isTop = false;
part = new WorkflowRootEditPart();
} else {
// we already have a "root" workflow manager
// must be a metanode
part = new SubworkflowEditPart();
}
} else if (model instanceof NodeAnnotation) {
/* IMPORTANT: first test NodeAnnotation then Annotation (as the
* first derives from the latter! */
part = new NodeAnnotationEditPart();
} else if (model instanceof Annotation) {
/* IMPORTANT: first test NodeAnnotation then Annotation (as the
* first derives from the latter! */
/* workflow annotations hang off the workflow manager */
part = new AnnotationEditPart();
} else if (model instanceof WorkflowPortBar) {
WorkflowPortBar bar = (WorkflowPortBar) model;
if (bar.isInPortBar()) {
part = new WorkflowInPortBarEditPart();
} else {
part = new WorkflowOutPortBarEditPart();
}
} else if (model instanceof SingleNodeContainerUI) {
// SingleNodeContainer -> NodeContainerEditPart
part = new NodeContainerEditPart();
// we have to test for WorkflowInPort first because it's a
// subclass of NodeInPort (same holds for WorkflowOutPort and
// NodeOutPort)
} else if (model instanceof WorkflowInPortUI && context instanceof WorkflowInPortBarEditPart) {
// WorkflowInPort and context WorkflowRootEditPart ->
// WorkflowInPortEditPart
/*
* if the context is a WorkflowRootEditPart it indicates that the
* WorkflowInPort is a model child of the WorkflowRootEditPart, i.e.
* we look at it as a workflow in port. If the context is a
* NodeContainerEditPart the WorkflowInPort is a model child of a
* NodeContainerEditPart and we look at it as a node in port.
*/
WorkflowInPortUI inport = (WorkflowInPortUI) model;
part = new WorkflowInPortEditPart(inport.getPortType(), inport.getPortIndex());
} else if (model instanceof WorkflowOutPortUI && context instanceof WorkflowOutPortBarEditPart) {
// WorkflowOutPort and context WorkflowRootEditPart ->
// WorkflowOutPortEditPart
/*
* if the context is a WorkflowRootEditPart it indicates that the
* WorkflowOutPort is a model child of the WorkflowRootEditPart,
* i.e. we look at it as a workflow out port. If the context is a
* NodeContainerEditPart the WorkflowOutPort is a model child of a
* NodeContainerEditPart and we look at it as a node out port.
*/
// TODO: return SubWorkFlowOutPortEditPart
WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
part = new WorkflowOutPortEditPart(outport.getPortType(), outport.getPortIndex());
} else if (model instanceof WorkflowOutPortUI) {
// TODO: return SubWorkFlowOutPortEditPart
WorkflowOutPortUI outport = (WorkflowOutPortUI) model;
part = new MetaNodeOutPortEditPart(outport.getPortType(), outport.getPortIndex());
} else if (model instanceof NodeInPortUI) {
// NodeInPort -> NodeInPortEditPart
NodePortUI port = (NodeInPortUI) model;
part = new NodeInPortEditPart(port.getPortType(), port.getPortIndex());
} else if (model instanceof NodeOutPortUI) {
// NodeOutPort -> NodeOutPortEditPart
NodePortUI port = (NodeOutPortUI) model;
part = new NodeOutPortEditPart(port.getPortType(), port.getPortIndex());
} else if (model instanceof ConnectionContainerUI) {
// ConnectionContainer -> ConnectionContainerEditPart
part = new ConnectionContainerEditPart();
} else {
throw new IllegalArgumentException("unknown model obj: " + model);
}
// associate the model with the part (= the controller)
part.setModel(model);
return part;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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
}
}
Aggregations