use of org.eclipse.gmf.runtime.notation.IdentityAnchor 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);
}
}
}
use of org.eclipse.gmf.runtime.notation.IdentityAnchor in project elk by eclipse.
the class GmfLayoutCommand method doExecuteWithResult.
@SuppressWarnings("unchecked")
@Override
protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
monitor.beginTask(getLabel(), 1);
// process shape layout data
for (ShapeLayoutData shapeLayout : shapeLayouts) {
// set new location of the element
if (shapeLayout.location != null) {
ViewUtil.setStructuralFeatureValue(shapeLayout.view, NotationPackage.eINSTANCE.getLocation_X(), Integer.valueOf(shapeLayout.location.x));
ViewUtil.setStructuralFeatureValue(shapeLayout.view, NotationPackage.eINSTANCE.getLocation_Y(), Integer.valueOf(shapeLayout.location.y));
}
// set new size of the element
if (shapeLayout.size != null) {
ViewUtil.setStructuralFeatureValue(shapeLayout.view, NotationPackage.eINSTANCE.getSize_Width(), Integer.valueOf(shapeLayout.size.width));
ViewUtil.setStructuralFeatureValue(shapeLayout.view, NotationPackage.eINSTANCE.getSize_Height(), Integer.valueOf(shapeLayout.size.height));
}
}
shapeLayouts.clear();
// process edge layout data
for (EdgeLayoutData edgeLayout : edgeLayouts) {
// set new bend points of the edge
if (edgeLayout.bends != null) {
List<RelativeBendpoint> newBendpoints = new ArrayList<RelativeBendpoint>(edgeLayout.bends.size());
Point sourcePoint = edgeLayout.bends.getFirstPoint();
Point targetPoint = edgeLayout.bends.getLastPoint();
for (int i = 0; i < edgeLayout.bends.size(); i++) {
Point bend = edgeLayout.bends.getPoint(i);
newBendpoints.add(new RelativeBendpoint(bend.x - sourcePoint.x, bend.y - sourcePoint.y, bend.x - targetPoint.x, bend.y - targetPoint.y));
}
RelativeBendpoints points = (RelativeBendpoints) edgeLayout.edge.getBendpoints();
points.setPoints(newBendpoints);
}
// set new source anchor point of the edge
if (edgeLayout.sourceTerminal != null) {
IdentityAnchor anchor = (IdentityAnchor) edgeLayout.edge.getSourceAnchor();
if (anchor == null) {
anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
edgeLayout.edge.setSourceAnchor(anchor);
}
anchor.setId(edgeLayout.sourceTerminal);
}
// set new target anchor point of the edge
if (edgeLayout.targetTerminal != null) {
IdentityAnchor anchor = (IdentityAnchor) edgeLayout.edge.getTargetAnchor();
if (anchor == null) {
anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
edgeLayout.edge.setTargetAnchor(anchor);
}
anchor.setId(edgeLayout.targetTerminal);
}
// set junction points as style
StringValueStyle style = (StringValueStyle) edgeLayout.edge.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), JUNCTION_POINTS_STYLE_NAME);
if (edgeLayout.junctionPoints == null) {
if (style != null) {
edgeLayout.edge.getStyles().remove(style);
}
} else {
if (style == null) {
style = NotationFactory.eINSTANCE.createStringValueStyle();
style.setName(JUNCTION_POINTS_STYLE_NAME);
edgeLayout.edge.getStyles().add(style);
}
style.setStringValue(edgeLayout.junctionPoints);
}
// set routing style to oblique
if (obliqueRouting) {
RoutingStyle routingStyle = (RoutingStyle) edgeLayout.edge.getStyle(NotationPackage.eINSTANCE.getRoutingStyle());
if (routingStyle != null) {
routingStyle.setRouting(Routing.MANUAL_LITERAL);
routingStyle.setSmoothness(Smoothness.NONE_LITERAL);
}
}
}
edgeLayouts.clear();
monitor.done();
return CommandResult.newOKCommandResult();
}
Aggregations