Model Listener¶
Language Namespace : com.mbeddr.mpsutil.modellisteners
The language adds a new aspect called listeners
where listeners can be created that react to various changes in the model:
instance
refers to the node from which the model listeners received the event, child
is the child node, role
is link
of a child or reference.
To listen for events in any node, select BaseConcept
as the target of the model listeners. Be careful when choosing
this approach as it can be slow when many events happen. Model listener can be used, for example, to calculate values when
something changes or execute an additional action when a root node is removed. When a node is replaced with another one
or a node is created, you might want to use node factories
or concept constructors instead.
Example for an empty model listener:
The listeners are called synchronously. Since they are operating on the models itself, there is no access to the opened editors. That means that the cursor might jump in the editor when a node is added or removed. The listeners also might make changes to the models unpredictable and not easily revertible, so think twice before using them.