Search in sources :

Example 66 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class DefaultOpenViewAction method internalCalculateEnabled.

/**
 * @return true if at least one selected node is executing or queued
 * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
    // enable if we have at least one executing or queued node in our
    // selection
    boolean atLeastOneNodeIsExecuted = 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));
            atLeastOneNodeIsExecuted |= nc.getNodeContainerState().isExecuted() && hasView;
        }
    }
    return atLeastOneNodeIsExecuted;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart)

Example 67 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class DefaultOpenViewAction method runOnNodes.

/**
 * This opens the first view of all the selected nodes.
 *
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
    LOGGER.debug("Creating open default view job for " + nodeParts.length + " node(s)...");
    for (NodeContainerEditPart p : nodeParts) {
        final NodeContainer cont = unwrapNC(p.getNodeContainer());
        final InteractiveWebViewsResult webViewsResult = cont.getInteractiveWebViews();
        boolean hasView = cont.getNrViews() > 0;
        hasView |= cont.hasInteractiveView() || webViewsResult.size() > 0;
        hasView |= OpenSubnodeWebViewAction.hasContainerView(cont);
        if (cont.getNodeContainerState().isExecuted() && hasView) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        final IAction action;
                        if (cont.hasInteractiveView()) {
                            action = new OpenInteractiveViewAction(cont);
                        } else if (cont instanceof SubNodeContainer) {
                            action = new OpenSubnodeWebViewAction((SubNodeContainer) cont);
                        } else if (webViewsResult.size() > 0) {
                            action = new OpenInteractiveWebViewAction(cont, webViewsResult.get(0));
                        } else {
                            action = new OpenViewAction(cont, 0);
                        }
                        action.run();
                    } catch (Throwable t) {
                        MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
                        mb.setText("View cannot be opened");
                        mb.setMessage("The view cannot be opened for the " + "following reason:\n" + t.getMessage());
                        mb.open();
                        LOGGER.error("The view for node '" + cont.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an " + "implementation error.", t);
                    }
                }
            });
        }
    }
    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 : IAction(org.eclipse.jface.action.IAction) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) MessageBox(org.eclipse.swt.widgets.MessageBox) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) InteractiveWebViewsResult(org.knime.core.node.workflow.action.InteractiveWebViewsResult)

Example 68 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class LockMetaNodeAction method runOnNodes.

/**
 * {@inheritDoc}
 */
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
    if (nodes.length != 1) {
        return;
    }
    Object model = nodes[0].getModel();
    if (!(model instanceof WorkflowManagerUI)) {
        return;
    }
    WorkflowManagerUI metaNodeWFM = (WorkflowManagerUI) model;
    final Shell shell = Display.getCurrent().getActiveShell();
    if (!unwrapWFM(metaNodeWFM).unlock(new GUIWorkflowCipherPrompt())) {
        return;
    }
    LockMetaNodeDialog lockDialog = new LockMetaNodeDialog(shell, unwrapWFM(metaNodeWFM));
    if (lockDialog.open() != Window.OK) {
        return;
    }
    String password = lockDialog.getPassword();
    String hint = lockDialog.getPasswordHint();
    try {
        metaNodeWFM.setWorkflowPassword(password, hint);
    } catch (NoSuchAlgorithmException e) {
        String msg = "Unable to encrypt metanode: " + e.getMessage();
        LOGGER.error(msg, e);
        MessageDialog.openError(shell, "Metanode encrypt", msg);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) GUIWorkflowCipherPrompt(org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)

Example 69 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class LockSubNodeAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of
 *         <code>SubNodeContainer</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    if (getManager().isWriteProtected()) {
        return false;
    }
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    Object model = nodes[0].getModel();
    if (Wrapper.wraps(model, SubNodeContainer.class)) {
        SubNodeContainer snc = Wrapper.unwrap((UI) model, SubNodeContainer.class);
        if (snc.isWriteProtected()) {
            return false;
        }
        return true;
    } else {
        return false;
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart)

Example 70 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.

the class MoveNodeAbstractAction method getMoveableSelectedEditParts.

private List<EditPart> getMoveableSelectedEditParts() {
    @SuppressWarnings("rawtypes") List selectedObjects = getSelectedObjects();
    LinkedList<EditPart> result = new LinkedList<EditPart>();
    for (Object o : selectedObjects) {
        if ((o instanceof AnnotationEditPart) && !(o instanceof NodeAnnotationEditPart)) {
            result.add((AnnotationEditPart) o);
            continue;
        }
        if (o instanceof NodeContainerEditPart) {
            result.add((NodeContainerEditPart) o);
            continue;
        }
    }
    return result;
}
Also used : AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) AbstractWorkflowEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowEditPart) EditPart(org.eclipse.gef.EditPart) List(java.util.List) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)

Aggregations

NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)77 NodeContainerUI (org.knime.core.ui.node.workflow.NodeContainerUI)28 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)16 EditPart (org.eclipse.gef.EditPart)15 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)14 Point (org.eclipse.draw2d.geometry.Point)11 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)11 NodeContainer (org.knime.core.node.workflow.NodeContainer)9 NodeID (org.knime.core.node.workflow.NodeID)9 AnnotationEditPart (org.knime.workbench.editor2.editparts.AnnotationEditPart)9 NodeAnnotationEditPart (org.knime.workbench.editor2.editparts.NodeAnnotationEditPart)9 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)9 ArrayList (java.util.ArrayList)8 GUIWorkflowCipherPrompt (org.knime.workbench.editor2.editparts.GUIWorkflowCipherPrompt)8 MetaNodeTemplateInformation (org.knime.core.node.workflow.MetaNodeTemplateInformation)6 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)6 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)6 Rectangle (org.eclipse.draw2d.geometry.Rectangle)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5