Listening for changes in a node via a plugin

Hello

I would like to accomplish the following :

When a reference in a node is changed i would like to execute some code. After reading the documentation and some posts in the forum, the only way i found to do that is by adding a plugin thats puts a listener on that node. If there is an other way plz tell me. Btw the ref is changed within an editor using the possibilites of smart references.

 

What I did so far is creating an action like suggested in this post :

https://mps-support.jetbrains.com/hc/en-us/community/posts/206614145-Creating-Model-Listener-and-accessing-changes-in-Models-inside-Actions-using-Open-API

BUT

when i try to define the Editorcontext in the action context parameters , MPS will not give ma that option. As type of paramaters i can ony choose :

model  /  nlist<>   /   node<>,

so no Editor Context or any other options shown in the documentation  ( https://confluence.jetbrains.com/display/MPSD33/Plugin ).

 

What  am I doing wrong?

 

P.S. using 3.3.1

 

Jochen

 

2 comments

I have found an alternative solution to my Listener problem. As I am creating the node I want to listen to in an Intention , I could add the Listener to the node there .

Well , thats what I thought. I wrote in the execute of the Intention :

 

node.@MyAnnotation/.getMode().addChangeListener(???????);

 

where all the ??? are i wanted to write : "  new SNodeChangeListener(){

"Implementetaiton of the Listener"

}   "

 

But MPS wont let me choose any kind of Listener Class after I type "new" . Any ideas?

0

You need to add the required dependency to your intentions aspect: org.jetbrains.mps.openapi.model@java_stub

Note, to find a model's name you can just search for the node name (e.g., SNodeChangeListener) by pressing ctrl/cmd + n, which gives you the corresponding model.

0

Please sign in to leave a comment.