Actions when children were added

I want to add a new line and modify an attribute when a new children was added in the MPS editor. How can I accomplish that?

Regards
msch95
9 comments
+1

I think it would be cool to be able to link custom functionality on children addition\removing.
The major problem that I see, is that when new children node is added to a parent - the child node itself isn't yet filled properly, like, it have null children and references. But knowing it there at least would be a way to make it all work.

Like, for example, `parent` is notified when new `child` is added. Parent knows that `child` is not yet in "working" state, so it registers a callback (implemented thru child behavior), and when child node receives it's own events of properties, children, or references being set it propagates them to callbacks, and so parent may implement additional functionality on child being changed.

If I understand correctly, all of this would happen at "editor" stage, so structure could be freely changed in these actions. It would allow a great deal of additional usability tricks, when editor dynamically reacts on user actions.

Maybe there's already a way to do this, but I also couldn't find it. Like if I need to perform some structure changing where child element is required to be set, I have to call some additional intention of editor action which is applicable only if the required child is present.
0
Yeah, that's what I meant. I don't need delegation functionality (yet). But I'm pretty sure, there's a way to accomplish that or at least a portion of it.
0
Model Listeners (com.mbeddr.mpsutil.modellisteners) of the Mbeddr Platform can do this. Just import it and add a ConceptModelListeners to the constraints aspect.

model listeners for <no concept> { 
  before child removed in role <all> (instance, child)->void { 
    <no statements> 
  } 
  child added in role <all> (instance, child)->void { 
    <no statements> 
  } 
  child removed in role <all> (instance, child)->void { 
     
  } 
  property changed of property <all> (instance, propertyName, oldValue, newValue)->void { 
    <no statements> 
  } 
  reference added in role <all> (instance, target, role)->void { 
    <no statements> 
  } 
  reference removed in role <all> (instance, target, role)->void { 
    <no statements> 
  } 
}
prettyPrint();

If you only need the parent node for initializing you can use a node factory(actions aspect).
1
Hi there,

I don't know if it does what you want, but in some cases it may be enough to use the "referent set handler" (under the "referent constrains" section of the Constraints perspective); code you put here is executed on every link assignment.
2

Hi,  I added the mpsutil.modellisters to my imports, but I don't see how I can add a ComceptModelListeners to the constraints aspect.  I only get the standard constraint options.

Jos

0

they moved it to its own aspect. You have to add a "listener aspect" model to your language first.

 

0

Context menu of your language should show this: 


Be aware though that model listeners can be tricky and we rather shy away from them because of weird/unpredictable Undo/Redo behavior and some instances where we felt like the model listeners messed with manual Git merges ... so we only use them very rarely.

1

Ok, thanks for the warning.  I used Sergio's suggestion, and solved this with a node factory. It does not cover the full case, but for now this is enough.

1

Please sign in to leave a comment.