Skip to content

Commit

Permalink
Improve errorCells documentation (#5)
Browse files Browse the repository at this point in the history
Also add sentence to customCells documentation
  • Loading branch information
neumantm authored Sep 12, 2023
1 parent a19598e commit 2736216
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ This repository contains some tips and tricks around JetBrains MPS, which I miss
### Editor

- [Custom cells and Swing Components](./editor/customCells.md)
- [Custom Error Cells](./editor/errorCells.md)
2 changes: 1 addition & 1 deletion editor/customCells.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Then you can instantiate an anonymous subclass of `AbstractCellProvider`:
```
Alternatively you can also create a named subclass of `AbstractCellProvider` in an util model and instantiate that.

If you want to store the node as its actual node type (`node<MyConcept>`) within the Provider, you can also override the constructor with a typed argument, store in a typed class attribute and pass it down to the super constructor.
If you want to store the node as its actual node type (`node<MyConcept>`) within the Provider, you can also override the constructor with a typed argument, store in a typed class attribute and pass it down to the super constructor. Alternatively, you can also store the node in a final attribute of the class (does not need constructor and therefore works in anonymous class).

To be able to instantiate cells, you usually want to import the model `jetbrains.mps.nodeEditor.cells@java_stub`.
I've found that the cells `EditorCell_Constant` and `EditorCell_RefPresentation` are particularly useful.
Expand Down
18 changes: 8 additions & 10 deletions editor/errorCells.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# Error Cells
# Custom Error Cells

Sometimes it is desired to make a cell of your editor appear like a usual error as automatically generated by MPS, e.g. when a property is empty which is not allowed to be empty.
This can be for example be the case in the editor of an abstract concept or as the empty cell of a reference or child cell.

Usually it is enough to use the provided `CellModel_Error` aka `[!<text>!]` aka `error`.
However, this currently only supports static text and is therefore not sufficient in all cases.
For example if you want to customize the empty cell of a child or reference cell with text about what this cell is about (e.g. parameter name, etc).

To do this we can use a custom cell provider as described in [Custom Cells](./customCells.md#custom-cell) with a `EditorCell_Error`:

```
new AbstractCellProvider(node) {
private node<myConcept> theNode;
public AbstractCellProvider$anonymous(node<MyConcept> theNode) {
super(theNode);
this.theNode = theNode;
}
private final node<MyConcept> theNode = node;
@Override
public EditorCell createEditorCell(EditorContext p1) {
new EditorCell_Error(p1, this.getSNode(), "Error: " + this.theNode.someBehavior(), false);
new EditorCell_Error(p1, this.getSNode(), this.theNode.getMyErrorString(), false);
}
};
```
Expand All @@ -37,7 +35,7 @@ Even though the cell is an error cell and also sets the internal error state to
this does not cause an error during model check.
Therefore, it is necessary to also check the appropriate condition in a checking rule.

The result can look like this (both the `<no type>` and the `<none>`):
The result can look like this (the `<no type>` is a usual error cell, but the parameter placeholders are custom):

![../media/screenshot_error_cell.png](../media/screenshot_error_cell.png)

Expand Down
Binary file modified media/screenshot_error_cell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2736216

Please sign in to comment.