Making part of an editor optional

1. How do you make an editor component optional? For example, considering Java:

class [Classname] extends [Parentname]..

If Parentname is absent, the word "extends" shouldn't be there. But how can I specify this?

2. I'm trying to create a comma separated list of references. At the moment it's specified as:

[> observe { type } { observed } in ( % castes % -> { name } ) <]

I want to make castes->name into a child item list instead of a single item, but it won't let me. If I change the ( to (-, it won't allow the -> operator to be placed inside it. How can I do this?

 

6 comments
Comment actions Permalink

!. The cell for extends has to specify a condition in the "show if" property. The "else" part of an if statement in the Robot Kaja language uses this technique

2. References can only have cardinality 1 or 0..1, so you can never have a collection of them in the editor. Only for children the 0..n and 1..n cardinalities are possible.

Vaclav

2
Comment actions Permalink

To provide maybe a bit more detail to guide you to solutions for your problems:

1. You can look at the Editor of ClassConcept (Press Ctrl+N and search for ClassConcept_Editor) to see an example for how to use the "show-if" rendering condition:

2. To get a collection of references, you have to create a new Concept that "wraps" the one you want to reference and use this new concept as a Children collection. This is commonly called a "smart reference" in MPS.

For example, assuming your concept of role "castes" is called "Cast", create a new Concept called "CastRef" that has a reference to Cast. Instead of your reference "castes" you mention in your original post above, you can use a [0..n] collection of type "CastRef" in your Concept that needs a list of references. CastRef just wraps your references. 

2
Comment actions Permalink

Also, be aware that if something is hidden in the editor when it is empty, you probably want to offer the user some way to still instantiate it. This is where side transformations or intentions might come in handy.

1
Comment actions Permalink

Thanks, that's really helpful. However the example above, with ClassConcept, shows some kind of modifier ?^ or ?[- which does not seem to be available in my spec, it appears only as a "constant" suggestion in the editor editor. Opening the "extend" block in node explorer shows only one property, "text = extend", and no way to add another. Opening it in "show reflective editor" shows: text, null text, default caret position, attracts focus, rendering condition, menu descriptor, focus policy application, id, transformation menu, and style item. I guess "rendering condition" is the one I want, but how is it different from "show if"?

0
Comment actions Permalink

These are just projections in the "Editor-Editor" ;)

The "?" will appear as soon as you add a condition to "show if". It just indicates to you, as an editor developer, that the collection is optional.

So let's try to take the notation apart:

The "[-" indicates the start of a so-called "indent collection". It allows you to group several Editor Cells together, add an indentation (I guess that's where the name is comming from), add other layout information to a group of cells, etc. "-]" denotes the end of this collection.

"extends" is the first cell within the indent collection and it is a constant cell. It basically tells MPS to "project" a constant string to the screen. The string "extends" is just what most Java developers are used to see when defining a extension-relationship for a type. You could also decide to project an image of an arrow, or something completely different. But the fact that it is a constant cell is the reason why you see the "text = extends" property in the node explorer. You are exploring the node instance of a concept called CellModel_Constant. If you go to its definition, you see that it actually has a property called "nullText" as well, which is not set for the instance you are exploring, hence it is not shown in the node explorer.

When you show the "reflective editor", you get the default projection for each node. This will indeed show you all properties, children, references for a node, even the ones that are empty. "default caret position" is a property that CellModel_Constant inherits from CellModel_AbstractLabel, the other ones you name are also inherited.

"rendering condition", as shown via the "reflective editor" is indeed what you want to set if you want to make a cell optionally hindden. But, at least  for the given example, you do not want to set the "rendering condition" for only the "extends" keyword (i.e. the CellModel_Constant instance), but the whole indent collection that also contains the "%superType%" ClassifierType. That way, the whole collection is optionally shown/hidden.

Again, look at my screenshot from above: When you place your cursor onto the indent collection (e.g. somewhere at the "?[-" before the "extends"-cell), look at the inspector tool window (Open/Close it with Alt+F2 or Cmd+F2 on MacOS, I guess). The inspector is also visible in my screenshot.

In the inspector, there is a "context sensitive" editor, meaning that it shows additional information based on your selection in the main editor.

There, you find a table of "Common:" properties in which you can also set the "rendering condition", which is labeled "show if".

As for the "^" in the editor. This is similarly to the "?" just an indicator that this Cell has something special set in the inspector. In this case, I think the "^" indicates the use of an action map. Don't get distracted by these prefixes. 

1
Comment actions Permalink

Sorry, the shortcut for the inspector is of course Alt+2 (Cmd+2 respectively), NOT Alt+F2!

1

Please sign in to leave a comment.