Get GMF Node from DNodeSpec [message #1789927] |
Thu, 31 May 2018 17:23  |
Eclipse User |
|
|
|
Hello,
I have tried a lot to see how I can retrieve the GMF node from a DNodeSpec.
I've got the idea from the following code but didn't help :(
ArrayList<EObject> references = new ArrayList<EObject>(new EObjectQuery(modelElement).getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET));
It returns DNodeSpec and cannot be used in references.get(0).getDiagramElements().get(0); because DNodeSpec does not have diagram element!
To give you the idea, I'm trying to get the gmf Node of an element (I have edit part and semantic model element of the element) and relocate it close to another shape. So, if you think there is another easier way, please advise.
Thanks,
Regards,
Parsa
|
|
|
|
|
Re: Get GMF Node from DNodeSpec [message #1789988 is a reply to message #1789948] |
Fri, 01 June 2018 11:52   |
Eclipse User |
|
|
|
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 11:57] by Moderator
|
|
|
Re: Get GMF Node from DNodeSpec [message #1790125 is a reply to message #1789988] |
Tue, 05 June 2018 09:49  |
Eclipse User |
|
|
|
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,
|
|
|
Powered by
FUDForum. Page generated in 0.03719 seconds