Current Editor and Semantic Resource [message #1714779] |
Mon, 16 November 2015 10:43  |
Eclipse User |
|
|
|
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 17:13   |
Eclipse User |
|
|
|
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
|
|
|
Re: Current Editor and Semantic Resource [message #1715176 is a reply to message #1714779] |
Thu, 19 November 2015 15:04   |
Eclipse User |
|
|
|
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 15:17  |
Eclipse User |
|
|
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03953 seconds