Search code examples
eclipseemfecoreeclipse-sirius

Different representation for superclass and subclass


I'm new to creating editors with Sirius and I have the following EMF model:

enter image description here

I want to create a Sirius editor for the given meta-model with different representations for Superclass A and Subclass B.

Both classes A and B can be instantiated and Class B has additional attributes and references. In the representation for Subclass B, I only want to show a limited number of attributes from Superclass A and a few additional attributes from Subclass B.

The idea is now to have different containers and depending on which class it is I want to show the respective container. So far when I have two containers defined in the Sirius editor, one for each class and I create an instance of Subclass B I get now two containers in the representation, one with the representation meant for Superclass A and one with the representation meant for Subclass B.

Is there any way I can tell Sirius to only show the container of the respective class?


Solution

  • So you have two different Diagram Elements for A and B in your .odesgin file?

    You can restrict the list of elements on which the graphical representation should be applied. This can be done with the "Semantic Candidates Expression" at your Diagram Element. You can easily use Java Services to filter your Model Tree and return a Collection<EObject> with all the relevant elements you want to be represented graphically (have a look at the link, it is explained perfectly).

    If the Diagram Element should only be applied on a specific feature of the parent Model Object have a look at the feature: option. Type in feature: in the 'Semantic Candidates Expression' field and hit ctrl + space, you should see a list with all possible features for the EObject you defined as the parent EObject to this Diagram Element.

    (By 'Diagram Element' I always refer to the 'Container'/'Node' Element defined in the .odesign Viewpoint)