|Customize Sirius meta-model editor to automatically add an eAnnotation to newly created elements [message #1828536]
||Thu, 11 June 2020 13:26
| Jean Walter
Registered: May 2020
I want to create ecore meta-models where each element (EClass, EAttribute, etc.) has its own eAnnotation, and I would like to create those eAnnotations automatically when creating the elements with the Sirius editor.|
I am working on metamodels, and I am currently trying to compare them with EMFCompare. This has worked quite well, but to improve the matching of the elements of my ecore meta-models, I got the idea of adding an eAnnotation with an ID key to all the elements of the meta-model. This allows perfect matching, because changing the name of an element can no longer be mistaken for a deletion of the element followed by the add of a similar element with a new name for example.
The problem is, adding all the eAnnotations by hand is quite unpractical, so I thought about customizing the Sirius editor to automatically add these eAnnotations with a new ID value for newly created elements. I don't know if this is possible, or if there exists another easier solution.
The other idea I had was to customize the Ecore meta meta-model to add an "ID" attribute to all the elements, but from what I found out, this would mean that I would have to re-write an entire Sirius Ecore editor to automatically give new values to this attributes for newly created elements.
I don't know if I am being perfectly clear, I tried to be as much as possible.
|Re: Customize Sirius meta-model editor to automatically add an eAnnotation to newly created elements [message #1828537 is a reply to message #1828536]
||Thu, 11 June 2020 13:49
|| Maxime Porhel
Registered: July 2009
Location: Nantes, France
Hi Jean, |
This kind of id/uid attribute can be found in several metamodels, as you say it is a way to not be impacted by change of other attributes as it is the case when you have a name attribute defined as ID.
It is possible to customize the genmodel to make this id unchangeable or even hidden to the use. The package factory can then set the id during during instantiation of each element (and not the graphical editor)
Your serialized models would use this id in hRef instead of xmi:id or xpath.
In Sirius we have added it in 2018 (see IdentifiedElement::uid, add in Bug 525261).
I dont't think that such kind of evolution would be accepted on the Ecore meta meta model.
For your use case, you might fork and complete your Ecore modeler but it could also be possible to provide your own behavior in a separate tool.
You could try to provide a plugin with a SessionManagerListener, on session opening and/or on Ecore Tools viewpoint activation, you would add a ModelChangeTrigger to the session.getSessionEventBroker() item.
It this change trigger you could react to creation/add of new EClass, or any wanted elements to your model.
Then you could complete this creation with a RecordingCommand which will create an eAnnotation with your own key and an id as value: see EcoreUtil.generateUUID() or java.util.UUID.randomUUID() for example.
You might also provide your own viewpoint with a layer to extend the EcoreTools modeler in order to add a tool in the palette to add your annotation on pre-existing elements.
Maxime Porhel - Obeo
Need training or professional services for Sirius?
Powered by FUDForum
. Page generated in 0.01897 seconds