Insert Dropdown + create new instance of structure

Newbie here. I would like to create something where I choose out of the exisiting instances or create a new instance of the structure from a dropdown menu. In my project I create different participants and I have another structure which is called clause which references exactly one participant. What I would like to do is that when I get to the participant field in the clause strucutre that there appears a dropdown menu (i dont know what language i have to import to get the dropdown or what I would have to do) with the already existing participants plus a "create a new participant" field. If the user selects the "create a new participant" field there should automatically be a new participant created where i could enter the name and the name in the clause should automatically update itself.

Thanks in advance.


Hi, there seem to be several questions inside your question:

* How to create a model (i.e. an instance of the structure) --> for this one, I would recommend that you follow a basic howto/getting started, such as the fast track to MPS tutorial:

* How to call up a drop down menu. --> here, it's not clear yet what you are asking, especially because it seems you didn't yet make a model (instance) based on your structure. Also, it's not clear if you added an editor yet. If the idea is to simply use the existing reflective editor to just play around with your structure, then (once you have completed the first step of creating a solution and a model based on your language that has the structure you mention) you can simply edit the model in an IDE-like way and use Ctrl+space for code completion etc.


It is possible to build something like this in MPS, but with a different UX. Example: if I'm creating a link declaration in a concept and I try to enter the name of a concept that does not exist yet, I can invoke an intention to create that concept for me. You can study the code behind that intention, the screenshot below shows how to open its declaration.


My bad for the bad description of my problem.
So I already created a handful of concepts, think I chose the wrong word in my original text. 

This is my almost the whole language. There will be a contract which contains some contents. The ContractContent is an abstract interface which contains the abstract concepts elements (which contain participants and assets) and covenants (which contain clauses and actions). A clause references 1 participant. In my whole Structure I create participants, actions and assets and then create a clause. In the clause editor I already added some stuff and I already have an option "add party". What I want is when I select "add party" that there will be a new participant created just like "Dieter" in the screenshot and when I type the name that the name automatically updates itself in the participant.

This is my editor for the clause concept right now plus the inspector


Thank you for your response. Nice to know how to do that. But my problem is other than that. I already got the concept participant and I want to add a new instance of the participant concept when I click on add party.
Party = Instance of participant concept.


Right, you can just use that code and modify it a bit. After all, a concept declaration is also just an instance of a concept (called ConceptDeclaration). It's much simpler to do it like that than via the menu.


I don't really get what I should do to get my problem solved with the ConceptDeclaration. Could you help me just by giving me a few steps of what to do?


If you look at the code for that intention, you'll find that it checks whether the current editor cell is in an error state (error cells are those red rectangles with red text in them). If so, it creates a new node (of concept ConceptDeclaration or InterfaceConceptDeclaration, depending on some details) using the current text of that cell as its name. So you could take that code and adapt it to create an instance of Participant rather than ConceptDeclaration.

I can still help you with individual problems you encounter on the way but I can't give you a full detailed guide at the moment because I don't have much time.


where do i adapt the code to? can i create new intentions?


and what would i have to do if i want to solve the problem with the menu thing? sorry for all the questions


can i create new intentions?

Sure, see

what would i have to do if i want to solve the problem with the menu thing?

You would need to write code inside that 'handler' in the 'generic item' to create a new instance of Party, add it to the correct place, and add a reference to that new instance. And then you need to make the name of the party editable by setting its 'read only' property to false in the inspector. Example using an editor from a sample language:

But making the name editable will make it editable for all existing parties too (there is no way to tell a new party apart from an existing party), and it leads to errors where users want to change the party reference to another party but instead sometimes end up editing the name of the current party without changing the reference.


Please sign in to leave a comment.