Search in sources :

Example 1 with IdentityAnchor

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);
        }
    }
}
Also used : IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) Anchor(org.eclipse.gmf.runtime.notation.Anchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 2 with IdentityAnchor

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();
}
Also used : RelativeBendpoint(org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint) IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) StringValueStyle(org.eclipse.gmf.runtime.notation.StringValueStyle) ArrayList(java.util.ArrayList) RelativeBendpoints(org.eclipse.gmf.runtime.notation.RelativeBendpoints) Point(org.eclipse.draw2d.geometry.Point) RoutingStyle(org.eclipse.gmf.runtime.notation.RoutingStyle) Point(org.eclipse.draw2d.geometry.Point) RelativeBendpoint(org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint)

Aggregations

IdentityAnchor (org.eclipse.gmf.runtime.notation.IdentityAnchor)2 ArrayList (java.util.ArrayList)1 Point (org.eclipse.draw2d.geometry.Point)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 BaseSlidableAnchor (org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor)1 SlidableAnchor (org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor)1 Anchor (org.eclipse.gmf.runtime.notation.Anchor)1 RelativeBendpoints (org.eclipse.gmf.runtime.notation.RelativeBendpoints)1 RoutingStyle (org.eclipse.gmf.runtime.notation.RoutingStyle)1 StringValueStyle (org.eclipse.gmf.runtime.notation.StringValueStyle)1 RelativeBendpoint (org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint)1