Search in sources :

Example 1 with ReconnectRequest

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

the class NodePart method getSourceConnectionAnchor.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.NodeEditPart#getSourceConnectionAnchor(org.eclipse.gef.Request)
     */
@Override
public ConnectionAnchor getSourceConnectionAnchor(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();
    // // System.out.println("getSource=> location:" + connReq.getLocation() + " / source:" + source.getLocation() +
    // "
    // // / target:"
    // // + target.getLocation());
    sourceAnchor = new DummyNodeAnchor((NodeFigure) getFigure(), source, false);
    return sourceAnchor;
}
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 2 with ReconnectRequest

use of org.eclipse.gef.requests.ReconnectRequest 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 3 with ReconnectRequest

use of org.eclipse.gef.requests.ReconnectRequest 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 4 with ReconnectRequest

use of org.eclipse.gef.requests.ReconnectRequest in project yamcs-studio by yamcs.

the class WidgetConnectionEditPart method createEditPolicies.

@Override
protected void createEditPolicies() {
    if (getExecutionMode() == ExecutionMode.EDIT_MODE && !getWidgetModel().isLoadedFromLinkedOpi()) {
        // Selection handle edit policy.
        // Makes the connection show a feedback, when selected by the user.
        installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new ConnectionEndpointEditPolicy() {

            private ConnectionRouter originalRouter = null;

            private Object originalConstraint = null;

            @Override
            protected void showConnectionMoveFeedback(ReconnectRequest request) {
                EditPolicy connectionHandlesEditpolicy = getEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE);
                if (connectionHandlesEditpolicy != null && connectionHandlesEditpolicy instanceof ManhattanBendpointEditPolicy) {
                    ((ManhattanBendpointEditPolicy) connectionHandlesEditpolicy).removeSelectionHandles();
                }
                if (getConnection().getConnectionRouter() instanceof FixedPointsConnectionRouter) {
                    originalRouter = getConnection().getConnectionRouter();
                    originalConstraint = originalRouter.getConstraint(getConnection());
                    getConnection().setConnectionRouter(new ManhattanConnectionRouter());
                }
                super.showConnectionMoveFeedback(request);
            }

            @Override
            protected void eraseConnectionMoveFeedback(ReconnectRequest request) {
                if (originalRouter != null) {
                    originalRouter.setConstraint(getConnection(), originalConstraint);
                    getConnection().setConnectionRouter(originalRouter);
                }
                super.eraseConnectionMoveFeedback(request);
            }
        });
        // Allows the removal of the connection model element
        installEditPolicy(EditPolicy.CONNECTION_ROLE, new ConnectionEditPolicy() {

            @Override
            protected Command getDeleteCommand(GroupRequest request) {
                return new ConnectionDeleteCommand(getWidgetModel());
            }
        });
    }
}
Also used : ConnectionEndpointEditPolicy(org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy) ReconnectRequest(org.eclipse.gef.requests.ReconnectRequest) ManhattanBendpointEditPolicy(org.csstudio.opibuilder.editpolicies.ManhattanBendpointEditPolicy) ConnectionEditPolicy(org.eclipse.gef.editpolicies.ConnectionEditPolicy) ConnectionDeleteCommand(org.csstudio.opibuilder.commands.ConnectionDeleteCommand) ConnectionDeleteCommand(org.csstudio.opibuilder.commands.ConnectionDeleteCommand) Command(org.eclipse.gef.commands.Command) GroupRequest(org.eclipse.gef.requests.GroupRequest) ManhattanConnectionRouter(org.eclipse.draw2d.ManhattanConnectionRouter) ConnectionEditPolicy(org.eclipse.gef.editpolicies.ConnectionEditPolicy) ConnectionEndpointEditPolicy(org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy) EditPolicy(org.eclipse.gef.EditPolicy) ManhattanBendpointEditPolicy(org.csstudio.opibuilder.editpolicies.ManhattanBendpointEditPolicy) ManhattanConnectionRouter(org.eclipse.draw2d.ManhattanConnectionRouter) ConnectionRouter(org.eclipse.draw2d.ConnectionRouter)

Aggregations

ReconnectRequest (org.eclipse.gef.requests.ReconnectRequest)4 CreateConnectionRequest (org.eclipse.gef.requests.CreateConnectionRequest)3 ChopboxAnchor (org.eclipse.draw2d.ChopboxAnchor)2 IFigure (org.eclipse.draw2d.IFigure)2 IExternalNode (org.talend.core.model.process.IExternalNode)2 INode (org.talend.core.model.process.INode)2 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)2 ConnectionFigure (org.talend.designer.core.ui.editor.connections.ConnectionFigure)2 TalendBorderItemRectilinearRouter (org.talend.designer.core.ui.editor.connections.TalendBorderItemRectilinearRouter)2 ConnectionDeleteCommand (org.csstudio.opibuilder.commands.ConnectionDeleteCommand)1 ManhattanBendpointEditPolicy (org.csstudio.opibuilder.editpolicies.ManhattanBendpointEditPolicy)1 ConnectionRouter (org.eclipse.draw2d.ConnectionRouter)1 ManhattanConnectionRouter (org.eclipse.draw2d.ManhattanConnectionRouter)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Point (org.eclipse.draw2d.geometry.Point)1 PointList (org.eclipse.draw2d.geometry.PointList)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 EditPolicy (org.eclipse.gef.EditPolicy)1 Command (org.eclipse.gef.commands.Command)1 ConnectionEditPolicy (org.eclipse.gef.editpolicies.ConnectionEditPolicy)1