Search in sources :

Example 1 with WorkflowManagerUI

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

the class AddMetaNodeAction method setActiveEditor.

/**
 * {@inheritDoc}
 */
@Override
public void setActiveEditor(final IAction action, final IEditorPart targetEditor) {
    m_editor = (WorkflowEditor) targetEditor;
    boolean enabled = false;
    if (m_editor != null) {
        WorkflowManagerUI wm = m_editor.getWorkflowManagerUI();
        enabled = wm != null && !wm.isWriteProtected();
    }
    action.setEnabled(enabled);
}
Also used : WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI)

Example 2 with WorkflowManagerUI

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

the class ChangeMetaNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainerUI nc = nodes[0].getNodeContainer();
    if (!(nc instanceof WorkflowManagerUI)) {
        return false;
    }
    WorkflowManagerUI metaNode = (WorkflowManagerUI) nc;
    if (!Role.Link.equals(unwrapWFM(metaNode).getTemplateInformation().getRole()) || metaNode.getParent().isWriteProtected()) {
        // metanode must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = unwrapWFM(metaNode).getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = metaNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) IOException(java.io.IOException) URI(java.net.URI)

Example 3 with WorkflowManagerUI

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

the class ExpandMetaNodeAction method runOnNodes.

/**
 * Expand metanode!
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    if (nodeParts.length < 1) {
        return;
    }
    LOGGER.debug("Creating 'Expand MetaNode' job for " + nodeParts.length + " node(s)...");
    try {
        WorkflowManager manager = getManager();
        WorkflowManagerUI metaNode = (WorkflowManagerUI) nodeParts[0].getNodeContainer();
        if (!Wrapper.unwrapWFM(metaNode).unlock(new GUIWorkflowCipherPrompt())) {
            return;
        }
        // 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());
            }
        }
        String res = manager.canExpandMetaNode(metaNode.getID());
        if (res != null) {
            throw new IllegalArgumentException(res);
        }
        ExpandMetaNodeCommand emnc = new ExpandMetaNodeCommand(manager, metaNode.getID(), getEditor());
        execute(emnc);
    } catch (IllegalArgumentException e) {
        MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
        mb.setMessage("Sorry, expanding 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 : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt) MessageBox(org.eclipse.swt.widgets.MessageBox) ExpandMetaNodeCommand(org.knime.workbench.editor2.commands.ExpandMetaNodeCommand)

Example 4 with WorkflowManagerUI

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

the class NodeContainerEditPart method openSubWorkflowEditor.

public void openSubWorkflowEditor() {
    WorkflowCipherPrompt prompt = new GUIWorkflowCipherPrompt();
    Object obj = getModel();
    WorkflowManagerUI wm;
    if (obj instanceof WorkflowManagerUI) {
        wm = (WorkflowManagerUI) getModel();
    } else if (obj instanceof SubNodeContainerUI) {
        wm = ((SubNodeContainerUI) obj).getWorkflowManager();
    } else {
        return;
    }
    // if workflow manager is encrypted, try unlocking it
    if (wm.isEncrypted()) {
        if (!Wrapper.unwrapWFM(wm).unlock(prompt)) {
            return;
        }
    }
    // open new editor for subworkflow
    LOGGER.debug("opening new editor for sub-workflow");
    try {
        final WorkflowEditor parent = (WorkflowEditor) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        WorkflowManagerInput input = new WorkflowManagerInput(wm, parent);
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, "org.knime.workbench.editor.WorkflowEditor");
    } catch (PartInitException e) {
        LOGGER.error("Error while opening new editor", e);
    }
    return;
}
Also used : WorkflowEditor(org.knime.workbench.editor2.WorkflowEditor) WorkflowCipherPrompt(org.knime.core.node.workflow.WorkflowCipherPrompt) WorkflowManagerInput(org.knime.workbench.editor2.WorkflowManagerInput) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) PartInitException(org.eclipse.ui.PartInitException)

Example 5 with WorkflowManagerUI

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

the class NodeContainerEditPart method checkMetaNodeLockIcon.

private void checkMetaNodeLockIcon() {
    NodeContainerUI nc = getNodeContainer();
    if (nc instanceof WorkflowManagerUI) {
        WorkflowManagerUI wm = (WorkflowManagerUI) nc;
        Image i;
        if (wm.isEncrypted()) {
            if (wm.isUnlocked()) {
                i = META_NODE_UNLOCK_ICON;
            } else {
                i = META_NODE_LOCK_ICON;
            }
        } else {
            i = null;
        }
        NodeContainerFigure fig = (NodeContainerFigure) getFigure();
        fig.setMetaNodeLockIcon(i);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) Image(org.eclipse.swt.graphics.Image) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure)

Aggregations

WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)37 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)16 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)12 SubNodeContainerUI (org.knime.core.ui.node.workflow.SubNodeContainerUI)7 ArrayList (java.util.ArrayList)6 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)6 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)5 URI (java.net.URI)3 IContainer (org.eclipse.core.resources.IContainer)3 Point (org.eclipse.draw2d.geometry.Point)3 EditPart (org.eclipse.gef.EditPart)3 Image (org.eclipse.swt.graphics.Image)3 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)3 NodeAnnotation (org.knime.core.node.workflow.NodeAnnotation)3 NodeID (org.knime.core.node.workflow.NodeID)3 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)3 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)3 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)3 List (java.util.List)2 IFile (org.eclipse.core.resources.IFile)2