Search in sources :

Example 1 with WorkflowInPortBarEditPart

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

the class WorkflowContextMenuProvider method buildContextMenu.

/**
 * {@inheritDoc}
 */
@Override
public void buildContextMenu(final IMenuManager manager) {
    final String FLOW_VAR_PORT_GRP = "Flow Variable Ports";
    // add the groups (grouped by separators) in their order first
    manager.add(new Separator(IWorkbenchActionConstants.GROUP_APP));
    manager.add(new Separator(FLOW_VAR_PORT_GRP));
    GEFActionConstants.addStandardActionGroups(manager);
    IAction action;
    action = m_actionRegistry.getAction("cut");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("copy");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction(PasteActionContextMenu.ID);
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("undo");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("redo");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    action = m_actionRegistry.getAction("delete");
    manager.appendToGroup(GEFActionConstants.GROUP_EDIT, action);
    ((UpdateAction) action).update();
    // Add (some) available actions from the registry to the context menu
    // manager
    // openDialog
    action = m_actionRegistry.getAction(OpenDialogAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // execute
    action = m_actionRegistry.getAction(ExecuteAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // execute and open first view
    action = m_actionRegistry.getAction(ExecuteAndOpenViewAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // cancel execution
    action = m_actionRegistry.getAction(CancelAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // show some menu items on LoopEndNodes only
    List parts = m_viewer.getSelectedEditParts();
    if (parts.size() == 1) {
        EditPart p = (EditPart) parts.get(0);
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI container = (NodeContainerUI) ((NodeContainerEditPart) p).getModel();
            if (container instanceof SingleNodeContainerUI) {
                SingleNodeContainerUI snc = (SingleNodeContainerUI) container;
                Wrapper.unwrapOptional(snc, SingleNodeContainer.class).ifPresent(sncImpl -> {
                    if (sncImpl.isModelCompatibleTo(LoopEndNode.class)) {
                        // pause loop execution
                        IAction loopAction;
                        loopAction = m_actionRegistry.getAction(PauseLoopExecutionAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                        // step loop execution
                        loopAction = m_actionRegistry.getAction(StepLoopAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                        // resume loop execution
                        loopAction = m_actionRegistry.getAction(ResumeLoopAction.ID);
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, loopAction);
                        ((AbstractNodeAction) loopAction).update();
                    }
                });
            }
        }
    }
    // reset
    action = m_actionRegistry.getAction(ResetAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // set name and description
    action = m_actionRegistry.getAction(SetNodeDescriptionAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // add workflow annotation
    action = m_actionRegistry.getAction(AddAnnotationAction.ID);
    AddAnnotationAction aaa = (AddAnnotationAction) action;
    aaa.setLocation(m_lastLocation.x, m_lastLocation.y);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // collapse metanodes
    action = m_actionRegistry.getAction(CollapseMetaNodeAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    action = m_actionRegistry.getAction(EncapsulateSubNodeAction.ID);
    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
    ((AbstractNodeAction) action).update();
    // insert "select loop" if loop nodes are selected
    boolean addSelectLoop = true;
    for (Object p : parts) {
        if (!(p instanceof NodeContainerEditPart)) {
            addSelectLoop = false;
            break;
        }
        NodeContainerUI nc = ((NodeContainerEditPart) p).getNodeContainer();
        if (!(nc instanceof SingleNodeContainerUI)) {
            addSelectLoop = false;
            break;
        }
        if (!((SingleNodeContainerUI) nc).isMemberOfScope()) {
            addSelectLoop = false;
            break;
        }
    }
    if (addSelectLoop) {
        action = m_actionRegistry.getAction(SelectLoopAction.ID);
        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
        ((AbstractNodeAction) action).update();
    }
    IMenuManager metanodeMenuMgr = null;
    IMenuManager subnodeMenuMgr = null;
    IMenuManager subnodeViewMgr = null;
    // depending on the current selection: add the actions for the port
    // views and the node views
    // also check whether this node part is a meta-node
    // if so offer the "edit meta-node" option
    // all these feature are only offered if exactly 1 part is selected
    parts = m_viewer.getSelectedEditParts();
    // by now, we only support one part...
    if (parts.size() == 1) {
        EditPart p = (EditPart) parts.get(0);
        if (p instanceof WorkflowInPortBarEditPart) {
            WorkflowInPortBarEditPart root = (WorkflowInPortBarEditPart) p;
            manager.add(new Separator("outPortViews"));
            for (Object o : p.getChildren()) {
                EditPart child = (EditPart) o;
                if (child instanceof WorkflowInPortEditPart && ((WorkflowInPortEditPart) child).isSelected()) {
                    final WorkflowManager wm = Wrapper.unwrapWFM(((WorkflowPortBar) root.getModel()).getWorkflowManager());
                    action = new OpenWorkflowPortViewAction(wm, ((WorkflowInPortEditPart) child).getIndex(), wm.getNrInPorts());
                    manager.appendToGroup("outPortViews", action);
                    ((WorkflowInPortEditPart) child).setSelected(false);
                }
            }
        }
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI container = null;
            container = (NodeContainerUI) ((NodeContainerEditPart) p).getModel();
            if (!(container instanceof WorkflowManagerUI)) {
                action = m_actionRegistry.getAction(ToggleFlowVarPortsAction.ID);
                manager.appendToGroup(FLOW_VAR_PORT_GRP, action);
                ((AbstractNodeAction) action).update();
            }
            // add for node views option if applicable
            int numNodeViews = container.getNrViews();
            for (int i = 0; i < numNodeViews; i++) {
                action = new OpenViewAction(unwrapNC(container), i);
                manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
            }
            // add interactive view options
            if (container.hasInteractiveView()) {
                action = new OpenInteractiveViewAction(unwrapNC(container));
                manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
            } else {
                // TODO for subnodes move to submenu?
                if (wraps(container, NativeNodeContainer.class)) {
                    InteractiveWebViewsResult interactiveWebViewsResult = unwrapNC(container).getInteractiveWebViews();
                    for (int i = 0; i < interactiveWebViewsResult.size(); i++) {
                        action = new OpenInteractiveWebViewAction(unwrapNC(container), interactiveWebViewsResult.get(i));
                        manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
                    }
                }
            }
            if (container instanceof WorkflowManagerUI) {
                metanodeMenuMgr = getMetaNodeMenuManager(metanodeMenuMgr, manager);
                // OPEN META NODE
                action = new OpenSubworkflowEditorAction((NodeContainerEditPart) p);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                // EXPAND META NODE
                action = m_actionRegistry.getAction(ExpandMetaNodeAction.ID);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                ((AbstractNodeAction) action).update();
                // RECONFIGURE META NODE
                if (parts.size() == 1) {
                    action = m_actionRegistry.getAction(MetaNodeReconfigureAction.ID);
                    metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                    ((AbstractNodeAction) action).update();
                }
                // WRAP
                action = m_actionRegistry.getAction(ConvertMetaNodeToSubNodeAction.ID);
                metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
                ((AbstractNodeAction) action).update();
            }
            // SUBNODE
            if (container instanceof SubNodeContainerUI) {
                subnodeMenuMgr = getSubNodeMenuManager(subnodeMenuMgr, manager);
                // OPEN SUBNODE
                action = new OpenSubNodeEditorAction((NodeContainerEditPart) p);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                // EXPAND SUBNODE
                action = m_actionRegistry.getAction(ExpandSubNodeAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                // RECONFIGURE SUBNODE
                action = m_actionRegistry.getAction(SubNodeReconfigureAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                // UNWRAP
                action = m_actionRegistry.getAction(ConvertSubNodeToMetaNodeAction.ID);
                subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
                ((AbstractNodeAction) action).update();
                if (wraps(container, SubNodeContainer.class)) {
                    InteractiveWebViewsResult interactiveWebViewsResult = unwrapNC(container).getInteractiveWebViews();
                    if (interactiveWebViewsResult.size() > 0) {
                        subnodeViewMgr = getSingleSubNodeViewsMenuManager(subnodeViewMgr, subnodeMenuMgr);
                        for (int i = 0; i < interactiveWebViewsResult.size(); i++) {
                            action = new OpenInteractiveWebViewAction(unwrapNC(container), interactiveWebViewsResult.get(i));
                            subnodeViewMgr.appendToGroup(GROUP_SUBNODE_VIEWS, action);
                        }
                    }
                    action = new OpenSubnodeWebViewAction(Wrapper.unwrap(container, SubNodeContainer.class));
                    manager.appendToGroup(IWorkbenchActionConstants.GROUP_APP, action);
                }
            }
            // add port views
            manager.add(new Separator("outPortViews"));
            int numOutPorts = container.getNrOutPorts();
            for (int i = 0; i < numOutPorts; i++) {
                if (i == 0 && !(container instanceof WorkflowManagerUI)) {
                    // skip the implicit flow var ports on "normal" nodes
                    continue;
                }
                if (wraps(container, NodeContainer.class)) {
                    action = new OpenPortViewAction(unwrapNC(container), i, numOutPorts);
                    manager.appendToGroup("outPortViews", action);
                }
            }
        }
    }
    boolean addMetaNodeActions = false;
    boolean addSubNodeActions = false;
    for (Object p : parts) {
        if (p instanceof NodeContainerEditPart) {
            NodeContainerUI model = ((NodeContainerEditPart) p).getNodeContainer();
            if (model instanceof WorkflowManagerUI) {
                addMetaNodeActions = true;
            } else if (model instanceof SubNodeContainerUI) {
                addSubNodeActions = true;
            }
        }
    }
    if (addMetaNodeActions) {
        metanodeMenuMgr = getMetaNodeMenuManager(metanodeMenuMgr, manager);
        // SAVE AS TEMPLATE
        action = m_actionRegistry.getAction(SaveAsMetaNodeTemplateAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHECK UPDATE
        action = m_actionRegistry.getAction(CheckUpdateMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // DISCONNECT
        action = m_actionRegistry.getAction(DisconnectMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LINK TYPE
        action = m_actionRegistry.getAction(ChangeMetaNodeLinkAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // REVEAL TEMPLATE
        action = m_actionRegistry.getAction(RevealMetaNodeTemplateAction.ID);
        metanodeMenuMgr.appendToGroup(GROUP_METANODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LOCK
        if (Boolean.getBoolean(KNIMEConstants.PROPERTY_SHOW_METANODE_LOCK_ACTION)) {
            action = m_actionRegistry.getAction(LockMetaNodeAction.ID);
            metanodeMenuMgr.appendToGroup(GROUP_METANODE, action);
            ((AbstractNodeAction) action).update();
        }
    }
    if (addSubNodeActions) {
        subnodeMenuMgr = getSubNodeMenuManager(subnodeMenuMgr, manager);
        // SAVE AS TEMPLATE (SUBNODE)
        action = m_actionRegistry.getAction(SaveAsSubNodeTemplateAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHECK UPDATE (SUBNODE)
        action = m_actionRegistry.getAction(CheckUpdateMetaNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // DISCONNECT LINK (SUBNODE)
        action = m_actionRegistry.getAction(DisconnectSubNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // CHANGE LINK (SUBNODE)
        action = m_actionRegistry.getAction(ChangeSubNodeLinkAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // REVEAL TEMPLATE (SUBNODE)
        action = m_actionRegistry.getAction(RevealSubNodeTemplateAction.ID);
        subnodeMenuMgr.appendToGroup(GROUP_SUBNODE_LINKS, action);
        ((AbstractNodeAction) action).update();
        // LOCK SUBNODE
        if (Boolean.getBoolean(KNIMEConstants.PROPERTY_SHOW_METANODE_LOCK_ACTION)) {
            action = m_actionRegistry.getAction(LockSubNodeAction.ID);
            subnodeMenuMgr.appendToGroup(GROUP_SUBNODE, action);
            ((AbstractNodeAction) action).update();
        }
    }
    manager.updateAll(true);
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ExecuteAndOpenViewAction(org.knime.workbench.editor2.actions.ExecuteAndOpenViewAction) OpenViewAction(org.knime.workbench.editor2.actions.OpenViewAction) OpenInteractiveWebViewAction(org.knime.workbench.editor2.actions.OpenInteractiveWebViewAction) AddAnnotationAction(org.knime.workbench.editor2.actions.AddAnnotationAction) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) OpenPortViewAction(org.knime.workbench.editor2.actions.OpenPortViewAction) AbstractNodeAction(org.knime.workbench.editor2.actions.AbstractNodeAction) OpenSubNodeEditorAction(org.knime.workbench.editor2.actions.OpenSubNodeEditorAction) List(java.util.List) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IAction(org.eclipse.jface.action.IAction) OpenSubworkflowEditorAction(org.knime.workbench.editor2.actions.OpenSubworkflowEditorAction) UpdateAction(org.eclipse.gef.ui.actions.UpdateAction) OpenInteractiveViewAction(org.knime.workbench.editor2.actions.OpenInteractiveViewAction) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) Point(org.eclipse.swt.graphics.Point) OpenSubnodeWebViewAction(org.knime.workbench.editor2.actions.OpenSubnodeWebViewAction) OpenWorkflowPortViewAction(org.knime.workbench.editor2.actions.OpenWorkflowPortViewAction) IMenuManager(org.eclipse.jface.action.IMenuManager) InteractiveWebViewsResult(org.knime.core.node.workflow.action.InteractiveWebViewsResult) Separator(org.eclipse.jface.action.Separator)

Example 2 with WorkflowInPortBarEditPart

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

the class WorkflowEditorDropTargetListener method getInsertLocation.

/**
 * Computes the location of the new node and also determines if some node should be moved.
 *
 * A successor node is selected for the move action if the distance between this node and the successor is
 * smaller than the {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE} and if they overlap vertically.
 *
 * @return point where the new node should be inserted and sets
 *         {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget}
 */
private Point getInsertLocation() {
    ZoomManager zoomManager = (ZoomManager) getViewer().getProperty(ZoomManager.class.toString());
    double zoom = zoomManager.getZoom();
    int adjustedMinimumNodeDistance = (int) (MINIMUM_NODE_DISTANCE * zoom);
    double adjustedMinimumNodeDistanceBeforeInsertion = MINIMUM_NODE_DISTANCE_BEFORE_INSERTION * zoom;
    Point dropLocation = getDropLocation();
    Point insertLocation = dropLocation;
    int[] sourceBounds = null;
    int[] targetBounds = null;
    int sourceAnnotationHeight = 0;
    int targetAnnotationHeight = 0;
    EditPart source = m_edge.getSource().getParent();
    EditPart target = m_edge.getTarget().getParent();
    NodeContainerEditPart nextNode = null;
    if (source instanceof WorkflowInPortBarEditPart && target instanceof NodeContainerEditPart) {
        // metanode start --> first node in metanode
        WorkflowInPortBarEditPart sourceBar = ((WorkflowInPortBarEditPart) source);
        NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
        Rectangle bounds = sourceBar.getFigure().getBounds();
        org.eclipse.swt.graphics.Point p = getViewer().getControl().toControl(bounds.x, bounds.y);
        sourceBounds = new int[] { p.x, p.y, bounds.width, bounds.height };
        targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
        targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
        nextNode = targetNode;
    } else if (source instanceof NodeContainerEditPart && target instanceof WorkflowOutPortBarEditPart) {
        // last node in metanode --> metanode end
        NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
        WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
        sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
        Rectangle bounds = targetBar.getFigure().getBounds();
        targetBounds = new int[] { bounds.x, bounds.y, bounds.width, bounds.height };
        sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
    } else if (source instanceof WorkflowInPortBarEditPart && target instanceof WorkflowOutPortBarEditPart) {
        // metanode start --> metanode end
        WorkflowInPortBarEditPart sourceBar = (WorkflowInPortBarEditPart) source;
        WorkflowOutPortBarEditPart targetBar = (WorkflowOutPortBarEditPart) target;
        sourceBounds = sourceBar.getNodeContainer().getUIInformation().getBounds();
        targetBounds = targetBar.getNodeContainer().getUIInformation().getBounds();
    } else if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
        // node --> node
        NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
        NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
        sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
        targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
        sourceAnnotationHeight = sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
        targetAnnotationHeight = targetNode.getNodeAnnotationEditPart().getModel().getHeight();
        nextNode = targetNode;
    }
    if (sourceBounds != null && targetBounds != null) {
        sourceBounds = recomputeBounds(sourceBounds);
        targetBounds = recomputeBounds(targetBounds);
        if (0 <= targetBounds[0] - sourceBounds[0] && targetBounds[0] - sourceBounds[0] >= adjustedMinimumNodeDistanceBeforeInsertion) {
            m_distanceToMoveTarget = 0;
        } else {
            m_distanceToMoveTarget = adjustedMinimumNodeDistance + (sourceBounds[0] + adjustedMinimumNodeDistance - targetBounds[0]);
            m_distanceToMoveTarget = (int) (m_distanceToMoveTarget / zoom);
        }
        insertLocation = new Point(getXLocation(dropLocation.x, sourceBounds[0], zoom), getYLocation(dropLocation.y, sourceBounds[1], targetBounds[1], zoom));
        if (WorkflowEditor.getActiveEditorSnapToGrid()) {
            insertLocation = WorkflowEditor.getActiveEditorClosestGridLocation(insertLocation);
        }
        getViewer().getSelectionManager().deselectAll();
        if (nextNode != null && selectSuccessor(sourceBounds[0], targetBounds[0], sourceBounds[1], sourceBounds[1] + sourceBounds[3] + sourceAnnotationHeight, targetBounds[1], targetBounds[1] + targetBounds[3] + targetAnnotationHeight, zoom)) {
            selectNodes(nextNode, zoom);
        }
    }
    return insertLocation;
}
Also used : WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Example 3 with WorkflowInPortBarEditPart

use of org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart 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;
}
Also used : SingleNodeContainerUI(org.knime.core.ui.node.workflow.SingleNodeContainerUI) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowOutPortUI(org.knime.core.ui.node.workflow.WorkflowOutPortUI) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) NodeAnnotation(org.knime.core.node.workflow.NodeAnnotation) Annotation(org.knime.core.node.workflow.Annotation) NodeInPortUI(org.knime.core.ui.node.workflow.NodeInPortUI) ConnectionContainerUI(org.knime.core.ui.node.workflow.ConnectionContainerUI) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart) NodeOutPortUI(org.knime.core.ui.node.workflow.NodeOutPortUI) WorkflowOutPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart) SubworkflowEditPart(org.knime.workbench.editor2.editparts.SubworkflowEditPart) WorkflowInPortUI(org.knime.core.ui.node.workflow.WorkflowInPortUI) NodePortUI(org.knime.core.ui.node.workflow.NodePortUI)

Example 4 with WorkflowInPortBarEditPart

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

the class NodeOutputView method selectionChanged.

/**
 * The method updating the content of the monitor.
 *
 * {@inheritDoc}
 */
@Override
public void selectionChanged(final IWorkbenchPart part, final ISelection selection) {
    if (!(selection instanceof IStructuredSelection)) {
        // showErrorAndClear("");
        return;
    }
    IStructuredSelection structSel = (IStructuredSelection) selection;
    if (m_pinned) {
        m_lastSelectionWhilePinned = structSel;
        if (m_branchLocked && m_selectionWhenLocked == null) {
            m_selectionWhenLocked = structSel;
        }
        return;
    }
    if (structSel.equals(m_lastSelection)) {
        // selection hasn't changed - return.
        return;
    }
    m_lastSelection = structSel;
    if (structSel.size() < 1) {
        // Nothing selected
        showErrorAndClear("No node selected");
        return;
    }
    if (structSel.size() > 1) {
        // too many selected items
        showErrorAndClear("Multiple elements selected");
        return;
    }
    // retrieve first (and only!) selection:
    Iterator<?> selIt = structSel.iterator();
    Object sel = selIt.next();
    // 
    if (sel instanceof NodeContainerEditPart) {
        // a NodeContainer was selected, display it's name and status
        NodeContainer nc = Wrapper.unwrapNC(((NodeContainerEditPart) sel).getNodeContainer());
        WorkflowManager wfm = nc.getParent();
        checkWorkflowManagerListener(wfm);
        updateNodeContainerInfo(nc.getID());
    } else if (sel instanceof WorkflowInPortBarEditPart) {
        WorkflowManager wfm = Wrapper.unwrapWFM(((WorkflowInPortBarEditPart) sel).getNodeContainer());
        checkWorkflowManagerListener(wfm);
    } else {
        // unsupported selection
        showErrorAndClear("No info available for this selection");
        return;
    }
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) PortObject(org.knime.core.node.port.PortObject) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)

Example 5 with WorkflowInPortBarEditPart

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

the class PortGraphicalRoleEditPolicy method getConnectionCreateCommand.

/**
 * This tries to initialize the command to create a connection as far as
 * possible. However, it is completed by
 * <code>getConnectionCompleteCommand</code>
 *
 * {@inheritDoc}
 */
@Override
protected Command getConnectionCreateCommand(final CreateConnectionRequest req) {
    if (!(getHost() instanceof AbstractPortEditPart)) {
        return null;
    }
    ConnectableEditPart nodePart = (ConnectableEditPart) getHost().getParent();
    WorkflowManagerUI wm;
    // TODO: if NodeContainerEditPart -> getParent
    if (nodePart instanceof NodeContainerEditPart) {
        NodeContainerEditPart p = (NodeContainerEditPart) nodePart;
        wm = p.getWorkflowManager();
    } else if (nodePart instanceof WorkflowInPortBarEditPart) {
        WorkflowInPortBarEditPart barEditPart = (WorkflowInPortBarEditPart) nodePart;
        WorkflowPortBar model = (WorkflowPortBar) barEditPart.getModel();
        wm = model.getWorkflowManager();
    } else {
        return null;
    }
    CreateConnectionCommand cmd = new CreateConnectionCommand(Wrapper.unwrapWFM(wm));
    if (getHost() instanceof NodeOutPortEditPart || getHost() instanceof WorkflowInPortEditPart || getHost() instanceof MetaNodeOutPortEditPart) {
        // request started on out port?
        cmd.setSourceNode(nodePart);
        cmd.setSourcePortID(((AbstractPortEditPart) getHost()).getIndex());
        cmd.setStartedOnOutPort(true);
    } else if (getHost() instanceof NodeInPortEditPart || getHost() instanceof WorkflowOutPortEditPart) {
        return null;
    }
    // we need the manager to execute the command
    // we must remember this partially initialized command in the request.
    req.setStartCommand(cmd);
    return cmd;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowPortBar(org.knime.workbench.editor2.model.WorkflowPortBar) ConnectableEditPart(org.knime.workbench.editor2.editparts.ConnectableEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) NodeOutPortEditPart(org.knime.workbench.editor2.editparts.NodeOutPortEditPart) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) MetaNodeOutPortEditPart(org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart) WorkflowOutPortEditPart(org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart) WorkflowInPortEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortEditPart) WorkflowInPortBarEditPart(org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) NodeInPortEditPart(org.knime.workbench.editor2.editparts.NodeInPortEditPart)

Aggregations

NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)5 WorkflowInPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortBarEditPart)5 EditPart (org.eclipse.gef.EditPart)3 WorkflowManagerUI (org.knime.core.ui.node.workflow.WorkflowManagerUI)3 WorkflowInPortEditPart (org.knime.workbench.editor2.editparts.WorkflowInPortEditPart)3 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)2 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)2 SingleNodeContainerUI (org.knime.core.ui.node.workflow.SingleNodeContainerUI)2 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)2 MetaNodeOutPortEditPart (org.knime.workbench.editor2.editparts.MetaNodeOutPortEditPart)2 NodeInPortEditPart (org.knime.workbench.editor2.editparts.NodeInPortEditPart)2 NodeOutPortEditPart (org.knime.workbench.editor2.editparts.NodeOutPortEditPart)2 WorkflowOutPortBarEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortBarEditPart)2 WorkflowOutPortEditPart (org.knime.workbench.editor2.editparts.WorkflowOutPortEditPart)2 WorkflowRootEditPart (org.knime.workbench.editor2.editparts.WorkflowRootEditPart)2 WorkflowPortBar (org.knime.workbench.editor2.model.WorkflowPortBar)2 List (java.util.List)1 Point (org.eclipse.draw2d.geometry.Point)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1