Search in sources :

Example 16 with WorkflowManager

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;
}
Also used : CreateDropRequest(org.knime.workbench.editor2.CreateDropRequest) DropNodeCommand(org.knime.workbench.editor2.commands.DropNodeCommand) ReaderNodeSettings(org.knime.workbench.editor2.ReaderNodeSettings) NodeFactory(org.knime.core.node.NodeFactory) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowPersistor(org.knime.core.node.workflow.WorkflowPersistor) NodeCreationContext(org.knime.core.node.NodeCreationContext)

Example 17 with WorkflowManager

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
    }
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeID(org.knime.core.node.workflow.NodeID)

Example 18 with WorkflowManager

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;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 19 with WorkflowManager

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;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager)

Example 20 with WorkflowManager

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
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) ExpandSubNodeCommand(org.knime.workbench.editor2.commands.ExpandSubNodeCommand) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox)

Aggregations

WorkflowManager (org.knime.core.node.workflow.WorkflowManager)99 NodeID (org.knime.core.node.workflow.NodeID)38 NodeContainer (org.knime.core.node.workflow.NodeContainer)22 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)15 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)15 File (java.io.File)14 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)14 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)10 WorkflowAnnotation (org.knime.core.node.workflow.WorkflowAnnotation)10 MessageBox (org.eclipse.swt.widgets.MessageBox)9 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)9 List (java.util.List)8 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)8 WorkflowCopyContent (org.knime.core.node.workflow.WorkflowCopyContent)8