Skip to content

Commit

Permalink
Add document about error cells (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
neumantm authored Sep 12, 2023
1 parent 6ab157e commit a19598e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions editor/customCells.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ If you want to store the node as its actual node type (`node<MyConcept>`) within

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.
Additionally, this technique can be used to create error cells, as described in [Error Cells](./errorCells.md).

It is also possible to set the style on those cells:

Expand Down
44 changes: 44 additions & 0 deletions editor/errorCells.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

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;
}
@Override
public EditorCell createEditorCell(EditorContext p1) {
new EditorCell_Error(p1, this.getSNode(), "Error: " + this.theNode.someBehavior(), false);
}
};
```

The final boolean parameter of the constructor is called `editable`.
The [javadoc] says the following:
```
@param editable - there are two different kinds of CEll_Error in MPS:
- one (!editable) intended to show error text and then substitute it completely then user type
something e.g. list<|<no type>>
- another (editable) allows editing error text directly without replacing it with first types character
e.g. myVariable.|field - in case "field" is not resolved, it should be highlighted as error, but should
be still completely editable
```
So if `false`, the cell will completely be replaced by the first character the user types, if `true` the content may be edited.

Even though the cell is an error cell and also sets the internal error state to true,
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>`):

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

[javadoc]: https://github.com/JetBrains/MPS/blob/7ed0ccb451197c7dc33d9395dbe0dfa74ca96786/editor/editor-runtime/source/jetbrains/mps/nodeEditor/cells/EditorCell_Error.java#L35-L42
Binary file added 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 a19598e

Please sign in to comment.