|
Re: Get GMF Node from DNodeSpec [message #1789948 is a reply to message #1789927] |
Fri, 01 June 2018 07:01 |
|
Hi Parsa,
From your modelElement element, your list references will contains all DNode, DEdge, DNodeContainer or DSemanticDiagram referencing your element, you might need to filter the result.
You might retrieve the corresponding GMF view with the same mechanism of inverse references using the NotationPackage.Literals.VIEW__ELEMENT reference.
But keep a look to the full reference chain from the edit part to the semantic model element and you will see that you have a better way to retreive the GMF node:
- Sirius -> semantic
org.eclipse.sirius.viewpoint.DSemanticDecorator.getTarget() : EObject
- GMF -> Sirius
org.eclipse.gmf.runtime.notation.View.getElement() : EObject
- EditPart -> GMF
org.eclipse.gef.EditPart.getModel() : Object
org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.getNotationView() : View
- EditPart -> Sirius
org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart.resolveSemanticElement() : EObject
org.eclipse.sirius.diagram.edit.api.part.IDiagramElementEditPart.resolveDiagramElement() : DDiagramElement
- EditPart -> Semantic
org.eclipse.sirius.diagram.edit.api.part.IDiagramElementEditPart.resolveTargetSemanticElement() : EObject
Regards
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
|
Re: Get GMF Node from DNodeSpec [message #1789988 is a reply to message #1789948] |
Fri, 01 June 2018 15:52 |
Parsa Pourali Messages: 210 Registered: February 2014 |
Senior Member |
|
|
Maxime Porhel wrote on Fri, 01 June 2018 03:01
From your modelElement element, your list references will contains all DNode, DEdge, DNodeContainer or DSemanticDiagram referencing your element, you might need to filter the result.
You might retrieve the corresponding GMF view with the same mechanism of inverse references using the NotationPackage.Literals.VIEW__ELEMENT reference.
Hi Maxime,
I tried your suggestion and it is partially working but there is something I don't understand! I am trying to retrieve and edge for a semanticModel Element using DSEMANTIC_DECORATOR__TARGET and then NotationPackage.Literals.VIEW__ELEMENT.
Using DSEMANTIC_DECORATOR__TARGET I get two DEdge elements (DEdge(0) and DEdge(1) ) and both of them are referring to the correct model element. They are kind of identical in the first glance. However, I try to get the coordinates of the sourceNode and targetNode of these two edges and set the position of my someElementNode in between them. Surprisingly, the coordinates (Layout Constraints) of the sourceNode and targetNode of DEdge(0) is different than DEdge(1). It is actually some strange coordinates that is not true. But the coordinates of the sourceNode and TargetNode of DEdge (1) shows the one I need.
So, is there any way to differentiate these two DEdges and just get the one that is the real one? Why does it return two DEdges for one element ? Below is my code:
EObject modelElement=SOME SEMANTIC MODEL ELEMENT THAT IS GIVEN AS INPUT TO THE METHOD;
ArrayList<EObject> dSemanticReferences = new ArrayList<EObject>(new EObjectQuery(modelElement)
.getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET));
EObject ref = dSemanticReferences.get(0); //HERE .get(0) returns some virtual DEdge that I don't see on the diagram, but if I use .get(1) then it works. and this is random, sometime .get(0) sometimes .get(1).
if (ref instanceof DEdge) {
if ((((DEdge) ref).getSourceNode() instanceof DNodeSpec)
&& (((DEdge) ref).getTargetNode() instanceof DNodeSpec)) {
ArrayList<EObject> viewElementReferences = new ArrayList<EObject>(
new EObjectQuery(ref).getInverseReferences(NotationPackage.Literals.VIEW__ELEMENT));
viewElementReferences.get(0);
Thanks,
Parsa
[Updated on: Fri, 01 June 2018 15:57] Report message to a moderator
|
|
|
Re: Get GMF Node from DNodeSpec [message #1790125 is a reply to message #1789988] |
Tue, 05 June 2018 13:49 |
|
Hi Parsa,
IMO, you simply have another diagram with an edge referencing your element.
That's why if your already have access to the edit part, you should go from the edit part and retrieve the GMF view, or at least filter the view return by the inverse references helper regading the current diagram. (part -> view > View.getDiagram())
Regards,
Maxime Porhel - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
|
|
|
Powered by
FUDForum. Page generated in 0.02186 seconds