Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Unable to add a viewpoint programmatically
Unable to add a viewpoint programmatically [message #1817103] Fri, 15 November 2019 14:37 Go to next message
Ilenia Salvadori is currently offline Ilenia SalvadoriFriend
Messages: 3
Registered: November 2019
Junior Member
Hi,
I have created a .odesign for a Sirius diagram. What I would like to do now is open a Sirius session where, provided a model instance, the corresponding model diagram should be displayed.
I was able, so far, to add the EObject corresponding to my model instance to the semantic resources of the session. I did that like this:

URL url = b.getResource("representation/representations.aird"); 
URI uri = URI.createURI(url.toString());
Session session = SessionFactory.INSTANCE.createSession(uri, new NullProgressMonitor());
				
Resource objRes = alloy.eResource();
if(objRes != null) {
	AddSemanticResourceCommand cmd = new AddSemanticResourceCommand(session, objRes.getURI(), new NullProgressMonitor());
	session.getTransactionalEditingDomain().getCommandStack().execute(cmd);
}


where "alloy" here is my EObject instance of the model which should be displayed at the end on the diagram.
Now, my representations.aird is empty, except for the model instance that I programmatically added above. How can I add the reference to my .odesign file?
I found that I can create a Representation, like:

DRepresentation representation = DialectManager.INSTANCE.createRepresentation(String, EObject, RepresentationDescription, Session, IProgressMonitor);


but what I am supposed to put as "RepresentationDescription"? Is there a similar command to add that, as I did for the semantic resources? I did not find anything.
Plus, once added the semantic resource, I can retrieve the root DAnalysis with

DAnalysis root =(DAnalysis) session.getSessionResource().getContents().get(0);


but the

DView dView = root.getOwnedViews()


is null, which I believe is because I do not have a Viewpoint. Right?

Thank you in advance for your help!

Best Regards,
Ilenia
Re: Unable to add a viewpoint programmatically [message #1818114 is a reply to message #1817103] Fri, 06 December 2019 08:23 Go to previous message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 476
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Ilenia,

It seems that you created the session but did not open it.
I would recommend to use Session session = SessionManager.INSTANCE.createSession(uri, progressMonitor), then session.open() and save it.

Then you will need to activate your Viewpoint (this will create the DView which will be used to store/reference your representations).
You might do it with:
- org.eclipse.sirius.ui.business.api.session.UserSession.from(session).selectViewpoint(viewpointName);
- or by executing a ChangeViewpointSelectionCommand() on the session.getTransactionalEditingDomain().getCommandStack()

Then for the diagram creation if you want to use the DialectManager.createRepresentation you will haver to retrieve the RepresentationDescription from the activated Viewpoint or from the ViewpointRegistry.getInstance(). You might also use or take a look to org.eclipse.sirius.ui.tools.internal.wizards.CreateRepresentationWizard and org.eclipse.sirius.ui.tools.internal.actions.creation.CreateRepresentationAction.

Once your .aird file will be saved, for the next opening you will simply need to open the session with SessionManager.INSTANCE.openSession (see also org.eclipse.sirius.ui.tools.internal.views.common.modelingproject.OpenRepresentationsFileJob) or SessionManager.INSTANCE.getSession(uri, progressmonitor) and then open() it.

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:How to set Values of attributes programmatically
Next Topic:[ANN] Sirius 6.3.0
Goto Forum:
  


Current Time: Thu Feb 20 19:17:47 GMT 2020

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

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

Back to the top