Multiple editor cells for same node in single editor window


I have different editor cells in a single editor window that show the same node in different ways (using custom cells).

The problem is that the cursor jumps to the other "original" editor cell, when I start typing in the alternative cell. Sometimes I need to show just a link instead of the complete "original" cell. But then editing isn't possible anymore in the alternative cell and IntelliJ tells me "EditorCell was not found for node ...".

Any ideas or workarounds?



Comment actions Permalink

Okay, I saw in the description of com.mbeddr.mpsutil.editor.querylist that states

"Note that any MPS root editor can project every node only once in an editable way. So if you are sure (by design) that a particular querylist only shows nodes from other roots, you can leave it editable. If it may show nodes from the same root, make sure you select the Duplicate Safe option."

Is this still up-to-date? If yes are there any workarounds or dirty hacks except copying the node?

Is there any way to make one editor editable and the other one just readable? I tried the editable flag in the editor's cell style. But that doesn't change anything. The cursor still jumps to the other actually "non-editable" editor... Wouldn't it be possible to obtain write access just for the editor under the cursor (which should lock to enable selections)?

Comment actions Permalink

I tried three ways to create EditorCell's with no luck. Moreover, I don't completely understand the outcome. In the following, I'll explain each try. Hopefully someone can help me to understand the behavior and maybe give me a hint on how to solve the issue.

The simplified scenario is as follows (hopefully not too confusing):

(1) I have a concept (let's say AggregationOfNodeAttributes) that has several children (nodeAttributeConnector_1, ... nodeAttributeConnector_n), each of which has a reference to an attribute node (i.e., node which is an instance of NodeAttribute).

Thus, we can iterate over all NodeAttributes as follows:

node.nodeAttributeConnector.foreach({~it => doSomethingWith(it.nodeAttribute);}

(2) In the editor of AggregationOfNodeAttributes there is a custom cell, where I create an editor cell for each parent of its aggregated nodeAttributes (i.e., nodeAttribute.parent, which gives the attributed node).

(3) In the editor for NodeAttribute I have a simple read only model access printing some string (i.e., the parent should be hidden).

Note that BaseConcept is the attributed concept of NodeAttribute and thus we can have nested structures. Consequently, nodeAttribute_xy might appear in the list of AggregationOfNodeAttributes (where we just print the parent) AND as a descendant of  these parents (where we just print some string to hide the attributed node). As a result, by design there is just one way to edit the attributed node (namely through AggregationOfNodeAttributes)

------- 1st TRY ----------------------------------------------------
My first try in the editor of AggregationOfNodeAttributes was using the following to create an EditorCell for each nodeAttribute parent

foreach nodeAttribute in node.getAllAttributes() {
EditorCell nodeToEdit = editorContext.createNodeCell(nodeAttribute.parent)

The result was the following:

As a result, within nodeToEdit the editor of NodeAttribute is called and thus just the specified string is printed. This is not what I wanted...


------- 2nd TRY ----------------------------------------------------
Next, I tried the following

foreach nodeAttribute in node.getAllAttributes() {
EditorCell nodeToEdit = editorContext.getCellFactory().createEditorCell(nodeAttribute.parent, false)

The result was:

This shows what I wanted to achieve: parents are printed and constants are shown for each subsequent appearance of NodeAttribute. For instance, int appears within test().

However, the main problem here is that editing breaks when an attribute is printed by nodeToEdit AND hidden within another nodeToEdit. For instance, assume that instead of int there would be a BlockStatement. Then editing in this block breaks as soon as we start typing. As a consequence, backspacing and selecting (by shift + up/down) is not possible anymore with the following error:

java.lang.AssertionError: EditorCell was not found for node: <statement>


------- 3d TRY ----------------------------------------------------
In the end, I saw a "trick" in the editor reduction rules of com.mbeddr.mpsutil.editor.querylist. They seemed to try getCellFactory as well, but commented it and used Updater instead. I tried their solution as follows (without knowing what is going on under the hood):

foreach nodeAttribute in node.getAllAttributes() {
EditorCell nodeToEdit = { => editorContext.getEditorComponent().getUpdater().getCurrentUpdateSession().updateReferencedNodeCell({ => editorContext.getEditorComponent().getUpdater().getCurrentUpdateSession().updateChildNodeCell(nodeAttribute.parent); }, nodeAttribute.parent, "test"); }.invoke()

With this result:

Thus, attributes are ignored within nodeToEdit and thus the content appears twice (i.e., instead of projecting constants for attributed nodes, just the entire AST is projected). However, editing is possible as I wanted and does not break ;)

Any ideas?




Please sign in to leave a comment.