Search in sources :

Example 6 with CreateConnectionRequest

use of org.eclipse.gef.requests.CreateConnectionRequest in project archi by archimatetool.

the class ConnectionCreationTool method handleKeyDown.

/**
 * Processes the arrow keys (to move the cursor to nearby anchor locations)
 * and the enter key (to start or complete a connections).
 *
 * @param event
 *            the key event
 * @return <code>true</code> if this key down event was processed
 */
@Override
protected boolean handleKeyDown(KeyEvent event) {
    if (acceptArrowKey(event)) {
        int direction = 0;
        switch(event.keyCode) {
            case SWT.ARROW_DOWN:
                direction = PositionConstants.SOUTH;
                break;
            case SWT.ARROW_UP:
                direction = PositionConstants.NORTH;
                break;
            case SWT.ARROW_RIGHT:
                direction = isCurrentViewerMirrored() ? PositionConstants.WEST : PositionConstants.EAST;
                break;
            case SWT.ARROW_LEFT:
                direction = isCurrentViewerMirrored() ? PositionConstants.EAST : PositionConstants.WEST;
                break;
        }
        boolean consumed = false;
        if (direction != 0 && event.stateMask == 0)
            consumed = navigateNextAnchor(direction);
        if (!consumed) {
            event.stateMask |= SWT.CONTROL;
            event.stateMask &= ~SWT.SHIFT;
            if (getCurrentViewer().getKeyHandler().keyPressed(event)) {
                navigateNextAnchor(0);
                updateTargetRequest();
                updateTargetUnderMouse();
                Command command = getCommand();
                if (command != null)
                    setCurrentCommand(command);
                return true;
            }
        }
    }
    if (event.character == '/' || event.character == '\\') {
        event.stateMask |= SWT.CONTROL;
        if (getCurrentViewer().getKeyHandler().keyPressed(event)) {
            navigateNextAnchor(0);
            return true;
        }
    }
    if (acceptConnectionStart(event)) {
        Command command = getCommand();
        if (command != null && command.canExecute()) {
            updateTargetUnderMouse();
            setConnectionSource(getTargetEditPart());
            ((CreateConnectionRequest) getTargetRequest()).setSourceEditPart(getTargetEditPart());
            setState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS);
            placeMouseInViewer(getLocation().getTranslated(6, 6));
        }
        return true;
    }
    if (acceptConnectionFinish(event)) {
        Command command = getCommand();
        if (command != null && command.canExecute()) {
            setState(STATE_INITIAL);
            placeMouseInViewer(getLocation().getTranslated(6, 6));
            eraseSourceFeedback();
            eraseTargetFeedback();
            setCurrentCommand(command);
            executeCurrentCommand();
        }
        return true;
    }
    return super.handleKeyDown(event);
}
Also used : Command(org.eclipse.gef.commands.Command) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) Point(org.eclipse.draw2d.geometry.Point)

Example 7 with CreateConnectionRequest

use of org.eclipse.gef.requests.CreateConnectionRequest in project tdi-studio-se by Talend.

the class TalendBorderItemRectilinearRouter method manualHorizontalScrolBarCase.

private boolean manualHorizontalScrolBarCase(Connection conn) {
    PointList points = conn.getPoints();
    Point start = getStartPoint(conn);
    Point end = getEndPoint(conn);
    boolean handle = false;
    boolean processHandle = false;
    if ((request != null) && (request instanceof CreateConnectionRequest)) {
        start = conn.getSourceAnchor().getReferencePoint();
        CreateConnectionRequest createRequest = (CreateConnectionRequest) request;
        if (createRequest.getTargetEditPart() != null && createRequest.getTargetEditPart() != createRequest.getSourceEditPart() && createRequest.getTargetEditPart().getModel() instanceof Node) {
            PointList pointList = new PointList();
            conn.translateToRelative(start);
            pointList.addPoint(start);
            Point targetPoint = conn.getTargetAnchor().getReferencePoint();
            conn.translateToRelative(targetPoint);
            pointList.addPoint(targetPoint);
            conn.setPoints(pointList);
            handle = true;
        } else if (createRequest.getTargetEditPart() != null && createRequest.getTargetEditPart() != createRequest.getSourceEditPart() && createRequest.getTargetEditPart() instanceof ProcessPart) {
            processHandle = true;
        }
    }
    if (conn instanceof ConnectionFigure) {
        IConnection connection = ((ConnectionFigure) conn).getConnection();
        EConnectionType lineStyle = connection.getLineStyle();
        EConnectionCategory category = lineStyle.getCategory();
        if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.ON_COMPONENT_ERROR || lineStyle == EConnectionType.ON_COMPONENT_OK || lineStyle == EConnectionType.ON_SUBJOB_ERROR || lineStyle == EConnectionType.ON_SUBJOB_OK || lineStyle == EConnectionType.RUN_IF)) {
            return handle || processHandle;
        }
    }
    if (!handle) {
        conn.translateToRelative(start);
        points.setPoint(start, 0);
        conn.translateToRelative(end);
        points.setPoint(end, points.size() - 1);
        conn.setPoints(points);
    }
    return handle || processHandle;
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) Node(org.talend.designer.core.ui.editor.nodes.Node) IConnection(org.talend.core.model.process.IConnection) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) Point(org.eclipse.draw2d.geometry.Point) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 8 with CreateConnectionRequest

use of org.eclipse.gef.requests.CreateConnectionRequest in project tdi-studio-se by Talend.

the class TalendBorderItemRectilinearRouter method manualPosition.

private boolean manualPosition(Connection conn, boolean horizontalHandle) {
    boolean isCreation = false;
    boolean isReconnect = false;
    boolean alreadyHandle = false;
    if (!(conn instanceof PolylineConnectionEx)) {
        return false;
    }
    if (this.request != null) {
        if (request instanceof CreateConnectionRequest) {
            isCreation = true;
        } else if (request instanceof ReconnectRequest) {
            isReconnect = true;
        }
    }
    IConnection connection = null;
    EConnectionCategory category = null;
    EConnectionType lineStyle = null;
    Rectangle sourceBounds = null;
    Rectangle targetBounds = null;
    if (conn instanceof ConnectionFigure) {
        connection = ((ConnectionFigure) conn).getConnection();
        if (!(connection.getSource() instanceof Node)) {
            return false;
        }
        lineStyle = connection.getLineStyle();
        category = lineStyle.getCategory();
        sourceBounds = new Rectangle(((Node) connection.getSource()).getLocation(), ((Node) connection.getSource()).getSize());
        targetBounds = new Rectangle(((Node) connection.getTarget()).getLocation(), ((Node) connection.getTarget()).getSize());
    }
    if (lineStyle == null) {
        lineStyle = ConnectionManager.getNewConnectionType();
        category = lineStyle.getCategory();
    }
    if (isCreation) {
        if (((CreateConnectionRequest) request).getSourceEditPart() == null) {
            return false;
        }
        if ((((CreateConnectionRequest) request).getTargetEditPart() == null) || horizontalHandle) {
            if (conn.getPoints().size() <= 2) {
                makeUpConnection(conn);
            }
            return false;
        }
    }
    if ((sourceBounds == null) && isCreation) {
        Node source = (Node) ((CreateConnectionRequest) request).getSourceEditPart().getModel();
        if (source != null) {
            sourceBounds = new Rectangle(source.getLocation(), source.getSize());
        }
    }
    if ((targetBounds == null) && isCreation) {
        Object obj = ((CreateConnectionRequest) request).getTargetEditPart().getModel();
        if (obj instanceof Node) {
            Node target = (Node) obj;
            if (target != null) {
                targetBounds = new Rectangle(target.getLocation(), target.getSize());
            }
        } else {
            Point lastPoint = conn.getPoints().getLastPoint();
            targetBounds = new Rectangle(lastPoint, new Dimension(2 * OFFSET, 2 * OFFSET));
        }
    }
    if (isReconnect) {
        if (((ReconnectRequest) request).getTarget() != null) {
            Object obj = ((ReconnectRequest) request).getTarget().getModel();
            if (obj instanceof Node) {
                Node target = (Node) obj;
                if (target != null) {
                    targetBounds = new Rectangle(target.getLocation(), target.getSize());
                }
            }
        } else {
            Point lastPoint = conn.getPoints().getLastPoint();
            targetBounds = new Rectangle(lastPoint, new Dimension(2 * OFFSET, 2 * OFFSET));
        }
    }
    if (targetBounds == null) {
        return false;
    }
    ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(32);
    PointList points = conn.getPoints();
    PointList pointList = new PointList();
    Point firstpoint = points.getFirstPoint();
    Point lastpoint = points.getLastPoint();
    if (category == EConnectionCategory.MAIN && lineStyle != EConnectionType.FLOW_REF) {
        if ((sourceBounds.x > targetBounds.x) && (sourceBounds.y == targetBounds.y)) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y + 2 * OFFSET);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y + 2 * OFFSET);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if ((sourceBounds.x > targetBounds.x) || (sourceBounds.getTopRight().x == targetBounds.getTopLeft().x) || ((sourceBounds.getTopLeft().x == targetBounds.getTopRight().x) && (sourceBounds.getTopLeft().y != targetBounds.getTopRight().y))) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (sourceBounds.x == targetBounds.x) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x + 2 * OFFSET, firstpoint.y);
            pointList.addPoint(firstpoint.x + 2 * OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - 2 * OFFSET, (sourceBounds.getCenter().y + targetBounds.getCenter().y) / 2);
            pointList.addPoint(lastpoint.x - 2 * OFFSET, lastpoint.y);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (Math.abs(sourceBounds.getCenter().y - targetBounds.getCenter().y) == 4 * OFFSET) {
            if ((firstpoint.x + lastpoint.x) / 2 - OFFSET <= firstpoint.x) {
                return false;
            }
            ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(16);
        }
    } else if (category == EConnectionCategory.OTHER && (lineStyle == EConnectionType.FLOW_REF || lineStyle == EConnectionType.TABLE_REF)) {
        if (targetBounds.y == sourceBounds.y) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if ((targetBounds.getTopRight().y == sourceBounds.getBottomLeft().y)) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y - OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y - OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (targetBounds.getBottomLeft().y == sourceBounds.getTopRight().y) {
            pointList.addPoint(firstpoint);
            pointList.addPoint(firstpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint.x, firstpoint.y + OFFSET);
            pointList.addPoint(lastpoint);
            alreadyHandle = true;
        } else if (Math.abs(sourceBounds.x - targetBounds.x) == 4 * OFFSET) {
            ((PolylineConnectionEx) conn).setRoundedBendpointsRadius(16);
        }
    }
    if (alreadyHandle && pointList.size() > 0) {
        conn.setPoints(pointList);
    }
    return alreadyHandle;
}
Also used : ReconnectRequest(org.eclipse.gef.requests.ReconnectRequest) PointList(org.eclipse.draw2d.geometry.PointList) Node(org.talend.designer.core.ui.editor.nodes.Node) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IConnection(org.talend.core.model.process.IConnection) EConnectionCategory(org.talend.core.model.process.EConnectionCategory) PolylineConnectionEx(org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 9 with CreateConnectionRequest

use of org.eclipse.gef.requests.CreateConnectionRequest in project tdi-studio-se by Talend.

the class NodePart method getTargetConnectionAnchor.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.NodeEditPart#getTargetConnectionAnchor(org.eclipse.gef.Request)
     */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
    if (!DesignerPlugin.getDefault().getPreferenceStore().getBoolean(TalendDesignerPrefConstants.EDITOR_LINESTYLE)) {
        return new ChopboxAnchor(getFigure());
    }
    if (!(request instanceof CreateConnectionRequest)) {
        if (request instanceof ReconnectRequest) {
            IFigure figure = ((ReconnectRequest) request).getConnectionEditPart().getFigure();
            if (figure instanceof ConnectionFigure) {
                ((ConnectionFigure) figure).setConnectionRouter(new TalendBorderItemRectilinearRouter(request));
            }
        }
        return new ChopboxAnchor(getFigure());
    }
    CreateConnectionRequest connReq = (CreateConnectionRequest) request;
    Node source = (Node) ((NodePart) connReq.getSourceEditPart()).getModel();
    Node target = (Node) ((NodePart) connReq.getTargetEditPart()).getModel();
    // // + target.getLocation());
    if (sourceAnchor != null) {
        sourceAnchor.setTarget(target);
    }
    return new DummyNodeAnchor((NodeFigure) getFigure(), source, target, true);
}
Also used : ReconnectRequest(org.eclipse.gef.requests.ReconnectRequest) ChopboxAnchor(org.eclipse.draw2d.ChopboxAnchor) TalendBorderItemRectilinearRouter(org.talend.designer.core.ui.editor.connections.TalendBorderItemRectilinearRouter) ConnectionFigure(org.talend.designer.core.ui.editor.connections.ConnectionFigure) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) IFigure(org.eclipse.draw2d.IFigure)

Example 10 with CreateConnectionRequest

use of org.eclipse.gef.requests.CreateConnectionRequest in project knime-core by knime.

the class NodeContainerEditPart method getTargetConnectionAnchor.

/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
    if (!(request instanceof CreateConnectionRequest)) {
        return null;
    }
    CreateConnectionRequest req = (CreateConnectionRequest) request;
    Command cmd = req.getStartCommand();
    if (!(cmd instanceof CreateConnectionCommand)) {
        return null;
    }
    CreateConnectionCommand connCmd = (CreateConnectionCommand) cmd;
    // find a free port that could take the connection
    int portIdx = getFreeInPort(connCmd.getSourceNode(), connCmd.getSourcePortID());
    if (portIdx < 0) {
        return null;
    }
    for (Object part : getChildren()) {
        if (part instanceof AbstractPortEditPart) {
            AbstractPortEditPart port = (AbstractPortEditPart) part;
            if (port.isInPort() && port.getIndex() == portIdx) {
                return port.getTargetConnectionAnchor(request);
            }
        }
    }
    return null;
}
Also used : CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Command(org.eclipse.gef.commands.Command) ShiftConnectionCommand(org.knime.workbench.editor2.commands.ShiftConnectionCommand) CreateConnectionRequest(org.eclipse.gef.requests.CreateConnectionRequest) CreateConnectionCommand(org.knime.workbench.editor2.commands.CreateConnectionCommand) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)16 Command (org.eclipse.gef.commands.Command)8 ArchimateDiagramModelFactory (com.archimatetool.editor.diagram.ArchimateDiagramModelFactory)5 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)5 CreateDiagramConnectionCommand (com.archimatetool.editor.diagram.commands.CreateDiagramConnectionCommand)4 Point (org.eclipse.draw2d.geometry.Point)4 Test (org.junit.Test)4 EditPart (org.eclipse.gef.EditPart)3 ReconnectRequest (org.eclipse.gef.requests.ReconnectRequest)3 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)2 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)2 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)2 ChopboxAnchor (org.eclipse.draw2d.ChopboxAnchor)2 IFigure (org.eclipse.draw2d.IFigure)2 PointList (org.eclipse.draw2d.geometry.PointList)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 EConnectionCategory (org.talend.core.model.process.EConnectionCategory)2 EConnectionType (org.talend.core.model.process.EConnectionType)2 IConnection (org.talend.core.model.process.IConnection)2 IExternalNode (org.talend.core.model.process.IExternalNode)2