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);
}
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);
}
}
}
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;
}
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);
}
}
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;
}
Aggregations