Search in sources :

Example 51 with NodeContainerEditPart

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

the class WorkflowEditor method addNode.

/**
 * Listener interface method of the {@link NodeProvider}. Called when other
 * instances want to add a node to the workflow in the editor. <br>
 * The implementation only adds it if the editor is active and one node is
 * selected in the editor, to which the new node will then be connected to.
 * {@inheritDoc}
 */
@Override
public boolean addNode(final NodeFactory<? extends NodeModel> nodeFactory) {
    if (!isEditorActive()) {
        return false;
    }
    if (!getWorkflowManager().isPresent()) {
        return false;
    }
    NodeContainerEditPart preNode = getTheOneSelectedNode();
    Point nodeLoc = null;
    Command newNodeCmd = null;
    if (preNode == null) {
        nodeLoc = getViewportCenterLocation();
        // this command accepts/requires relative coordinates
        newNodeCmd = new CreateNodeCommand(unwrapWFM(m_manager), nodeFactory, nodeLoc, getEditorSnapToGrid());
    } else {
        nodeLoc = getLocationRightOf(preNode);
        newNodeCmd = new CreateNewConnectedNodeCommand(getViewer(), unwrapWFM(m_manager), nodeFactory, nodeLoc, preNode.getNodeContainer().getID());
    }
    getCommandStack().execute(newNodeCmd);
    // after adding a node the editor should get the focus
    // this is issued asynchronously, in order to avoid bug #3029
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            setFocus();
        }
    });
    return true;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) CreateNewConnectedNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedNodeCommand) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand) Command(org.eclipse.gef.commands.Command) CreateNewConnectedMetaNodeCommand(org.knime.workbench.editor2.commands.CreateNewConnectedMetaNodeCommand) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) CreateNodeCommand(org.knime.workbench.editor2.commands.CreateNodeCommand)

Example 52 with NodeContainerEditPart

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

the class WorkflowEditor method isNodeAtRel.

private boolean isNodeAtRel(final Point relativeLoc) {
    EditPart ep = getViewer().findObjectAt(relativeLoc);
    if (ep == null) {
        return false;
    }
    while (!(ep instanceof RootEditPart)) {
        if (ep instanceof NodeContainerEditPart) {
            return true;
        }
        EditPart parent = ep.getParent();
        // avoid endless loops
        if (parent == null || parent.equals(ep)) {
            return false;
        }
        ep = parent;
    }
    return false;
}
Also used : NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) EditPart(org.eclipse.gef.EditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) RootEditPart(org.eclipse.gef.RootEditPart) ScalableFreeformRootEditPart(org.eclipse.gef.editparts.ScalableFreeformRootEditPart)

Example 53 with NodeContainerEditPart

use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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 54 with NodeContainerEditPart

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

the class WorkflowEditorDropTargetListener method selectNodes.

/**
 * Selects all nodes after this node which are around the same y coordinate and closer than
 * {@link WorkflowEditorDropTargetListener#m_distanceToMoveTarget} +
 * {@link WorkflowEditorDropTargetListener#MINIMUM_NODE_DISTANCE}
 *
 * All selected elements will be moved by the move action.
 *
 * @param node from which on the selection starts
 */
private void selectNodes(final NodeContainerEditPart node, final double zoom) {
    getViewer().getSelectionManager().appendSelection(node);
    for (ConnectionContainerEditPart c : node.getOutgoingConnections()) {
        EditPart source = c.getSource().getParent();
        EditPart target = c.getTarget().getParent();
        if (source instanceof NodeContainerEditPart && target instanceof NodeContainerEditPart) {
            NodeContainerEditPart sourceNode = (NodeContainerEditPart) source;
            NodeContainerEditPart targetNode = (NodeContainerEditPart) target;
            int[] sourceBounds = sourceNode.getNodeContainer().getUIInformation().getBounds();
            int[] targetBounds = targetNode.getNodeContainer().getUIInformation().getBounds();
            sourceBounds = recomputeBounds(sourceBounds);
            targetBounds = recomputeBounds(targetBounds);
            int sourceYTop = sourceBounds[1];
            int sourceYBot = sourceYTop + sourceBounds[3] + sourceNode.getNodeAnnotationEditPart().getModel().getHeight();
            int targetYTop = targetBounds[1];
            int targetYBot = targetYTop + targetBounds[3] + targetNode.getNodeAnnotationEditPart().getModel().getHeight();
            if (selectSuccessor(sourceBounds[0], targetBounds[0], sourceYTop, sourceYBot, targetYTop, targetYBot, zoom)) {
                selectNodes(targetNode, zoom);
            }
        }
    }
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) 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) Point(org.eclipse.draw2d.geometry.Point)

Example 55 with NodeContainerEditPart

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

the class WorkflowSelectionDragEditPartsTracker method getEmbracedConnections.

/**
 * Returns the connections whose source and target is contained in the argument list.
 * @param parts list of selected nodes
 * @return the connections whose source and target is contained in the argument list.
 */
public static ConnectionContainerEditPart[] getEmbracedConnections(final List<EditPart> parts) {
    // result list
    List<ConnectionContainerEditPart> result = new ArrayList<ConnectionContainerEditPart>();
    for (EditPart part : parts) {
        if (part instanceof NodeContainerEditPart || part instanceof AbstractWorkflowPortBarEditPart) {
            EditPart containerPart = part;
            ConnectionContainerEditPart[] outPortConnectionParts = getOutportConnections(containerPart);
            // selected list, the connections bendpoints must be adapted
            for (ConnectionContainerEditPart connectionPart : outPortConnectionParts) {
                // get the in-port-node part of the connection and check
                AbstractPortEditPart inPortPart = null;
                if (connectionPart.getTarget() != null && ((AbstractPortEditPart) connectionPart.getTarget()).isInPort()) {
                    inPortPart = (AbstractPortEditPart) connectionPart.getTarget();
                } else if (connectionPart.getSource() != null) {
                    inPortPart = (AbstractPortEditPart) connectionPart.getSource();
                }
                if (inPortPart != null && isPartInList(inPortPart.getParent(), parts)) {
                    result.add(connectionPart);
                }
            }
        }
    }
    return result.toArray(new ConnectionContainerEditPart[result.size()]);
}
Also used : ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) ArrayList(java.util.ArrayList) AbstractPortEditPart(org.knime.workbench.editor2.editparts.AbstractPortEditPart) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) ConnectionContainerEditPart(org.knime.workbench.editor2.editparts.ConnectionContainerEditPart) EditPart(org.eclipse.gef.EditPart)

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