Java Code Examples for org.eclipse.gef.requests.ReconnectRequest#getLocation()

The following examples show how to use org.eclipse.gef.requests.ReconnectRequest#getLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectSourceCommand(final ReconnectRequest reconnectrequest) {
    final ConnectionElement connection = (ConnectionElement) reconnectrequest.getConnectionEditPart().getModel();

    if (connection.getSource() == connection.getTarget()) {
        return null;
    }

    final NodeElement newSource = (NodeElement) reconnectrequest.getTarget().getModel();
    if (connection.getSource() != newSource) {
        return null;
    }

    final NodeElementEditPart sourceEditPart = (NodeElementEditPart) reconnectrequest.getConnectionEditPart().getSource();

    final Point location = new Point(reconnectrequest.getLocation());

    final IFigure sourceFigure = sourceEditPart.getFigure();
    sourceFigure.translateToRelative(location);

    int xp = -1;
    int yp = -1;

    final Rectangle bounds = sourceFigure.getBounds();

    final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

    if (!centerRectangle.contains(location)) {
        final Point point = NodeElementEditPart.getIntersectionPoint(location, sourceFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }

    final ReconnectSourceCommand command = new ReconnectSourceCommand(connection, xp, yp);

    return command;
}
 
Example 2
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectTargetCommand(final ReconnectRequest reconnectrequest) {
    final ConnectionElement connection = (ConnectionElement) reconnectrequest.getConnectionEditPart().getModel();

    if (connection.getSource() == connection.getTarget()) {
        return null;
    }

    final NodeElement newTarget = (NodeElement) reconnectrequest.getTarget().getModel();
    if (connection.getTarget() != newTarget) {
        return null;
    }

    final NodeElementEditPart targetEditPart = (NodeElementEditPart) reconnectrequest.getConnectionEditPart().getTarget();

    final Point location = new Point(reconnectrequest.getLocation());

    final IFigure targetFigure = targetEditPart.getFigure();
    targetFigure.translateToRelative(location);

    int xp = -1;
    int yp = -1;

    final Rectangle bounds = targetFigure.getBounds();

    final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

    if (!centerRectangle.contains(location)) {
        final Point point = NodeElementEditPart.getIntersectionPoint(location, targetFigure);

        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectTargetCommand command = new ReconnectTargetCommand(connection, xp, yp);

    return command;
}
 
Example 3
Source File: DiagramWalkerGraphicalNodeEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected Command getReconnectSourceCommand(ReconnectRequest reconnectrequest) {
    final WalkerConnection connection = (WalkerConnection) reconnectrequest.getConnectionEditPart().getModel();
    if (!(connection instanceof Relationship)) {
        return null;
    }
    final Relationship relation = (Relationship) connection;
    if (relation.getSourceWalker() == relation.getTargetWalker()) {
        return null;
    }
    final DiagramWalker newSource = ((DiagramWalker) reconnectrequest.getTarget().getModel()).toMaterialize();
    if (!relation.getSourceWalker().equals(newSource)) {
        return null;
    }
    final DiagramWalkerEditPart sourceEditPart = (DiagramWalkerEditPart) reconnectrequest.getConnectionEditPart().getSource();
    final Point location = new Point(reconnectrequest.getLocation());
    final IFigure sourceFigure = sourceEditPart.getFigure();
    sourceFigure.translateToRelative(location);
    int xp = -1;
    int yp = -1;
    final Rectangle bounds = sourceFigure.getBounds();
    final Rectangle centerRectangle =
            new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
    if (!centerRectangle.contains(location)) {
        final Point point = ERTableEditPart.getIntersectionPoint(location, sourceFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectSourceCommand command = new ReconnectSourceCommand(relation, xp, yp);
    return command;
}
 
Example 4
Source File: DiagramWalkerGraphicalNodeEditPolicy.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
protected Command getReconnectTargetCommand(ReconnectRequest reconnectrequest) {
    final WalkerConnection connection = (WalkerConnection) reconnectrequest.getConnectionEditPart().getModel();
    if (!(connection instanceof Relationship)) {
        return null;
    }
    final Relationship relation = (Relationship) connection;
    if (relation.getSourceWalker() == relation.getTargetWalker()) {
        return null;
    }
    final DiagramWalker newTarget = ((DiagramWalker) reconnectrequest.getTarget().getModel()).toMaterialize();
    if (!relation.getTargetWalker().equals(newTarget)) {
        return null;
    }
    final DiagramWalkerEditPart targetEditPart = (DiagramWalkerEditPart) reconnectrequest.getConnectionEditPart().getTarget();
    final Point location = new Point(reconnectrequest.getLocation());
    final IFigure targetFigure = targetEditPart.getFigure();
    targetFigure.translateToRelative(location);
    int xp = -1;
    int yp = -1;
    final Rectangle bounds = targetFigure.getBounds();
    final Rectangle centerRectangle =
            new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
    if (!centerRectangle.contains(location)) {
        final Point point = ERTableEditPart.getIntersectionPoint(location, targetFigure);
        xp = 100 * (point.x - bounds.x) / bounds.width;
        yp = 100 * (point.y - bounds.y) / bounds.height;
    }
    final ReconnectTargetCommand command = new ReconnectTargetCommand(relation, xp, yp);
    return command;
}
 
Example 5
Source File: NodeElementEditPart.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getSourceConnectionAnchor(final Request request) {
    if (request instanceof ReconnectRequest) {
        final ReconnectRequest reconnectRequest = (ReconnectRequest) request;

        final ConnectionEditPart connectionEditPart = reconnectRequest.getConnectionEditPart();

        // if (!(connectionEditPart instanceof RelationEditPart)) {
        // return super.getSourceConnectionAnchor(request);
        // }

        final ConnectionElement connection = (ConnectionElement) connectionEditPart.getModel();
        if (connection.getSource() == connection.getTarget()) {
            return new XYChopboxAnchor(getFigure());
        }

        final EditPart editPart = reconnectRequest.getTarget();

        if (editPart == null || !editPart.getModel().equals(connection.getSource())) {
            return new XYChopboxAnchor(getFigure());
        }

        final Point location = new Point(reconnectRequest.getLocation());
        getFigure().translateToRelative(location);
        final IFigure sourceFigure = ((TableViewEditPart) connectionEditPart.getSource()).getFigure();

        final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());

        final Rectangle bounds = sourceFigure.getBounds();

        final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

        if (!centerRectangle.contains(location)) {
            final Point point = getIntersectionPoint(location, sourceFigure);
            anchor.setLocation(point);
        }

        return anchor;

    } else if (request instanceof CreateConnectionRequest) {
        final CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;

        final Command command = connectionRequest.getStartCommand();

        if (command instanceof CreateCommentConnectionCommand) {
            return new ChopboxAnchor(getFigure());
        }
    }

    return new XYChopboxAnchor(getFigure());
}
 
Example 6
Source File: NodeElementEditPart.java    From ermasterr with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final Request request) {
    if (request instanceof ReconnectRequest) {
        final ReconnectRequest reconnectRequest = (ReconnectRequest) request;

        final ConnectionEditPart connectionEditPart = reconnectRequest.getConnectionEditPart();

        // if (!(connectionEditPart instanceof RelationEditPart)) {
        // return super.getTargetConnectionAnchor(request);
        // }

        final ConnectionElement connection = (ConnectionElement) connectionEditPart.getModel();
        if (connection.getSource() == connection.getTarget()) {
            return new XYChopboxAnchor(getFigure());
        }

        final EditPart editPart = reconnectRequest.getTarget();

        if (editPart == null || !editPart.getModel().equals(connection.getTarget())) {
            return new XYChopboxAnchor(getFigure());
        }

        final Point location = new Point(reconnectRequest.getLocation());
        getFigure().translateToRelative(location);
        final IFigure targetFigure = ((AbstractModelEditPart) connectionEditPart.getTarget()).getFigure();

        final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());

        final Rectangle bounds = targetFigure.getBounds();

        final Rectangle centerRectangle = new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

        if (!centerRectangle.contains(location)) {
            final Point point = getIntersectionPoint(location, targetFigure);
            anchor.setLocation(point);
        }

        return anchor;

    } else if (request instanceof CreateConnectionRequest) {
        final CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;

        final Command command = connectionRequest.getStartCommand();

        if (command instanceof CreateCommentConnectionCommand) {
            return new ChopboxAnchor(getFigure());
        }
    }

    return new XYChopboxAnchor(getFigure());
}
 
Example 7
Source File: TableViewEditPart.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
    if (request instanceof ReconnectRequest) {
        final ReconnectRequest reconnectRequest = (ReconnectRequest) request;
        final ConnectionEditPart connectionEditPart = reconnectRequest.getConnectionEditPart();
        if (!(connectionEditPart instanceof RelationEditPart)) {
            return super.getSourceConnectionAnchor(request);
        }

        final Relationship relation = (Relationship) connectionEditPart.getModel();
        if (relation.getSourceWalker() == relation.getTargetWalker()) {
            return new XYChopboxAnchor(getFigure());
        }

        final EditPart editPart = reconnectRequest.getTarget();
        if (editPart == null || !editPart.getModel().equals(relation.getSourceWalker())) {
            return new XYChopboxAnchor(getFigure());
        }

        final Point location = new Point(reconnectRequest.getLocation());
        getFigure().translateToRelative(location);

        final IFigure sourceFigure = ((TableViewEditPart) connectionEditPart.getSource()).getFigure();
        final Rectangle bounds = sourceFigure.getBounds();
        final Rectangle centerRectangle =
                new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);

        final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());
        if (!centerRectangle.contains(location)) {
            final Point point = getIntersectionPoint(location, sourceFigure);
            anchor.setLocation(point);
        }

        return anchor;
    } else if (request instanceof CreateConnectionRequest) {
        final CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;
        final Command command = connectionRequest.getStartCommand();
        if (command instanceof CreateCommentConnectionCommand) {
            return super.getTargetConnectionAnchor(request);
        }
    }

    return new XYChopboxAnchor(getFigure());
}
 
Example 8
Source File: TableViewEditPart.java    From erflute with Apache License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
    if (request instanceof ReconnectRequest) {
        final ReconnectRequest reconnectRequest = (ReconnectRequest) request;
        final ConnectionEditPart connectionEditPart = reconnectRequest.getConnectionEditPart();
        if (!(connectionEditPart instanceof RelationEditPart)) {
            return super.getTargetConnectionAnchor(request);
        }

        final Relationship relation = (Relationship) connectionEditPart.getModel();
        if (relation.getSourceWalker() == relation.getTargetWalker()) {
            return new XYChopboxAnchor(getFigure());
        }

        final EditPart editPart = reconnectRequest.getTarget();
        if (editPart == null || !editPart.getModel().equals(relation.getTargetWalker())) {
            return new XYChopboxAnchor(getFigure());
        }

        final Point location = new Point(reconnectRequest.getLocation());
        getFigure().translateToRelative(location);

        final IFigure targetFigure = ((TableViewEditPart) connectionEditPart.getTarget()).getFigure();
        final Rectangle bounds = targetFigure.getBounds();
        final Rectangle centerRectangle =
                new Rectangle(bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4), bounds.width / 2, bounds.height / 2);
        final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());
        if (!centerRectangle.contains(location)) {
            final Point point = getIntersectionPoint(location, targetFigure);
            anchor.setLocation(point);
        }

        return anchor;
    } else if (request instanceof CreateConnectionRequest) {
        final CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;
        final Command command = connectionRequest.getStartCommand();
        if (command instanceof CreateCommentConnectionCommand) {
            return super.getTargetConnectionAnchor(request);
        }
    }

    return new XYChopboxAnchor(getFigure());
}
 
Example 9
Source File: TableViewEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request request) {
	if (request instanceof ReconnectRequest) {
		ReconnectRequest reconnectRequest = (ReconnectRequest) request;

		ConnectionEditPart connectionEditPart = reconnectRequest
				.getConnectionEditPart();

		if (!(connectionEditPart instanceof RelationEditPart)) {
			return super.getSourceConnectionAnchor(request);
		}

		Relation relation = (Relation) connectionEditPart.getModel();
		if (relation.getSource() == relation.getTarget()) {
			return new XYChopboxAnchor(this.getFigure());
		}

		EditPart editPart = reconnectRequest.getTarget();

		if (editPart == null
				|| !editPart.getModel().equals(relation.getSource())) {
			return new XYChopboxAnchor(this.getFigure());
		}

		Point location = new Point(reconnectRequest.getLocation());
		this.getFigure().translateToRelative(location);
		IFigure sourceFigure = ((TableViewEditPart) connectionEditPart
				.getSource()).getFigure();

		XYChopboxAnchor anchor = new XYChopboxAnchor(this.getFigure());

		Rectangle bounds = sourceFigure.getBounds();

		Rectangle centerRectangle = new Rectangle(bounds.x
				+ (bounds.width / 4), bounds.y + (bounds.height / 4),
				bounds.width / 2, bounds.height / 2);

		if (!centerRectangle.contains(location)) {
			Point point = getIntersectionPoint(location, sourceFigure);
			anchor.setLocation(point);
		}

		return anchor;

	} else if (request instanceof CreateConnectionRequest) {
		CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;

		Command command = connectionRequest.getStartCommand();

		if (command instanceof CreateCommentConnectionCommand) {
			return super.getTargetConnectionAnchor(request);
		}
	}

	return new XYChopboxAnchor(this.getFigure());
}
 
Example 10
Source File: TableViewEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request request) {
	if (request instanceof ReconnectRequest) {
		ReconnectRequest reconnectRequest = (ReconnectRequest) request;

		ConnectionEditPart connectionEditPart = reconnectRequest
				.getConnectionEditPart();

		if (!(connectionEditPart instanceof RelationEditPart)) {
			return super.getTargetConnectionAnchor(request);
		}

		Relation relation = (Relation) connectionEditPart.getModel();
		if (relation.getSource() == relation.getTarget()) {
			return new XYChopboxAnchor(this.getFigure());
		}

		EditPart editPart = reconnectRequest.getTarget();

		if (editPart == null
				|| !editPart.getModel().equals(relation.getTarget())) {
			return new XYChopboxAnchor(this.getFigure());
		}

		Point location = new Point(reconnectRequest.getLocation());
		this.getFigure().translateToRelative(location);
		IFigure targetFigure = ((TableViewEditPart) connectionEditPart
				.getTarget()).getFigure();

		XYChopboxAnchor anchor = new XYChopboxAnchor(this.getFigure());

		Rectangle bounds = targetFigure.getBounds();

		Rectangle centerRectangle = new Rectangle(bounds.x
				+ (bounds.width / 4), bounds.y + (bounds.height / 4),
				bounds.width / 2, bounds.height / 2);

		if (!centerRectangle.contains(location)) {
			Point point = getIntersectionPoint(location, targetFigure);
			anchor.setLocation(point);
		}

		return anchor;

	} else if (request instanceof CreateConnectionRequest) {
		CreateConnectionRequest connectionRequest = (CreateConnectionRequest) request;

		Command command = connectionRequest.getStartCommand();

		if (command instanceof CreateCommentConnectionCommand) {
			return super.getTargetConnectionAnchor(request);
		}
	}

	return new XYChopboxAnchor(this.getFigure());
}
 
Example 11
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectSourceCommand(
		ReconnectRequest reconnectrequest) {
	ConnectionElement connection = (ConnectionElement) reconnectrequest
			.getConnectionEditPart().getModel();

	if (!(connection instanceof Relation)) {
		return null;
	}

	Relation relation = (Relation) connection;

	if (relation.getSource() == relation.getTarget()) {
		return null;
	}

	NodeElement newSource = (NodeElement) reconnectrequest.getTarget().getModel();
	if (!relation.getSource().equals(newSource)) {
		return null;
	}

	NodeElementEditPart sourceEditPart = (NodeElementEditPart) reconnectrequest
			.getConnectionEditPart().getSource();

	Point location = new Point(reconnectrequest.getLocation());

	IFigure sourceFigure = sourceEditPart.getFigure();
	sourceFigure.translateToRelative(location);

	int xp = -1;
	int yp = -1;

	Rectangle bounds = sourceFigure.getBounds();

	Rectangle centerRectangle = new Rectangle(
			bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4),
			bounds.width / 2, bounds.height / 2);

	if (!centerRectangle.contains(location)) {
		Point point = ERTableEditPart.getIntersectionPoint(location,
				sourceFigure);
		xp = 100 * (point.x - bounds.x) / bounds.width;
		yp = 100 * (point.y - bounds.y) / bounds.height;
	}

	ReconnectSourceCommand command = new ReconnectSourceCommand(relation,
			xp, yp);

	return command;
}
 
Example 12
Source File: NodeElementGraphicalNodeEditPolicy.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected Command getReconnectTargetCommand(
		ReconnectRequest reconnectrequest) {
	ConnectionElement connection = (ConnectionElement) reconnectrequest
			.getConnectionEditPart().getModel();

	if (!(connection instanceof Relation)) {
		return null;
	}

	Relation relation = (Relation) connection;

	if (relation.getSource() == relation.getTarget()) {
		return null;
	}

	NodeElement newTarget = (NodeElement) reconnectrequest.getTarget()
			.getModel();
	if (!relation.getTarget().equals(newTarget)) {
		return null;
	}

	NodeElementEditPart targetEditPart = (NodeElementEditPart) reconnectrequest
			.getConnectionEditPart().getTarget();

	Point location = new Point(reconnectrequest.getLocation());

	IFigure targetFigure = targetEditPart.getFigure();
	targetFigure.translateToRelative(location);

	int xp = -1;
	int yp = -1;

	Rectangle bounds = targetFigure.getBounds();

	Rectangle centerRectangle = new Rectangle(
			bounds.x + (bounds.width / 4), bounds.y + (bounds.height / 4),
			bounds.width / 2, bounds.height / 2);

	if (!centerRectangle.contains(location)) {
		Point point = ERTableEditPart.getIntersectionPoint(location,
				targetFigure);

		xp = 100 * (point.x - bounds.x) / bounds.width;
		yp = 100 * (point.y - bounds.y) / bounds.height;
	}
	ReconnectTargetCommand command = new ReconnectTargetCommand(relation,
			xp, yp);

	return command;
}