use of org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor in project elk by eclipse.
the class GmfLayoutEditPolicy method addEdgeLayout.
/**
* Adds an edge layout to the given command.
*
* @param command
* command to which an edge layout shall be added
* @param elkEdge
* edge with layout data
* @param connectionEditPart
* edit part to which layout is applied
* @param scale
* scale factor for coordinates
*/
private void addEdgeLayout(final GmfLayoutCommand command, final ElkEdge elkEdge, final ConnectionEditPart connectionEditPart, final double scale) {
if (connectionEditPart.getSource() != null && connectionEditPart.getTarget() != null) {
// create source terminal identifier
INodeEditPart sourceEditPart = (INodeEditPart) connectionEditPart.getSource();
ConnectionAnchor sourceAnchor;
if (sourceEditPart instanceof ConnectionEditPart) {
// if the edge source is a connection, don't consider the source point
sourceAnchor = new SlidableAnchor(sourceEditPart.getFigure());
} else {
KVector sourceRel = getRelativeSourcePoint(elkEdge);
sourceAnchor = new SlidableAnchor(sourceEditPart.getFigure(), new PrecisionPoint(sourceRel.x, sourceRel.y));
}
String sourceTerminal = sourceEditPart.mapConnectionAnchorToTerminal(sourceAnchor);
// create target terminal identifier
INodeEditPart targetEditPart = (INodeEditPart) connectionEditPart.getTarget();
ConnectionAnchor targetAnchor;
if (targetEditPart instanceof ConnectionEditPart) {
// if the edge target is a connection, don't consider the target point
targetAnchor = new SlidableAnchor(targetEditPart.getFigure());
} else {
KVector targetRel = getRelativeTargetPoint(elkEdge);
targetAnchor = new SlidableAnchor(targetEditPart.getFigure(), new PrecisionPoint(targetRel.x, targetRel.y));
}
String targetTerminal = targetEditPart.mapConnectionAnchorToTerminal(targetAnchor);
PointList bendPoints = getBendPoints(elkEdge, connectionEditPart.getFigure(), scale);
// check whether the connection is a note attachment to an edge, then remove bend points
if (sourceEditPart instanceof ConnectionEditPart || targetEditPart instanceof ConnectionEditPart) {
while (bendPoints.size() > 2) {
bendPoints.removePoint(1);
}
}
// retrieve junction points and transform them to absolute coordinates
KVectorChain junctionPoints = elkEdge.getProperty(CoreOptions.JUNCTION_POINTS);
String serializedJP = null;
if (junctionPoints != null) {
for (KVector point : junctionPoints) {
ElkUtil.toAbsolute(point, elkEdge.getContainingNode());
}
serializedJP = junctionPoints.toString();
}
command.addEdgeLayout((Edge) connectionEditPart.getModel(), bendPoints, sourceTerminal, targetTerminal, serializedJP);
}
}
use of org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor in project statecharts by Yakindu.
the class AdjustIdentityAnchorCommand method handleEdge.
private void handleEdge(Edge edge, EditPart editPart, boolean sourceAnchor) {
Anchor anchorToModify;
if (sourceAnchor) {
anchorToModify = edge.getSourceAnchor();
} else {
anchorToModify = edge.getTargetAnchor();
}
String terminalString = composeTerminalString(DEFAULT_POINT);
if (anchorToModify instanceof IdentityAnchor) {
terminalString = ((IdentityAnchor) anchorToModify).getId();
}
PrecisionPoint anchorPoint = BaseSlidableAnchor.parseTerminalString(terminalString);
PrecisionPoint newPoint = computeNewAnchor(anchorPoint, editPart);
String newTerminalString = new SlidableAnchor(null, newPoint).getTerminal();
if (anchorToModify instanceof IdentityAnchor) {
((IdentityAnchor) anchorToModify).setId(newTerminalString);
} else if (anchorToModify == null) {
// Create a new one
IdentityAnchor newAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
newAnchor.setId(newTerminalString);
if (sourceAnchor) {
edge.setSourceAnchor(newAnchor);
} else {
edge.setTargetAnchor(newAnchor);
}
}
}
Aggregations