Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Current Editor and Semantic Resource(Accessing the current editor and query the main semantic resource under editing)
Current Editor and Semantic Resource [message #1714779] Mon, 16 November 2015 15:43 Go to next message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Hi community,

I am developing a plugin which then needs to access a Sirius editor in order to manipulate semantic objects.

The assumption is that there could be multiple running Sirius editors opening different models. I would like to access only the current active editor and query its semantic resource it is associated with.

For finding the current active editor I could use Eclipse API IWorkbenchWindow.getActivePage() and then IWorkbenchPage.getActiveEditor()

But I don't know how to relate this to a Sirius editor. Perhaps this is not the right way. Please let me know.

I also tried a different way (as in Sirius documentation) which makes use of org.eclipse.sirius.ui.business.SessionUIManager.INSTANCE.getSessions(). I can get the sessions but in each session the Session.getSemanticResources() return more than one semantic resources. I only want to the main (or the root) resource. How do I do that?

Many thanks,

Re: Current Editor and Semantic Resource [message #1715059 is a reply to message #1714779] Wed, 18 November 2015 22:13 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 500
Registered: July 2009
Location: Nantes, France
Senior Member
Hi,

Le 16/11/2015 16:43, C Tran a écrit :
> Hi community,
>
> I am developing a plugin which then needs to access a Sirius editor in
> order to manipulate semantic objects.
> The assumption is that there could be multiple running Sirius editors
> opening different models. I would like to access only the current active
> editor and query its semantic resource it is associated with.
>
> For finding the current active editor I could use Eclipse API
> IWorkbenchWindow.getActivePage() and then IWorkbenchPage.getActiveEditor()
>
> But I don't know how to relate this to a Sirius editor. Perhaps this is
> not the right way. Please let me know.

Sirius editors inherit from
org.eclipse.sirius.ui.business.api.dialect.DialectEditor.

If your active editor is a DialectEditor, you will have access to the
getDRepresentation() method, then you could check if it is a
org.eclipse.sirius.viewpoint.DSemanticDecorator (all current Sirius
concrete representations (diagram, table, tree) inherit from it as the
representation elements).

This DSemanticDecorator interface has a getTarget() method which will
return the represented semantic object.

For a representation (diagram, table, tree), it will be the semantic
element on which the user created it.

Then if you want its semantic resource, just call eResource() on it.

>
> I also tried a different way (as in Sirius documentation) which makes
> use of
> org.eclipse.sirius.ui.business.SessionUIManager.INSTANCE.getSessions().
> I can get the sessions but in each session the
> Session.getSemanticResources() return more than one semantic resources.
> I only want to the main (or the root) resource. How do I do that?

Sirius is able to deal with several semantic resource, there is no
"main" semantic resources except if your are not using the modeling
project nature, in this legacy mode, the first semantic resource should
be the one on/from which your created the aird file.

>
> Many thanks,
>
>

Regards


--
Maxime - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius
Re: Current Editor and Semantic Resource [message #1715176 is a reply to message #1714779] Thu, 19 November 2015 20:04 Go to previous messageGo to next message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Quote:
Sirius editors inherit from
org.eclipse.sirius.ui.business.api.dialect.DialectEditor.

If your active editor is a DialectEditor, you will have access to the
getDRepresentation() method, then you could check if it is a
org.eclipse.sirius.viewpoint.DSemanticDecorator (all current Sirius
concrete representations (diagram, table, tree) inherit from it as the
representation elements).

This DSemanticDecorator interface has a getTarget() method which will
return the represented semantic object.

For a representation (diagram, table, tree), it will be the semantic
element on which the user created it.

Then if you want its semantic resource, just call eResource() on it.


This indeed gives me the right direction. Thanks a lot.

For those who are also interested in this issue and want to edit the semantic element, use the following code:

EObjectQuery query = new EObjectQuery(target);
Session session = query.getSession();
final ModelAccessor accessor = session.getModelAccessor();

TransactionalEditingDomain ted = session.getTransactionalEditingDomain();
ted.getCommandStack().execute(new RecordingCommand(ted) {
@Override
protected void doExecute() {
...
}
});


Re: Current Editor and Semantic Resource [message #1715179 is a reply to message #1715059] Thu, 19 November 2015 20:17 Go to previous message
C Tran is currently offline C TranFriend
Messages: 15
Registered: July 2014
Junior Member
Quote:
Sirius is able to deal with several semantic resource, there is no
"main" semantic resources except if your are not using the modeling
project nature, in this legacy mode, the first semantic resource should
be the one on/from which your created the aird file.


Can you elaborate a bit more on those statements above. What is "legacy mode"? In addition, what is the scenario where (many) semantic resources are useful? In my case, Session returns semantic resources for those that are NOT being opened by any editors. I cannot get my head around this semantics.

Thanks in advance.
Previous Topic:How can I develop a Graphical Modeler like UMLdesigner?
Next Topic:boolean representation in edition table
Goto Forum:
  


Current Time: Wed Jan 20 04:53:47 GMT 2021

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

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

Back to the top