Thursday, October 28, 2010

Spy On Your Models - Part 3



In this sequence of posts, I explain how to use the Model Browser provided by MoDisco to inspect an EMF model.


In the first two posts, I have described how to directly access to instances of a given type, and how to navigate through the model elements. In this third post, I will now describe how to customize the browser.



When your model contains a large number of model elements, you need help to identify the nature of the objects your are looking for. A good idea is to define a graphical extension to associate a specific graphical rendering (icon, label, color, etc). It can be achieved with the EMF.Edit framework by developing content and label provider classes. You can develop and deploy a new plug-in, and once this plug-in is installed, the customization is applied systematically. 


But in some situations, you need a more flexible customization. A customization which presents the model according to a given viewpoint. A customizations that you apply temporarily, depending on a working situation. 
This is what you can do by creating a UICustom model. 


A UICustom model defines graphical properties for elements of a metamodel (a ECore model). These properties can be loaded dynamically by the Model Browser and applied to the model elements.
First, you have to create a new MoDisco project:




Then, create a UICustom model in this project:




The UICustom creation wizard asks which is the metamodel to be customized. It proposes all the ECore models registered in your Eclipse:




Once created, you can edit the UICustom model with the editor provided by MoDisco:




Now you can select a metaclass and edit its graphical properties (label, bold, italic, font, color, icon, visible, etc). You can also customize the attributes and the references of the metaclass.


Each graphical property can be set with a static value (for example, define a new icon for all the instances of Class) or a dynamic value, computed by a Query (for example, the label of an instance of Class can be italic if its "isAbstract" value is true).


To understand how to define a customization, you can read the user manual in the MoDisco wiki.


Once saved, a UICustom is applicable. Click on the "Load Customization" button in the toolbar :




Your UICustom model appears with all the other registered UICustom models. You can select it to apply it on the current model loaded in the Model Browser.




In the next post, I will describe how to create and execute queries on model elements directly from the Model Browser.

2 comments:

  1. Hi Fred,

    I've found the MoDisco model browser most useful to explore the contents of large (around 150MB) Xtext builder state files. Thank you for the work and the informative posts!

    I have found some small bugs which I hope to report in Bugzilla soon:
    * Ctrl-X, Ctrl-C, and Ctrl-V don't work in the filter field. On OSX I can however use the corresponding context menu items.
    * The labels in the editor history (Navigate > Back and Navigate > Forward) seem to reflect the selection in the Types pane rather than that in the Instances pane.
    * The properties view doesn't get updated when I either click on the same property of another object or if I click on another property of the same object as is currently displayed.

    ReplyDelete