Skip to content

Listener Aspect¶ ⧉

This aspect allows the creation of listeners that can react to changes in the model. It can respond to different events, such as adding and removing children or value changes of properties.

How do you react to changes in the model?

Use com.mbeddr.mpsutil.modellisteners from the mbeddr platform ⧉.

Is there a way to listen to changes in any descendant?

Add a single change listener to BaseConcept ⧉. You must still define your logic for every type of change (property, reference, child) separately.

Are they executed synchronously or asynchronously?

They execute synchronously.

What are real-world examples of listeners?

  • update other nodes when children are removed or added
  • add missing references when the model changes
  • update components that preview nodes
  • remove cache entries when you remove a node
  • calculate IDs or updated calculated hashes when the model changes
  • populating the list of results when the specified scope of a node changes that fetches information from the model

What listener can you call when an MPS project is ready?

The simplest solution would be to just create an application plugin in a plugin solution.

If you only need the IntelliJ Platform to be loaded, the extension point com.intellij.postStartupActivity or com.intellij.backgroundPostStartupActivity can be used.

For that you have to implement com.intellij.openapi.startup.ProjectActivity. To support older versions of MPS, you can implement com.intellij.openapi.startup.StartupActivity instead.

Then you can declare you implementation as extension.

1
2
3
<extensions defaultExtensionNs="com.intellij">
    <postStartupActivity implementation="com.example.MyProjectActivity"/>
</extensions>

answered by: @odzhychko

Is there a listener that's called when an MPS project is closed?

For simple use cases, you can use the dispose method of an application plugin. If you want get notified on the IntelliJ platform level, there is AppLifecycleListener which can be registered as described here ⧉.

Comments