Error Markers and Quick Fixes in GMF editors using EVL

The Epsilon Validation Language (EVL) is a model validation language that provides additional features to OCL, such as guards, constraint dependency management, user interaction, access to Java objects, and the ability to specify a number of fixes for each constraint, that the user can invoke if the constraint fails in order to repair the model. We’ve been recently working on integrating EVL with GMF so that failed constraints can appear as error/warning markers in GMF editors, and fixes can be invoked using the standard Quick Fix mechanism. An example follows:

The following screenshot shows a file system model in a GMF-based editor (constructed here).

FileSystem

We now specify the following EVL constraints and bind them to the editor (using the instructions provided here):

context File {
 
    constraint HasName {
 
        check : self.name.isDefined()
 
        message : 'Unnamed ' + self.eClass().name + ' not allowed'
 
    }
 
}
 
context Folder {
 
    critique NameStartsWithCapital {
 
        guard : self.satisfies('HasName')
 
        check : self.name.firstToUpperCase() = self.name
 
        message : 'Folder ' + self.name +
            ' should start with an upper-case letter'
 
        fix {
 
            title : 'Rename to ' + self.name.firstToUpperCase()
 
            do {
                self.name := self.name.firstToUpperCase();
            }
        }
 
    }
 
}
 
context Sync {
 
    constraint MustLinkSame {
 
        check : self.source.eClass() = self.target.eClass()
 
        message : 'Cannot synchronize a ' + self.source.eClass().name
            + ' with a ' + self.target.eClass().name
 
        fix {
 
            title : 'Synchronize with another ' +
                self.source.eClass().name
 
            do {
 
                var target := UserInput.choose('Select target',
                    _Model.getAllOfType(self.source.eClass().name));
 
                if (target.isDefined()) self.target := target;
 
            }
 
        }
 
    }
 
}

Then, we evaluate the constraints by clicking Diagram->Validate, and our editor and Problems view now look like this:

FileSystemWithErrorsHighlighted

ProblemsView

We can now right click on the warning and invoke quick fix we have defined for the NameStartsWithCapital critique.

QuickFix 

By clicking Finish, the fix is executed and the warning disappears.

AfterQuickFix

A complete reference of the syntax and semantics of EVL can be found in Chapter 6 of the Epsilon Book (PDF). Also, instructions for binding EVL constraints with an existing GMF editor can be found here. Finally, a Flash screencast of this example is available here.

About these ads
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Error Markers and Quick Fixes in GMF editors using EVL

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s