Show a list of nodes in a read-only style in an editor

Hi,

I have an entity language to define entities and their associations.
Associations are either owned by the source or the target entity.

I would like to show the "unowned" associations additionally at the other node in a readonly matter.

My first idea was to add a second list of children and automatically update its content.
e.g.
reverseAssociations = node.model.nodes(Association).where({~it => it.target == node; }).select({~it => it.copy; });
prettyPrint();

But that has some major disadvantages:
The content is saved in the model (instead of just showing it).

What I need:
  • A getter for a child?
  • A cell where I can provide a list of strings or better: nodes to display.

Any ideas on that? Perhaps some kind of workaround?

Greets
14 comments
Sorry, I can't help you but I'm interested in an answer, too!
0
I use a "custom" cell to show calculated nodes. Here is an example for a cell provider das returns a cell for a calculated node (node.getActualResult() in this case).
cell provider (node, editorContext)->AbstractCellProvider { 
  return new AbstractCellProvider() { 
    public EditorCell createEditorCell(EditorContext p0) { 
      EditorCell_Collection enclosingCell = EditorCell_Collection.createIndent2(p0, node); 
      enclosingCell.addEditorCell(p0.createNodeCell(node.getActualResult())); 
      return enclosingCell; 
    } 
     
    <add members (ctrl+space)> 
  }; 
}
prettyPrint();
I had to wrap the cell (p0.createNodeCell) with a cell collection to work around some problems with cell IDs.
0
Hey slisson,

Can you please tell me where and how you enter this cell provider? Do I need some language therefore??

Thanks
Fabian
0
Hi!

Currently it's not possible to handle somehow derived references in MPS in a "native" way, but if you'd like to display some kind of read-only information by adding
* R/O model access *
prettyPrint(); cell into the editor. Such cell is able to display string based on model query, so you can iterate through all "unowned" associations there and collect a label representing this information in an editor.

Going back to the original question (not sure I understood it correctly) - in MPS it's possible to store node either inside another node or directly inside a model. In case you have to create associations and then bind them to source/target entities I think you can store all associations as model root nodes or create single root node "associationContainer" and save all associations there.

Please let me know if I did not answered original question.
0
Hello Alex,

I currently use the read only model access. But it's really inconvenient if you want to display a list of information, because you can just return a string. If you want to show a variable number of elements (for example all subclasses of a class) then you must construct the string with seperators and line wraps. But you can't use something like indentation. So it would be nice to return a collection of string, which could be embedded in a collection cell. Is this possible?
0
Right now it's not possible with MPS. We have a request to support "derived" links but it's not implemented yet.

And what about modifying concept structure in order to save "unowned" associations as model roots or create one special root "Unowned Associations Container" ?
0
I was trying to help with this case by automatically maintaining a root node that contains all the associations, and then in each entity have a reference to this collection of associations, which is also automatically maintained. Then I tried to display the list of associations through the reference, and that works - each entity's editor can display all associations, and by making the reference concepts' editors read only, I can display them and disallow editing as well. The problem comes when I try to display only the unowned associations. I need to filter the collection of associations for only those whose target is equal to the entity, but unfortunately the cell list editor node's filter query function only has two parameters, scope and childNode, so I cannot obtain the Entity node which owns this editor cell. So I am unable to proceed.

But I can alternatively make the special root node contain a mapping from Entity to its unowned associations. However, that is not much different from letting each entity have a child collection of unowned associations due to the similar memory cost and maintenance code needed.
0
Ok. I see. Then for now the only way to display it is R/O model access
0
I think I will wait for this feature and live with the r/o access for now. Mostly I use this just to display some debug information, for example to show which elements my scopes return at some statement. Such use case does not justify any structure changes.
0
When you define an editor, you can use a "custom" component from the completion menu. In the Inspector you then have to type the code for returning a CellProvider.

custom_cell1.png


custom_cell2.png
0
Thanks! Thats exactly what I've looked for! I haven't seen this custom cell before.
0
Hi all,
yes this was also was I was looking for.
I had some difficulties and errors when using the actual nodes from another concept.
So i decided to use node.copy to create a transient copy for the AbstractCellProvider.
Now it is more stable. The only downside is, that changes to the original node are only displayed, when the editor containing the CellProvider is reopend.
How can I switch the editor for nodes displayed by CellProvider to readonly (editable=false). Can I use a switch in the editor definition? What is the condition for the switch? Or do i need to change this programmatically in the CellProvider?

Thanks for your help slisson!
0
You can set corresponding style value before returning new cell from custom AbstractCellProvider.createEditorCell() method implementation.

You can use EditorCell_Label.setEditable() method implementation as an example:
public void setEditable(boolean editable) {
    getStyle().set(StyleAttributes.EDITABLE, editable);
}
prettyPrint();
0

Hi Jetbrains,

I was wondering if this "derived" attributes for Concepts have made it into MPS or if there is a better way of implementing them.

Thank you!

0

Please sign in to leave a comment.