Custom editor for child nodes

I have an concept which I would like to create a custom editor for.

The concept have a number of children.

For each child I would like to display the childs own editor but with a "-" in front of it.

I'm not completely sure I'm trying to solve this in the right way.

But my first attempt is a custom cell looping over the child nodes. 

But I can't figure out how to find the editor cell of the child nodes:

 

return new AbstractCellProvider(node) {
@Override
public EditorCell createEditorCell(EditorContext ctx) {
  EditorCell_Collection cells = EditorCell_Collection.createVertical(ctx, node);
  foreach n in node.elements {  
    EditorCell_Collection a = EditorCell_Collection.createHorizontal(ctx, node);
    EditorCell_Label label = new EditorCell_Constant(ctx, node, "-");
    a.addEditorCell(label);
    cells.addEditorCell(a);
    how to add the child node's editor here? 
   }
return cells;
}
};

0
14 comments
Avatar
Permanently deleted user

Have you tried to get the editorCell for your child like this:

 

EditorCell nCell = ctx.getEditorComponent().getUpdater().getCurrentUpdateSession().updateChildNodeCell(n);

 

if this works, you can just add the cells as you do with the others.

0
Avatar
Permanently deleted user

Thanks I'll try that. Is that kind of chain of method calls possible to learn from the documentation? It is not completely obvious to me...

0
Avatar
Permanently deleted user

Hi Marco, 

I certainly did not "learn" this from the documentation, no ;)

The people who have implemented mbeddr (partly now in MPS-extensions) and the iets3 project did a lot of uncovering such "methods". In this particular case, I think I just came across this use case (how can I get a handle to a editor cell of a given node programmatically?) by asking in the slack myself or reading about it by accident, I don't remember.

In general, I think it is a good idea to explore the MPS codebase and the other project's I've mentioned to learn about these kinds of things, although it would be particulalry hard for this specific use case, it still helps to explore prominent things like editorContext / editorComponent and their methods, you learn a lot while doing that. It's not the optimal, but in conjunction with the documentation and the forum and slack, it's the best you can do, I'd say.

 

Best,

Robert 

0
Avatar
Permanently deleted user

Thanks for the pointers, I'll continue my search...

0
Avatar
Permanently deleted user

Thanks a lot for your advise. At the end I did not manage to get it to work completely so I had to go for another less ideal solution. It's a great tool but with lots of things lacking from the documentation it's hard to get things to work..

0
Avatar
Permanently deleted user

Hi Marco,

you are welcome to share your eventual solution maybe people in the forum can point out how to optimzie a thing or two.

As with all open source platforms, the community is key, so feel free to contribute questions, answers, suggestions (e.g. on how to improve documentation), etc. All input is welcome!

Robert

 

0
Avatar
Permanently deleted user

My "solution" was to change how my language looks like. I had to go for lists that don't have a "-" in front of each list member. 

0
Avatar
Permanently deleted user

So, what is the reason why you want to do this programmatically in the first place?

A list with a "-" in front of each item seems to be a straightforward thing to do with the MPS editor language. What am I missing?

0
Avatar
Permanently deleted user

The thing is that I want a concept to have a "-" in front of it when it is used as a child of another concept. 

0
Avatar
Permanently deleted user

Yeah, that's no problem. You could use editorhints that are added by the parent concept editor to use a second editor (with the "-")  for your child nodes in that context.

Or you could work with separators and a "manual" first "-", all done in the parent concept editor, or you can use a simple condition in the child editor ("show if parent is of concept") ... there are many ways to achieve what you want, which one is best depends on your specific use case.

Let me know if you need me to show you these options in more detail

 

0
Avatar
Permanently deleted user

I added a sample project (created with MPS 2019.2.3) that demos two of the three approaches I describe above. Feel free to check it out: https://github.com/digital-ember/mps-SSCCEs/tree/master/optionalEditorDemo

0
Avatar
Permanently deleted user

Thanks a lot for the examples. So easy when you know what to look for. I think my initial idea got very complex as I wanted the list concept to add the bullets to the list. I wanted to list items to NOT be aware that they was used in a list. I thought it would be a good idea to keep the knowledge on how to render the list editor in the list concept and let all the items that can be used in the list not know anything on what symbol to use for the bullet.

0
Avatar
Permanently deleted user

I understand your idea. In the end, it always depends on the use case to know what version makes the most sense. I added a version of a bulleted list where only the list editor knows about the bullet symbols. I use the "separator" and indentation styles. It means you need an extra constant cell before the items list so that there is an bullet in front of the first item... also a bit of a trick, but it means that the items themselves have no "knowledge" about being projected as a list.

That's the third option I was describing earlier.

0
Avatar
Permanently deleted user

Now that's exactly what I was looking for. Thanks a lot. At one point I looked at using the separator but failed to understand how to place them on new lines. The styling did it!

0

Please sign in to leave a comment.