Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » DDiagramElement of a programatically created model object(How to get the DDiagramElement of a programatically created model object?)
DDiagramElement of a programatically created model object [message #1806777] Wed, 15 May 2019 06:49 Go to next message
Jai M is currently offline Jai MFriend
Messages: 4
Registered: February 2019
Junior Member
I am creating objects of my model classes in a java service. And I have graphical representations set for them in the visual specification project. I'm able to see the diagram representation of the newly created objects. I wish to set the position and size of these newly created object in my java service and by referring to [1] I understand that I need to have the DDiagramElement referring to this object so that I can set the LayoutData. How can I retrieve the DDiagramElement for a model object that is created in the java service.

For example:
In the case of Family model, if I create a Man object and named it "Alex" in a java service, how can I get the DDiagramElement referring to this? Or is there another way doing what I am trying to do?

I will greatly appreciate your thoughts in this direction.

Thanks in Advance
Jai

[1] https://wiki.eclipse.org/Sirius/Cookbook#Set_Coordinates
Re: DDiagramElement of a programatically created model object [message #1806792 is a reply to message #1806777] Wed, 15 May 2019 08:36 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 432
Registered: May 2011
Senior Member
Hello,

When a service creates semantic elements a command is executed. This will trigger a synchronization on the diagram that will create the required DDiagramElements concerning the change introduced by the command. Therefore, in your service you only need to refresh the representation for the the new DDiagramElements to be created: DialectManager.INSTANCE.refresh(diagram, new NullProgressMonitor());
The DDiagramElement is now created but there is no reference of a semantic element to DDiagramElements representing it, it's DDiagramElements that references their semantic element. You will need to use the API new EObjectQuery(semanticElement).getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET);

Regards,
Steve


Steve Monnier - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: DDiagramElement of a programatically created model object [message #1806816 is a reply to message #1806792] Wed, 15 May 2019 15:15 Go to previous message
Jai M is currently offline Jai MFriend
Messages: 4
Registered: February 2019
Junior Member
Hello Steve,

Thank you for quick reply :)

I managed to something like this (Not complete and elegant yet. But it confirms things work)

	Session createdSession = SessionManager.INSTANCE.getSession(ab);
	Collection<EObject> objects;
	Collection<DRepresentation> allRepresentations = DialectManager.INSTANCE.getAllRepresentations(createdSession);
	for(DRepresentation representation: allRepresentations) {
		DialectManager.INSTANCE.refresh(representation, new NullProgressMonitor());
	}
	objects = new EObjectQuery(ab).getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET);

	for(EObject eo: objects){
		DDiagramElement de = (DDiagramElement) eo;
		String n = de.getName();
		LayoutData layoutData = SiriusLayoutDataManager.INSTANCE.getData((AbstractDNode)de, true);
		layoutData.getLocation().setLocation(0, 0);
	}


I can see that the new element is getting positioned at x=0 and y=0. But immediately it moves to somewhere else on the screen. Not sure if i'm doing something wrong here. Again, I would greatly appreciate your inputs. Thank you in advance :)

Jai
Previous Topic:how to drag the palette to left side on opening of representation in eclipse emf sirius programatic
Next Topic:Performance on Query Legacy with Sirius 6.1.0
Goto Forum:
  


Current Time: Sat Aug 24 00:55:46 GMT 2019

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

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

Back to the top