Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Get GMF Node from DNodeSpec
Get GMF Node from DNodeSpec [message #1789927] Thu, 31 May 2018 21:23 Go to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
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 #1789948 is a reply to message #1789927] Fri, 01 June 2018 07:01 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 429
Registered: July 2009
Location: Nantes, France
Senior Member
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

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/
Re: Get GMF Node from DNodeSpec [message #1789975 is a reply to message #1789948] Fri, 01 June 2018 12:29 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
Registered: February 2014
Senior Member
Awesomeeeee ! The mappings between entities is what I was looking for, thank you sooooo much Maxime!

Bests,
Parsa
Re: Get GMF Node from DNodeSpec [message #1789988 is a reply to message #1789948] Fri, 01 June 2018 15:52 Go to previous messageGo to next message
Parsa Pourali is currently offline Parsa PouraliFriend
Messages: 193
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 Go to previous message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 429
Registered: July 2009
Location: Nantes, France
Senior Member
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

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/
Previous Topic:Disable vertical scroll bar container
Next Topic:Why save all resources in DAnalysisSession
Goto Forum:
  


Current Time: Tue Sep 25 05:48:25 GMT 2018

Powered by FUDForum. Page generated in 0.02110 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top