React on setting/adding children-node

Hi,

apart from mbeddr's platform-utility "com.mbeddr.mpsutil.modellisteners": ist it possible to execute custom code when a concept-child is added/changed/removed using core MPS 2018.2 functionality only? Currently i'm only able to react on adding/changing/removing a reference.

Thanks in advance!

3 comments
Comment actions Permalink

Some options I'm aware of and that might be worth considering are node factories and substitution menues when children are added. Action Maps might be worth considering when you want to react to node deletion. But it is a tricky topic. Those suggestions are not exactly model listeners and operations like Cut/Copy/Paste or Ctrl+D might not trigger these "actions", especially when subtrees are inserted / deleted and you want to react to a node somewhere in this subtree being added/removed, but it's the best I can come up with out of the top of my head.

Model listeners seem to be a popular request, but as I said, they are tricky, for example when it comes to manually merging /  resolving conflicts via the VCS plugin. Maybe it is worthwhile to describe your use case to offer some more specific help, even though I understand your question might be a general one.

1
Comment actions Permalink

Hi Robert,

thank you for your quick reply!

The use-case is as follows: i have a smart-reference-concept and need to react to new/removed/changed "real" references within that (obviously every time a new smart-reference-node is created, even if the referent ist just "changed" from an editors view).
My first thought was to use the NodeReferentConstraint within the smart-reference, but unfortunately the parent of the smart-reference-node (it seems to be connected to the surrounding node AFTER the referent has been assigned) is not yet set (is null), when "referent set handler" of the smart-reference (via the constraint aspect) is called. However in my code i need to be aware of the parent of the smart-reference to do some specific logic (model adaptations).

Thanks,
Mirko

1
Comment actions Permalink

You can use a checking rule where you attach an error to the node that needs to be updated, with a quick fix that's set to apply immediately. This will only work in the editor but maybe it's enough. See check_ArrayLength rule in MPS sources for example (there are many others).

1

Please sign in to leave a comment.