use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class NewWorkflowContainerEditPolicy method getCreateCommand.
/**
* {@inheritDoc}
*/
@Override
protected Command getCreateCommand(final CreateRequest request) {
// point where the command occurred
// The node/description should be initially located here
boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
WorkflowRootEditPart workflowPart = (WorkflowRootEditPart) this.getHost();
if (!Wrapper.wraps(workflowPart.getWorkflowManager(), WorkflowManager.class)) {
// adding new nodes not supported yet by UI-interfaces and implemenations
LOGGER.error("Adding new nodes not supported by '" + workflowPart.getWorkflowManager().getClass().getSimpleName() + "'.");
return null;
}
WorkflowManager manager = Wrapper.unwrapWFM(workflowPart.getWorkflowManager());
if (request instanceof CreateDropRequest) {
Object obj = request.getNewObject();
CreateDropRequest cdr = (CreateDropRequest) request;
if (obj instanceof NodeFactory) {
return handleNodeDrop(manager, (NodeFactory<? extends NodeModel>) obj, cdr);
} else if (obj instanceof AbstractExplorerFileStore) {
AbstractExplorerFileStore fs = (AbstractExplorerFileStore) obj;
if (AbstractExplorerFileStore.isWorkflowTemplate(fs)) {
return handleMetaNodeTemplateDrop(manager, cdr, fs);
}
} else if (obj instanceof WorkflowPersistor) {
return handleMetaNodeDrop(manager, (WorkflowPersistor) obj, cdr);
} else if (obj instanceof ReaderNodeSettings) {
ReaderNodeSettings settings = (ReaderNodeSettings) obj;
return new DropNodeCommand(manager, settings.getFactory(), new NodeCreationContext(settings.getUrl()), request.getLocation(), snapToGrid);
} else {
LOGGER.error("Illegal drop object: " + obj);
}
}
return null;
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ExecuteAction method runOnNodes.
/**
* This starts an execution job for the selected nodes. Note that this is
* all controlled by the WorkflowManager object of the currently open
* editor.
*
* @see org.knime.workbench.editor2.actions.AbstractNodeAction
* #runOnNodes(org.knime.workbench.editor2.
* editparts.NodeContainerEditPart[])
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
if (!isEnabled()) {
// for some reason hitting F7 bypasses the enable status
return;
}
LOGGER.debug("Creating execution job for " + nodeParts.length + " node(s)...");
WorkflowManager manager = getManager();
NodeID[] ids = new NodeID[nodeParts.length];
for (int i = 0; i < nodeParts.length; i++) {
ids[i] = nodeParts[i].getNodeContainer().getID();
}
manager.executeUpToHere(ids);
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 ExecuteAction method internalCalculateEnabled.
/**
* @return always <code>true</code>, as the WFM tries to execute as much
* as possible
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
// enable if we have at least one executable node in our selection
WorkflowManager wm = getEditor().getWorkflowManager().orElse(null);
if (wm == null) {
// fixes NPE when shutting down
return false;
}
for (int i = 0; i < parts.length; i++) {
NodeContainerUI nc = parts[i].getNodeContainer();
if (wm.canExecuteNode(nc.getID())) {
return true;
}
}
return false;
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ExecuteAndOpenViewAction method internalCalculateEnabled.
/**
* @return <code>true</code>, if just one node part is selected which is
* executable and additionally has at least one view.
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
// enable if we have at least one executable node in our selection
WorkflowManager wm = getEditor().getWorkflowManager().orElse(null);
if (wm == null) {
return false;
}
for (int i = 0; i < parts.length; i++) {
NodeContainerUI nc = parts[i].getNodeContainer();
boolean hasView = nc.getNrViews() > 0;
if (Wrapper.wraps(nc, NodeContainer.class)) {
hasView |= nc.hasInteractiveView() || unwrapNC(nc).getInteractiveWebViews().size() > 0;
hasView |= OpenSubnodeWebViewAction.hasContainerView(unwrapNC(nc));
}
if (wm.canExecuteNode(nc.getID()) && hasView) {
return true;
}
}
return false;
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ExpandSubNodeAction method runOnNodes.
/**
* Expand sub node!
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length < 1) {
return;
}
LOGGER.debug("Creating 'Expand Wrapped Metanode' job for " + nodeParts.length + " node(s)...");
try {
WorkflowManager manager = getManager();
SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
if (!subNode.getWorkflowManager().unlock(new GUIWorkflowCipherPrompt())) {
return;
}
// reset the metanode
if (manager.canResetNode(subNode.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 Wrapped 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(subNode.getID())) {
manager.resetAndConfigureNode(subNode.getID());
}
}
String res = manager.canExpandSubNode(subNode.getID());
if (res != null) {
throw new IllegalArgumentException(res);
}
ExpandSubNodeCommand emnc = new ExpandSubNodeCommand(manager, subNode.getID(), getEditor());
execute(emnc);
} catch (IllegalArgumentException e) {
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
mb.setMessage("Expanding Wrapped Metanode failed: " + e.getMessage());
mb.setText("Expand 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