Skip to main content
Jump to: navigation, search

Difference between revisions of "Sirius/Cookbook"

(Retrieve a DNode (or another Sirius representation elements) from given semantic element)
Line 11: Line 11:
 
Note that this will find all the <code>DSemanticDecorator</code>s which represent <code>mySemanticElement</code> in the whole session (all representations included), which may or may not be what you want.
 
Note that this will find all the <code>DSemanticDecorator</code>s which represent <code>mySemanticElement</code> in the whole session (all representations included), which may or may not be what you want.
 
If you need more precision, you will have to filter the result (using <code>EObjectQuery#getRepresentation(DRepresentation)</code> for example to restrict to a specific diagram).
 
If you need more precision, you will have to filter the result (using <code>EObjectQuery#getRepresentation(DRepresentation)</code> for example to restrict to a specific diagram).
 +
 +
=== Have editor/properties view in read-only  ===
 +
 +
To control the permission on object edition, Sirius use an implementation of IPermissionAuthority. A default one named ReadOnlyPermissionAuthority is used by Sirius, to enable the read-only mode you can the following code snippet :
 +
 +
<pre>
 +
IPermissionAuthority permissionAuthority = IPermissionAuthorityRegistry.getPermissionAuthority(session.getTransactionalEditingDomain().getResourceSet());
 +
if(permissionAuthority instanceof ReadOnlyPermissionAuthority){
 +
  ((ReadOnlyPermissionAuthority)permissionAuthority).activate();
 +
}
 +
</pre>
 +
 +
To better control permissions, you can provide your own IPermissionAuthority implementation using the PermissionProvider extension point.
  
 
[[Category:Sirius]]
 
[[Category:Sirius]]

Revision as of 07:01, 30 March 2016

This page gathers code snippets which can be useful when using and extending Sirius programmatically.

Retrieve a DNode (or another Sirius representation element) from given semantic element

Sirius maintains an session-scoped inverse cross-referencer which can be used to find "who references who" even in the absence of explicit navigable references in the model. Sirius representation elements have a reference to the semantic model they represents, so you can use it for this kind of task. The most convenient way is to use the org.eclipse.sirius.business.api.query.EObjectQuery:

 Collection<EObject> result = new EObjectQuery(mySemanticElement).getInverseReferences(ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET);

Note that this will find all the DSemanticDecorators which represent mySemanticElement in the whole session (all representations included), which may or may not be what you want. If you need more precision, you will have to filter the result (using EObjectQuery#getRepresentation(DRepresentation) for example to restrict to a specific diagram).

Have editor/properties view in read-only

To control the permission on object edition, Sirius use an implementation of IPermissionAuthority. A default one named ReadOnlyPermissionAuthority is used by Sirius, to enable the read-only mode you can the following code snippet :

IPermissionAuthority permissionAuthority = IPermissionAuthorityRegistry.getPermissionAuthority(session.getTransactionalEditingDomain().getResourceSet());
if(permissionAuthority instanceof ReadOnlyPermissionAuthority){
   ((ReadOnlyPermissionAuthority)permissionAuthority).activate();
}

To better control permissions, you can provide your own IPermissionAuthority implementation using the PermissionProvider extension point.

Back to the top