Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Creating diagram for transient EObject
Creating diagram for transient EObject [message #1803462] Fri, 01 March 2019 06:22 Go to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello ,

I have a use case where i need to create a diagram for the model which is not serialized.

Below is my implementation.

1) Create session using aird file.
URI uri = URI.createPlatformResourceURI(aird.getFullPath().toString(), true);
Session s = SessionManager.INSTANCE.getSession(uri, new NullProgressMonitor());
s.save(new NullProgressMonitor());
s.open(new NullProgressMonitor());
SessionManager.INSTANCE.add(this.session);
SessionUIManager.INSTANCE.getOrCreateUISession(this.session);

2) Add all viewpoints.

3) Get RepresentationDescription associated to that model element type
final Collection<RepresentationDescription> allRepresentationDescriptions = DialectManager.INSTANCE
.getAvailableRepresentationDescriptions(this.session.getSelectedViewpoints(false), this.diagramTarget);
// filter to find specific RepresentationDescription

4) Create representation
DRepresentation rep = DialectManager.INSTANCE.createRepresentation(diagramName + " : " + elementName,
this.diagramTarget, repDescForCurrentDiag, this.session, new NullProgressMonitor());

5) Open editor
IEditorPart openEditor =
DialectUIManager.INSTANCE.openEditor(OpenGraphicalEditorAction.this.session, representation, monitor);//
openEditor.doSave(monitor);

When i try to open the editor i am getting below exception:
Root exception:
java.lang.NullPointerException
at org.eclipse.sirius.diagram.ui.business.internal.dialect.DiagramDialectUIServices.openEditor(DiagramDialectUIServices.java:180)
at org.eclipse.sirius.ui.business.internal.dialect.DialectUIManagerImpl.openEditor(DialectUIManagerImpl.java:95)

The eResource of representation is null .
Null pointer exception is thrown in below line of DiagramDialectUIServices class.

if (URIQuery.CDO_URI_SCHEME.equals(diag.eResource().getURI().scheme())) {
viewpointsActivated = activateNeededViewpoints(session, diag, monitor);
}

Few details:
Representation is getting created properly.
When i want to fetch created representation using below code i am getting empty list.

final Collection<DRepresentation> representations =
DialectManager.INSTANCE.getRepresentations(this.diagramTarget, this.session);

I have also tried attaching session to eObject
this.eObject .add(new SessionTransientAttachment(checkSession));
Even this didn't work.

Please let me know how to resolve this issue and also
Is it possible to create a diagram for transient objects ?

Thank you.

Regards,
Rakesh
Re: Creating diagram for transient EObject [message #1804918 is a reply to message #1803462] Wed, 03 April 2019 09:52 Go to previous messageGo to next message
Rakesh Nidavani is currently offline Rakesh NidavaniFriend
Messages: 25
Registered: March 2018
Junior Member
Hello,

This problem can be fixed by attaching a virtual resource to the object.

String filePath= "C:\\temp\\test.*";
URI actualURI = URI.createURI(filePath);
final ExtendedResourceSet resSet = new ExtendedResourceSetImpl();
final Resource res = resSet.createResource(actualURI);
res.getContents().add(this.model);

By using the above way we can create diagram for non serialized model.

Regards,
Rakesh
Re: Creating diagram for transient EObject [message #1804954 is a reply to message #1804918] Wed, 03 April 2019 16:25 Go to previous message
Pierre Guilet is currently offline Pierre GuiletFriend
Messages: 250
Registered: June 2017
Senior Member
Hi,

In Sirius we use org.eclipse.sirius.tools.internal.resource.InMemoryResourceImpl
It avoids file creation. Everything is in memory in streams. You can take inspiration on that.

Regards,


Pierre Guilet - Obeo
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Previous Topic:Dynamic command handlers for diagram-selections
Next Topic:[ANN] Sirius 6.2.0
Goto Forum:
  


Current Time: Fri Apr 26 02:17:34 GMT 2024

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

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

Back to the top