Spy On Your Models - Part 3

Posté le dans Blog


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.
Auteur d'origine: Fred