Editor Language Overview

What is editor language?

Editor language is used in MPS to define presentation and editing aspects of the language (some aspects of editing can be specified in actions language, but it is possible to use only editor language for them). MPS editor is cell based i.e. nodes are shown as different kinds of nested cells. To create an editor in MPS you have to declare a ConceptEditorDeclaration instance for your concept. You can specify in it a template that describes how the concept will be presented.

Cells in editor

Almost everything that you see in an editor is build from cells. Cells which represent a node form a tree with a root cell representing a whole node and child cells which represent its referents, children, properties etc. Base interface for all cells is jetbrains.mps.nodeEditor.EditorCell. Every cell occupy a rectangle area of an editor and knows how to draw and layout itself and children if there are some (see the methods paint(Graphics g) and relayout()). For cells that can contain other cells there is a base class jetbrains.mps.nodeEditor.EditorCell_Collection, it can contain collection of children and has a layout manager that knows how to layout them. In MPS we has 3 layouts : horizontal layout, vertical layout and flow layout.

How to create simple editor

When you define a ConceptEditorDeclaration you describe how to create a cell (with children cells) that will represent instance of a concept. For this task we have template language in that you can easily describe how editor creation will be performed. Actually you define two editors: one editor that will be displayed in main editor component and another one that will be displayed in inspector. Usually main editor contains basic pieces of information about editor and inspector contain more specific ones. For example in editor language almost all presentation attributes are hidden in editor.

In ConceptEditorDeclaration process of editor creation described using meta cells. Each meta cell translated into one or many cells during concept creation. Most import of them are:

There are also other kinds of meta cells but they aren't as important as these.

Improving editor behaviour

When you are editing nodes in MPS it is possible to edit them in different ways. Most common of them are: completion menus that appear when you press control+space, and node insert and delete actions that are activated when you press enter, insert, delete. When you declare editor MPS generates sensible default editing actions but there are situations when you have to alter this default behaviour to improve your language usability. For example in Base Language we have local variables and local variable references. In editor for variable references MPS generates completion menu that shows all variables from this model and all imported models (it's a default behaviour) However, Base Language scoping rules restrict usage of the most of that variables. For instance, you can't reference local variable declared in one method in another methods. So if you want you editor to be more usable you have to override such defaults.

In MPS there are several parts of editor behaviour that you can override: