Multiple children in editors: menu parts and additional elements


First, sorry for the long post, I tried to condence everything here.

I am trying to customize the way children are added to a concept in the editor. E.g, concept A has 0..n children of concept B. In the editor I can make a children list, and users can add new children with the list. In this scenario, I have the following questions:

1) why can't I use menu parts for children in a multiple relationship (0..n, 1..n)? I tried adding custom menu parts but it only worked if the relationship is 0..1 or 1.

2) what is the difference between adding the first element and adding additional elements? When the list is empty there's a placeholder (<<...>>) that I can use to press Crtl-Space and get a list of possible completions (if the target is abstract, I get a list of subtypes; if it has a smart reference, I get a list of possible targets, etc). But after I add the first element I lose this placeholder and all I can do is add new elements and then fix them (unless the target is abstract, in which case I get an <abstract> placeholder which works the same way as <<...>>). So, can I control how the additional elements are chosen? (I know I can control how they are instantiated with the factory, but I am talking about choosing if pressing <enter> after the last item creates a new item or a placeholder like <<...>>). Also, the first element never triggers the construtor of the behavioural model, whereas the additional elements do.

3) how exactly do smart references add to the completion menu? More specifically, concept B (from the example above) has a smart reference (cardinality 1) to C and B also implements IVisible from the base language. In the initial placeholder (<<...>>) for adding Bs to an A, the completion menu lists the possible targets of the smart references, i.e., instances of C. However, it also adds the possible IVisible values (private, protected, public). Shouldn't only the smart references be added to this menu? Is this a bug?

Thanks for the support!!


Comment actions Permalink


I found the answer to question 1, basically one has to create an "element menu part" in the list element block, not a menu part in the common block. Is there a way to constraint the common block so that it does not show these options if the reference is multiple?

There's still the problem that this part only gets added for the completion menu of the first element.

And since I am here, I can add another question, right?

4) is there a way to prevent items to be added? Say that I want to have at most 4 children. I can do some checks in the factory and return null, which indeed prevents the 5th child to be added, but throws an exception. Can you add a check so that you only try to add the child if the factory returns not null?



Comment actions Permalink


I'll try to answer your questions below:

1. You right, looks like menu part is useless there. Can you please file a youtrack entry for me so I'll try to fix it.

2. If you have "<<...>>" placeholder in an editor and you press "Enter" there - new element will be created and this element will be created "silently" - exactly like in case you are pressing Enter/Insert inside child list after existing child node... I suppose you are actually asking to show "completion" menu on pressing Insert/Enter if different type of child elements can be created in this place (do not make a decision by default, do not create abstract concept instances, but rather show completion menu instead). Again, you are right - this is not possible now, so please file one more request for me. As a workaround for now you can add a keymap for corresponding children list and specify several KeyMapItems there all handling "Enter" key. In this case I can see menu (different from completion one, but still some menu) with all KeyMapItems attached to "Enter" key on pressing "Enter" in editor.

3. I cannot see "private, protected, public" choices in completion menu - just possible targets of SmartReference.. If you still have this problem - file a request and attach sample project there.

4. It's possible to add a constraints in MPS. You can specify canBeChild/canBeParent/canBeAncestor constraints for each concept. These constraints will be checked in completion menu and will not be checked on performing insertChild action (Enter or Insert pressed), so as a result of pressing "Enter" you can make model invalid from the side of constraints - corresponding child elements will be highlighted as incorrect elements. Again, this issue can be fixed as a result of 2. correction, but it's better have separate request for it.

Thank you for your feedback!

Unfortunately this time I have to say: "file a request and we'll correct it" for each of your complains. Sorry. :-(

Comment actions Permalink

Hi Alex,

thanks for the answers!

I created entries for the following issues:

1) MPS-9749 Remove useless "common" editor configurations for multiple children.

2) MPS-9750 Configure editor list behavior when creating new elements

4) MPS-9751 Limiting the number of children using the editor

3) I solved by using element menus instead of relying on smart references. I don't know how to reproduce that right now, if I ever do it again I will post.

Best regards,



Please sign in to leave a comment.