org.eclipse.draw2d.ConnectionAnchor Java Examples

The following examples show how to use org.eclipse.draw2d.ConnectionAnchor. 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: TableViewEditPart.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart editPart) {
    if (!(editPart instanceof RelationEditPart)) {
        return super.getTargetConnectionAnchor(editPart);
    }

    final Relationship relation = (Relationship) editPart.getModel();
    final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());
    final Rectangle bounds = getFigure().getBounds();
    if (relation.getTargetXp() != -1 && relation.getTargetYp() != -1) {
        anchor.setLocation(new Point(bounds.x + (bounds.width * relation.getTargetXp() / 100),
                bounds.y + (bounds.height * relation.getTargetYp() / 100)));
    }

    return anchor;
}
 
Example #2
Source File: TableViewEditPart.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart editPart) {
    if (!(editPart instanceof RelationEditPart)) {
        return super.getSourceConnectionAnchor(editPart);
    }

    final Relationship relation = (Relationship) editPart.getModel();
    final Rectangle bounds = getFigure().getBounds();
    final XYChopboxAnchor anchor = new XYChopboxAnchor(getFigure());
    if (relation.getSourceXp() != -1 && relation.getSourceYp() != -1) {
        anchor.setLocation(new Point(bounds.x + (bounds.width * relation.getSourceXp() / 100),
                bounds.y + (bounds.height * relation.getSourceYp() / 100)));
    }

    return anchor;
}
 
Example #3
Source File: NodeElementEditPart.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(final ConnectionEditPart editPart) {
    // if (!(editPart instanceof RelationEditPart)) {
    // return new ChopboxAnchor(this.getFigure());
    // }

    final ConnectionElement connection = (ConnectionElement) editPart.getModel();

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

    final Rectangle bounds = getFigure().getBounds();

    if (connection.getTargetXp() != -1 && connection.getTargetYp() != -1) {
        anchor.setLocation(new Point(bounds.x + (bounds.width * connection.getTargetXp() / 100), bounds.y + (bounds.height * connection.getTargetYp() / 100)));
    }

    return anchor;
}
 
Example #4
Source File: TableViewEditPart.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getTargetConnectionAnchor(
		ConnectionEditPart editPart) {
	if (!(editPart instanceof RelationEditPart)) {
		return super.getTargetConnectionAnchor(editPart);
	}

	Relation relation = (Relation) editPart.getModel();

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

	Rectangle bounds = this.getFigure().getBounds();

	if (relation.getTargetXp() != -1 && relation.getTargetYp() != -1) {
		anchor.setLocation(new Point(bounds.x
				+ (bounds.width * relation.getTargetXp() / 100), bounds.y
				+ (bounds.height * relation.getTargetYp() / 100)));
	}

	return anchor;
}
 
Example #5
Source File: TableViewEditPart.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getSourceConnectionAnchor(
		ConnectionEditPart editPart) {
	if (!(editPart instanceof RelationEditPart)) {
		return super.getSourceConnectionAnchor(editPart);
	}

	Relation relation = (Relation) editPart.getModel();

	Rectangle bounds = this.getFigure().getBounds();

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

	if (relation.getSourceXp() != -1 && relation.getSourceYp() != -1) {
		anchor.setLocation(new Point(bounds.x
				+ (bounds.width * relation.getSourceXp() / 100), bounds.y
				+ (bounds.height * relation.getSourceYp() / 100)));
	}

	return anchor;
}
 
Example #6
Source File: NodeElementEditPart.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ConnectionAnchor getSourceConnectionAnchor(final ConnectionEditPart editPart) {
    // if (!(editPart instanceof RelationEditPart)) {
    // return super.getSourceConnectionAnchor(editPart);
    // }

    final ConnectionElement connection = (ConnectionElement) editPart.getModel();

    final Rectangle bounds = getFigure().getBounds();

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

    if (connection.getSourceXp() != -1 && connection.getSourceYp() != -1) {
        anchor.setLocation(new Point(bounds.x + (bounds.width * connection.getSourceXp() / 100), bounds.y + (bounds.height * connection.getSourceYp() / 100)));
    }

    return anchor;
}
 
Example #7
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart con) {
	Link link = (Link) con.getModel();
	ProcessNode process = link.outputNode;
	ExchangeNode output = process.getOutput(link.processLink);
	return LinkAnchor.forOutput(process, output);
}
 
Example #8
Source File: DiagramElementsModifierTest.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test for setConnectionAnchors
 */
@Test
public void setConnectionAnchorsTest() {
	Pair<String, Class<?>> A = new Pair<String, Class<?>>("ClassA",
			org.eclipse.uml2.uml.Class.class);
	Pair<String, Class<?>> B = new Pair<String, Class<?>>("ClassB",
			org.eclipse.uml2.uml.Class.class);

	List<Pair<String, Class<?>>> objects = Arrays.asList(A, B);
	List<Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>> associations = Arrays
			.asList(new Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>(
					A, B));

	init(objects, associations);
	@SuppressWarnings("unchecked")
	List<EditPart> eps = getDiagramEditPart().getChildren();
	ClassEditPart classAEp = (ClassEditPart) eps.get(0);
	ClassEditPart classBEp = (ClassEditPart) eps.get(1);

	@SuppressWarnings("unchecked")
	List<ConnectionEditPart> conns = classBEp.getSourceConnections();
	ConnectionEditPart assoc = conns.get(0);
	DiagramElementsModifier.setConnectionAnchors(assoc, "(1, 0.5)",
			"(0, 0.5)");

	ConnectionAnchor source = classAEp.getSourceConnectionAnchor(assoc);
	ConnectionAnchor target = classBEp.getTargetConnectionAnchor(assoc);
	Point sourceReferencePoint = ((SlidableAnchor) source)
			.getReferencePoint();
	Point targetReferencePoint = ((SlidableAnchor) target)
			.getReferencePoint();
	PrecisionPoint sourceAnchor = SlidableAnchor.getAnchorRelativeLocation(
			sourceReferencePoint, source.getOwner().getBounds());
	PrecisionPoint targetAnchor = SlidableAnchor.getAnchorRelativeLocation(
			targetReferencePoint, target.getOwner().getBounds());

	Assert.assertEquals(new PrecisionPoint(1, 0.5), sourceAnchor);
	Assert.assertEquals(new PrecisionPoint(0, 0.5), targetAnchor);
}
 
Example #9
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private ConnectionAnchor targetAnchor(ReconnectRequest req) {
	Link link = (Link) req.getConnectionEditPart().getModel();
	ExchangeNode input = ((ExchangePart) req.getTarget()).getModel();
	ExchangeNode output = link.outputNode.getOutput(link.processLink);
	if (output == null || !output.matches(input))
		return null;

	// TODO: waste links
	if (input.exchange.id != link.processLink.exchangeId
			&& input.parent().isConnected(input.exchange.id))
		return null;

	return LinkAnchor.forInput(input.parent(), input);
}
 
Example #10
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private ConnectionAnchor targetAnchor(CreateConnectionRequest req) {
	CreateLinkCommand cmd = (CreateLinkCommand) req.getStartCommand();
	if (cmd.startedFromOutput) {
		if (cmd.input != null)
			return LinkAnchor.forInput(cmd.input.parent(), cmd.input);
		return null;
	}
	if (cmd.output != null)
		return LinkAnchor.forOutput(cmd.output.parent(), cmd.output);
	return null;
}
 
Example #11
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request req) {
	if (req instanceof CreateConnectionRequest)
		return targetAnchor((CreateConnectionRequest) req);
	if (req instanceof ReconnectRequest)
		return targetAnchor((ReconnectRequest) req);
	return null;
}
 
Example #12
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart con) {
	Link link = (Link) con.getModel();
	ProcessNode process = link.inputNode;
	ExchangeNode input = process.getInput(link.processLink);
	return LinkAnchor.forInput(process, input);
}
 
Example #13
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private ConnectionAnchor sourceAnchor(ReconnectRequest req) {
	Link link = (Link) req.getConnectionEditPart().getModel();
	ProcessNode process = ((ExchangePart) req.getTarget()).getModel().parent();
	ExchangeNode output = process.getOutput(link.processLink);
	ExchangeNode input = link.inputNode.getInput(link.processLink);
	if (input == null || !input.matches(output))
		return null;
	return LinkAnchor.forOutput(process, output);
}
 
Example #14
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private ConnectionAnchor sourceAnchor(CreateConnectionRequest req) {
	CreateLinkCommand cmd = (CreateLinkCommand) ((CreateConnectionRequest) req)
			.getStartCommand();
	if (cmd.output != null)
		return LinkAnchor.forOutput(cmd.output.parent(), cmd.output);
	if (cmd.input != null)
		return LinkAnchor.forInput(cmd.input.parent(), cmd.input);
	return null;
}
 
Example #15
Source File: AbstractNodeEditPart.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request req) {
	if (req instanceof CreateConnectionRequest)
		return sourceAnchor((CreateConnectionRequest) req);
	if (req instanceof ReconnectRequest)
		return sourceAnchor((ReconnectRequest) req);
	return null;
}
 
Example #16
Source File: TreeConnectionRouter.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
private ProcessFigure getProcessFigure(ConnectionAnchor anchor) {
	if (anchor.getOwner() instanceof ProcessFigure)
		return (ProcessFigure) anchor.getOwner();
	else
		return (ProcessFigure) anchor.getOwner().getParent().getParent();
}
 
Example #17
Source File: RemovedNodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #18
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
	Link link = (Link) connection.getModel();
	return new ProcessLinkAnchor(link, false);
}
 
Example #19
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
	return null;
}
 
Example #20
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
	Link link = (Link) connection.getModel();
	return new ProcessLinkAnchor(link, true);
}
 
Example #21
Source File: ProcessPart.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
	return null;
}
 
Example #22
Source File: ConnectionCreationEditPolicy.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected ConnectionAnchor getTargetConnectionAnchor(
		CreateConnectionRequest request )
{
	// TODO Auto-generated method stub
	return super.getTargetConnectionAnchor( request );
}
 
Example #23
Source File: RemovedNodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #24
Source File: RemovedNodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #25
Source File: RemovedNodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getTargetConnectionAnchor(Request arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #26
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 #27
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 #28
Source File: NodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #29
Source File: NodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getSourceConnectionAnchor(Request arg0) {
	return new ChopboxAnchor(this.getFigure());
}
 
Example #30
Source File: NodeElementEditPart.java    From ermaster-b with Apache License 2.0 4 votes vote down vote up
public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart arg0) {
	return new ChopboxAnchor(this.getFigure());
}