Editor Actions

Last modified: 23 March 2021

MPS editor has quite sensible defaults in completion actions, node creation policy. But when you want to customize them, you have to work with the actions language.

Node Factories

When a node is replaced with another one, it may be useful to parametrize the process of creation of the replacing node with values held by the node that is being replaced, or perhaps also to reflect the future position of the replacing node in the model.  Node Factories give you exactly that. You write a set of handlers that get invoked whenever a new node needs to be created in a substitution action or through one of the  new initialized node<>set new initialized node<>add new initialized node<>replace with new initialized node<> and new initialized instance<> methods.

In brief, Node Factories allow you to customize instantiation of new nodes. In order to create node factory, you first have to create a new Node Factories root node. Inside of this root you can create node factories for concepts. Each node factory consists of node creation block which has the following parameters: newNode (the created node), sampleNode (the currently substituted node; can be null), enclosing node (a node which will be the parent of newNode in the model), and a model. The node factory handler is invoked before the new node gets inserted into the model.

You can leverage the concept inheritance hierarchy in  Node Factories to reduce repetition.

Ac6