|
Re: Current Editor and Semantic Resource [message #1715059 is a reply to message #1714779] |
Wed, 18 November 2015 22:13 |
|
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 |
C Tran 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() {
...
}
});
|
|
|
|
Powered by
FUDForum. Page generated in 0.03380 seconds