Model Refactoring in GMF editors

To extract an interface from a UML class using the GMF-based UML2Tools class-diagram editor, one has to manually go through the following steps:

  • create and name the new interface
  • move the methods from the concrete class to the interface
  • create a generalization between the class and the interface
  • update all association ends that pointed to the class to now point to the interface

Having a wizard that could do all the above with a single click instead would arguably be a good thing. Even more, having a tool that would allow us to easily define custom wizards at a high level of abstraction by hiding the complexity of GMF would be even better.

Motivated by such scenarios, in the Epsilon GMT component we have implemented a small dedicated language (EWL) and supporting tools that enable users to specify and execute such wizards from within GMF-based editors. Our solution works with existing editors, such as the UML editors provided by the UML2Tools project, without needing to customize or re-generate them. Wizards appear in a sub-menu of the right-click menu and their effects can be undone/redone using the standard Ctrl-Z/Ctrl-Y shortcuts. Wizards are also interactive in the sense that they can prompt the user to provide additional information through standard Eclipse dialogs.

This screencast demonstrates defining and executing a wizard that implements the scenario above, as well as undoing/redoing its effects on the model. A detailed discussion on EWL can be found here and an overview of the GMF/EWL integration can be found here.

This entry was posted in Uncategorized. Bookmark the permalink.

5 Responses to Model Refactoring in GMF editors

  1. Ed Merks says:

    Cool! I could imagine it being used to create an “association” based on a pattern like the one I described in .I guess it could work in either the Ecore Tools graphical editor or even in the sample one…

  2. Thanks. I actually tried it with the built-in GMF ECore visual editor. The EWL wizard that creates the first type of association class looks like this:

    wizard CreateAssociationClassCase1 {

    guard : self.isKindOf(Collection) and
    self.size() = 2 and self.forAll(s|s.isTypeOf(ecore::EClass))

    title : ‘Create association ‘ + + + ‘Link’

    do {

    var classA :=;
    var classB :=;
    var classABLink := new ecore::EClass; := + + ‘Link’;

    var classARefB := classA.createRef(classB, true);
    var classBRefA := classB.createRef(classA, true);

    var classABLinkRefA := classABLink.createRef(classA, false);
    var classABLinkRefB := classABLink.createRef(classB, false);

    var classARefABLinks := classA.createRef(classABLink, true);
    var classBRefABLinks := classB.createRef(classABLink, true);

    classARefABLinks.eOpposite := classABLinkRefA;
    classBRefABLinks.eOpposite := classABLinkRefB;
    classABLinkRefA.eOpposite := classARefABLinks;
    classABLinkRefB.eOpposite := classBRefABLinks;

    classARefABLinks.containment := true;



    operation ecore::EClass createRef(type : ecore::EClass, many : Boolean) : ecore::EReference {

    var ref := new ecore::EReference; :=;
    if (many) { := + ‘s’;}
    ref.eType := type;
    if (many) {ref.upperBound := -1;}
    return ref;

  3. Ed Merks says:

    That’s very succinct! Cool.

    BTW, why doesn’t have a nice photo of you and a biography? Please reopen and provide some details about yourself.

  4. Thanks Ed. I’ll do that asap.

  5. Pingback: Model Refactoring in EMF editors « Epsilon Weblog

Leave a Reply

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

You are commenting using your 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