Search in sources :

Example 6 with Edge

use of org.eclipse.gmf.runtime.notation.Edge in project statecharts by Yakindu.

the class StateTemplatesModification method execute.

@SuppressWarnings("unchecked")
@Override
protected void execute(EObject semanticObject, View view) {
    State state = (State) semanticObject;
    Resource resource = loadTemplateResource(getTemplatePath());
    Diagram diagram = (Diagram) getObjectByType(resource.getContents(), NotationPackage.Literals.DIAGRAM);
    EList<View> children = diagram.getChildren();
    List<Node> regions = new ArrayList<Node>();
    for (View child : children) {
        if (child.getType().equals(SemanticHints.REGION)) {
            regions.add((Node) child);
        }
    }
    View figureCompartment = ViewUtil.getChildBySemanticHint(view, SemanticHints.STATE_FIGURE_COMPARTMENT);
    while (regions.size() > 0) {
        Node child = regions.get(0);
        regions.remove(child);
        setPreferredSize(child);
        figureCompartment.insertChild(child);
        state.getRegions().add((Region) child.getElement());
    }
    EList<Edge> edges = diagram.getEdges();
    while (edges.size() > 0) {
        view.getDiagram().insertEdge(edges.get(0));
    }
    setPreferredSize(view);
}
Also used : State(org.yakindu.sct.model.sgraph.State) Node(org.eclipse.gmf.runtime.notation.Node) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) View(org.eclipse.gmf.runtime.notation.View) Edge(org.eclipse.gmf.runtime.notation.Edge) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Example 7 with Edge

use of org.eclipse.gmf.runtime.notation.Edge in project statecharts by Yakindu.

the class AdjustIdentityAnchorCommand method adjustAnchors.

@SuppressWarnings("unchecked")
protected void adjustAnchors(IGraphicalEditPart editPart) {
    if (editPart instanceof IGraphicalEditPart) {
        View view = ((IGraphicalEditPart) editPart).getNotationView();
        List<Edge> targetEdges = view.getTargetEdges();
        for (Edge edge : targetEdges) {
            handleEdge(edge, editPart, false);
        }
        List<Edge> sourceEdges = view.getSourceEdges();
        for (Edge edge : sourceEdges) {
            handleEdge(edge, editPart, true);
        }
    }
}
Also used : IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) View(org.eclipse.gmf.runtime.notation.View) Edge(org.eclipse.gmf.runtime.notation.Edge)

Example 8 with Edge

use of org.eclipse.gmf.runtime.notation.Edge in project statecharts by Yakindu.

the class SetLabelsOffsetOperation method isEdgeWithObliqueRoutingStyle.

public static boolean isEdgeWithObliqueRoutingStyle(org.eclipse.gef.ConnectionEditPart part) {
    Edge edge = (Edge) part.getModel();
    ConnectorStyle style = (ConnectorStyle) edge.getStyle(NotationPackage.Literals.CONNECTOR_STYLE);
    if (style != null) {
        return Routing.MANUAL_LITERAL == style.getRouting();
    }
    return false;
}
Also used : ConnectorStyle(org.eclipse.gmf.runtime.notation.ConnectorStyle) Edge(org.eclipse.gmf.runtime.notation.Edge)

Example 9 with Edge

use of org.eclipse.gmf.runtime.notation.Edge in project statecharts by Yakindu.

the class SetLabelsOffsetOperation method computeGMFLabelOffset.

/**
 * Update {@link Bounds} of a label {@link Node}.
 *
 * @param labelEdgeEditPart
 *            the editPart of the edge label to be updated
 * @param connectionEditPart
 *            The connection having these labels
 */
private void computeGMFLabelOffset(LabelEditPart labelEditPartToUpdate, ConnectionEditPart connectionEditPart) {
    Point newLabelOffset = null;
    Node labelNodeToUpdate = (Node) labelEditPartToUpdate.getModel();
    if (connectionEditPart.getModel() instanceof Edge) {
        PointList oldBendpoints = oldBendPointsList;
        if (oldBendpoints == null) {
            oldBendpoints = connectionEditPart.getConnectionFigure().getPoints();
        }
        boolean isEdgeWithObliqueRoutingStyle = isEdgeWithObliqueRoutingStyle(connectionEditPart);
        LayoutConstraint layoutConstraint = labelNodeToUpdate.getLayoutConstraint();
        if (layoutConstraint instanceof Location) {
            Location point = (Location) layoutConstraint;
            newLabelOffset = new EdgeLabelQuery(oldBendpoints, newPointList, isEdgeWithObliqueRoutingStyle, new Point(point.getX(), point.getY()), labelEditPartToUpdate.getFigure().getSize(), labelEditPartToUpdate.getKeyPoint(), false).calculateGMFLabelOffset();
        }
    }
    if (newLabelOffset != null) {
        labelsWithNewOffset.put(labelNodeToUpdate, newLabelOffset);
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) EdgeLabelQuery(org.yakindu.base.xtext.utils.gmf.routing.EdgeLabelQuery) Node(org.eclipse.gmf.runtime.notation.Node) LayoutConstraint(org.eclipse.gmf.runtime.notation.LayoutConstraint) Point(org.eclipse.draw2d.geometry.Point) Edge(org.eclipse.gmf.runtime.notation.Edge) Location(org.eclipse.gmf.runtime.notation.Location)

Example 10 with Edge

use of org.eclipse.gmf.runtime.notation.Edge in project statecharts by Yakindu.

the class ConnectorViewPostPasteChildOperation method doPaste.

/**
 * @return
 * @throws Exception
 */
private EObject doPaste() throws Exception {
    View sourceView = getConnectorViewPasteOperation().getSourceView();
    View targetView = getConnectorViewPasteOperation().getTargetView();
    if ((sourceView == null) || (targetView == null)) {
        return null;
    }
    EObject sourceViewContainer = sourceView.eContainer();
    EObject targetViewContainer = targetView.eContainer();
    if ((sourceViewContainer == null) || (targetViewContainer == null)) {
        return null;
    }
    if (sourceViewContainer.equals(targetViewContainer) == false) {
        // not in the same container, let's try to see if they are in the
        // same diagram at least
        Diagram sourceViewDiagram = NotationClipboardOperationHelper.getContainingDiagram((View) sourceViewContainer);
        Diagram targetViewDiagram = NotationClipboardOperationHelper.getContainingDiagram((View) targetViewContainer);
        if ((sourceViewDiagram == null) || (targetViewDiagram == null) || (sourceViewDiagram.equals(targetViewDiagram) == false)) {
            return null;
        }
    }
    Edge connectorView = getConnectorViewPasteOperation().getConnectorView();
    if (pasteSemanticElement) {
        EObject semanticElement = connectorView.getElement();
        if (semanticElement != null) {
            if (semanticElement.eIsProxy()) {
                semanticElement = ClipboardSupportUtil.resolve(semanticElement, getParentPasteProcess().getLoadedIDToEObjectMapCopy());
            }
            String loadedId = getLoadedEObjectID(semanticElement);
            if (loadedId != null) {
                // even if we failed to paste the semantic element, we'll
                // proceed to paste the edge view
                doPasteSemanticElement();
                // should have been pasted by now, if not then return
                String newId = getEObjectID(semanticElement);
                if (newId == null) {
                    return null;
                }
            }
        }
    }
    EObject pastedElement = null;
    Diagram pasteTargetDiagram = NotationClipboardOperationHelper.getContainingDiagram((View) sourceViewContainer);
    if (pasteTargetDiagram != null) {
        // if we reached here then we should paste the connector and set
        // refs to it accordingly
        pastedElement = ClipboardSupportUtil.appendEObjectAt(pasteTargetDiagram, getContainmentFeature(), connectorView);
        if (pastedElement != null) {
            ClipboardSupportUtil.appendEObjectAt(sourceView, NotationPackage.eINSTANCE.getView_SourceEdges(), connectorView);
            ClipboardSupportUtil.appendEObjectAt(targetView, NotationPackage.eINSTANCE.getView_TargetEdges(), connectorView);
        }
    }
    return pastedElement;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) View(org.eclipse.gmf.runtime.notation.View) Edge(org.eclipse.gmf.runtime.notation.Edge) Diagram(org.eclipse.gmf.runtime.notation.Diagram)

Aggregations

Edge (org.eclipse.gmf.runtime.notation.Edge)10 View (org.eclipse.gmf.runtime.notation.View)6 EObject (org.eclipse.emf.ecore.EObject)5 Diagram (org.eclipse.gmf.runtime.notation.Diagram)3 Node (org.eclipse.gmf.runtime.notation.Node)3 ArrayList (java.util.ArrayList)2 ConnectorStyle (org.eclipse.gmf.runtime.notation.ConnectorStyle)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Point (org.eclipse.draw2d.geometry.Point)1 PointList (org.eclipse.draw2d.geometry.PointList)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 IGraphicalEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart)1 AbstractTransactionalCommand (org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand)1 LayoutConstraint (org.eclipse.gmf.runtime.notation.LayoutConstraint)1