More clickable URL links

Last time we looked at a simple way to create hyperlinks in MPS. As a reminder, it involved using a constant cell, adding styles to decorate it like a link and creating an action map with a CLICK action. In reaction to my post, Bernd Kolb has tweeted a much simpler way of creating hyperlinks: using the url style attribute. And Niko Stotz reminded me of the existence of the hyperlink language, com....

Creating clickable URL links in the editor

Today we’ll create a hyperlink cell in the MPS editor that will open a URL in the browser when clicked: The final result The link cell is in fact a customized constant cell. We need to modify two things: make the cell clickable, and make it blue and underlined. To make a cell clickable I use a cell action map and define a handler for the CLICK action:...

Use notification balloons instead of message boxes

Sometimes we need to display an error message to the user to let them know that something went wrong. Our first instinct in these cases is often to reach for a simple Swing message box: Showing a Swing message box While quick enough to write, the actual message box looks rather ugly: Swing message box in action And it can easily get you in trouble:...

Evolving your language gracefully

When you make changes to language concepts, make them backward-compatible. Don’t remove anything right away. Instead, deprecate features and make them optional first. Remove them when they have been deprecated for a while and the users have migrated not only their master branch but any work-in-progress they may have on other branches. Until you remove them, leave the deprecated features in the editor. Show them conditionally (show if), only when they have a value....

How to create a TestInfo node for your tests

You have written some tests, now you try to run them and you get this exception: jetbrains.mps.lang.test.runtime.ProjectPathIsNullException: The project path was not specified in the TestInfo root. What’s going on and how do you fix this? Solution Below I list the steps to take to set up TestInfo roots properly. I used MPS 2020.1 and the robot_Kaja sample project. The sample project comes without tests and a build file so I created a simple test model and a build file from scratch....

How to get the current MPS project from within the editor

Concept functions that are used in the MPS editor aspect usually have two parameters, editorContext and node. The current editor context provides access to the editor component, the repository, and a whole host of other services, but not to the current project. Nevertheless, it is possible and I’ll show you two ways of obtaining the project. Approach 1: Using the IDEA platform APIs // Component below is java.awt.Component Component editorComponent = (Component) editorContext....

Translation vs export

I got a question about my recent post on Good and bad ways of exporting DSL models. Adrián Szegedi messaged me on the MPS Slack and wanted to clarify why I don’t recommend using the MPS generator to export models. He said it worked for him when he built a generator to export the MPS structure model to a set of Java classes. His generator converted this concept: concept VeryEmpty extends BaseConcept implements IEmpty instance can be root: false alias: <no alias> short description: <no short description> properties: first : string second : integer third : boolean fourth : SomeEnum children: childo : VeryEmpty[0....

Use empty text for empty cells

MPS lets you customize the empty (placeholder) cell for any optional link, that is the cell that shows some gray text like no propertyValue or simply << ... >>. You generally want the custom placeholder to look just like the default one, except you may need to set a custom menu or change the default text to something more user-friendly. So you create a constant cell and specify its text. But by default this text is drawn in bold black and it looks out of place....

Advanced editors: splitting child collection in editor

I recently had to model a data warehouse star schema. The central table of a data warehouse is called a fact table. This table has two kinds of columns: dimensions and facts. If I were modelling it from scratch, I could have used two separate child links for the different columns. In pseudocode: concept FactTable children: - dimensions: DimensionColumn[0..n] - facts: FactColumn[0..n] However, in my case I had to make sure the FactTable is a KernelF record so it had to implement the IRecordDeclaration interface concept:...

Get feedback from users with generic comments

As we have seen when discussing Typesystem vs constraints and as Kolja Dummann says in his MPS Community Meetup presentation, it is often useful to let users write invalid code. This gives users an easy to use place to leave feedback: “Hey, the DSL tells me that ‘foo’ is invalid here, but I actually should be able to write that.” Sometimes it makes sense for a user to leave a textual comment at some place, say “I want to be able to write ‘foo bar baz’ here but the IDE doesn’t let me”....

Want to receive MPS tips directly in your inbox? Leave your e-mail address below.