6 Editing objects in the projection

 

This chapter covers

  • Adding new AST objects to the projection
  • Selecting AST objects in the projection
  • Deleting AST objects from the projection
  • Projecting unset properties
  • Capturing special keypresses

In chapter 5, you learned how to make property values in the AST editable. That’s useful, but it’s not enough for domain experts to have complete control over the AST. In this chapter, we’ll extend the capabilities of the DSL editor to add new and delete existing AST objects, as outlined in figure 6.1.

Figure 6.1 Extending the DSL editor’s editing capabilities at the object level
figure

We’re going to use all of the mechanisms we implemented in chapter 5, and we’ll need a couple of new mechanisms too. You’ll probably need all of these to implement an editor for any DSL.

To identify which AST object should be deleted, we’re going to implement a selection mechanism. We’re also going to show how to deal with properties of newly created AST objects that don’t have a value set yet. You’ll also learn how to handle keyboard events and deal with event propagation. We’ll continue with the code from the latest versions of the files under src from chapter 5.

6.1 Adding new objects to the AST

Let’s enable a domain expert to add new AST objects to the example AST—our trusty Rental record type. There are two spots where we could add new objects (see figure 6.2):

6.1.1 Adding an attribute

6.1.2 Adding an initial value

6.2 Selecting objects

6.2.1 Selecting an attribute

6.2.2 Deselecting an attribute

6.2.3 Selecting and deselecting any object

6.3 Deleting objects

6.3.1 Deleting initial values

6.3.2 Deleting attributes

6.3.3 Deleting any object

Summary