Preconfigure Concepts when inserting... not possible with Node Factories .. but with?

Hi Folks,

just wondering if someone has a good hint for this requirement. I have a simple Ui Language, which allows the DSL Developer to insert Widgets into a GridLayout. The Widgets are childs of the Grid-Layout concept .. 

Now, when the user inserts a new Widget, i want to preconfigure the Widget. But the config of the Widgets depends on the Widget (prev-sibling) in Front of the current one...

Now node factories can only access information from the enclosed node.  

node concept:IBindable 
description:<none>
set-up:(newNode, sampleNode, enclosingNode, model)->void{

if(!newNode.isInstanceOf(GridLayout)){
//Do not bind Gridlayouts.

newNode.boundClassifier=
OFXScopeBridge.getProbableBoundTypeForBindable(enclosingNode.ancestor<concept =IBindable,+>).classifier;

}

}

 

 

Any alternative solutions to hook in my auto-completion / pre-configuration after insertion of the widget-node ?

 

Any hint aprecciated, cheers,

Daniel

 

3 comments

I know two ways to do this :

1) Dirty hack :

Use in your NodeFactory :

EditorComponent currentEditorComponent = MPSEditorDataKeys.EDITOR_COMPONENT.getData(DataManager.getInstance().getDataContext());

From that EditorComponent you can get selectedNode in your Editor. Then you know where the node you are about to create will be placed. And therefore know your siblings.

 

2) Use a SNodeChangeListener . This listener will be called when the node is already entered into the tree. So you have the possibility to get your siblings, and then manipulate the node according to your needs. Not sure if you have experience with listeners, here is a very short explanation how to add a listener : https://mps-support.jetbrains.com/hc/en-us/community/posts/203365210-Delete-multiple-nodes-by-action-map-So-urgent  .

Btw : I personally hate Listeners as much as I love them.

Greetings

Jochen

0

Hi Jochen,

 

nice! I just tried your first solution - perfect. Since that feature is used in a single place only, i ll isolate it and use the dirty hack. 

 

Just out of curiosity -- how do you know those things? 

 

Dan

 

 

 

0

 2 people using mps on nearly daily basis for 9 months. Lots of try and error :). Lots of searches in this forum. Going thorugh the source code of MPS looking for examples.

 

@MPS Team :  There should be a chapter in the docu about listeners! :)

0

Please sign in to leave a comment.