Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Adding a Semantic Resource to the Session (SOLVED)(Side-effect of using a different ResourceSet/editing-domain than the one from session)
Adding a Semantic Resource to the Session (SOLVED) [message #1818519] Wed, 18 December 2019 11:48 Go to next message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi All,

I use the following code to add a semantic-resource to the Session instance.

final AddSemanticResourceCommand command = new AddSemanticResourceCommand(session, resource.getURI(), monitor);
session.getTransactionalEditingDomain().getCommandStack().execute(command);


The constructor takes the resource URI as an input parameter. After the command is executed, the semantic-resource "instance" loaded in the session is not the same as the one used to get the URI (resource.getURI()). As a side-effect, I see the following error when I try to perform the save operation - Impossible to find an interpreter - Could not find a session for the model element...

As a workaround, I get hold of the semantic-resource from the session using the resource URI and replace the model element in the resource with the one passed as the parameter to the service method. The hack works.

Is there a better way to deal with the above?

Out of curiosity, why is it that the `AddSemanticResourceCommand` constructor takes a resource URI and not a resource as a parameter?

Please comment.
Thanks in advance.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj

[Updated on: Wed, 18 December 2019 15:02]

Report message to a moderator

Re: Adding a Semantic Resource to the Session [message #1818523 is a reply to message #1818519] Wed, 18 December 2019 14:08 Go to previous messageGo to next message
Steve Monnier is currently offline Steve MonnierFriend
Messages: 572
Registered: May 2011
Senior Member
Hello,

Yes, this is expected to happen if your resource was loaded in a different editing domain and resource set than from the session. This is why the constructor takes a resource URI, because it will load the resource with the editing domain of the session.
You can use the command, but it will be simpler in your code to directly call addSemanticResource(URI, IProgressMonitor) from your session.

Best regards,
Steve


Steve Monnier - Obeo Canada
Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Adding a Semantic Resource to the Session [message #1818524 is a reply to message #1818523] Wed, 18 December 2019 15:01 Go to previous message
Neeraj Bhusare is currently offline Neeraj BhusareFriend
Messages: 177
Registered: July 2009
Location: Canada
Senior Member
Hi Steve,

Your tip worked. Tx.

I was loading the resource using `new XtextResourcSet().getResource(...)` . I replace it with `session.getTransactionalEditingDomain().getResourceSet().getResource(uri, true)`.


Twitter : @NeerajBhusare
Blog : https://nbhusare.github.io/
Best regards, Neeraj
Previous Topic:Performing unrelated tasks as part of separate operations - resource creation, set operation
Next Topic:Hide BorderedNode when connected Edge is hidden or filtered
Goto Forum:
  


Current Time: Thu Apr 25 07:45:27 GMT 2024

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

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

Back to the top