So following this concept and the use-case; select Entity and Attribute as node, Relation as link, and Attributes (under Entity) and property (under Attribute) as attribute (Figure 9). After configuration, finish the wizard. As soon as you click finish, a file with gmfgraph extension is created.
Figure 9. Graphical Definitions: This step shows categorization.
Figure 10. Generated gmfGraph File: This graph model contains a figure gallery.
As can be seen in Figure 10, the graph model contains a figure gallery that consists of figure descriptors. Figure descriptors specify the properties such as shape, color, line width, line type, etc.
By default, figure descriptor defined for Entity is of rectangle shape, and it has one label corresponding to the name attribute. Apart from figure gallery, there are Nodes, Connections, Compartment, and Diagram Label. They will use figure from figure gallery for their graphical properties.
In our case, we want Attribute node to be inside Entity and it’s just a label without any shape. Hence, Entity node will act as compartment for Attribute node.
Follow these steps to modify .gmfgraph file according to the use-case requirement:
- As Attribute node does not have any shape, delete Rectangle AttributeFigurenode from Figure Descriptor AttributeFigure and the child Access getFigureAttributePropertyFigure present under Figure Gallery.
- Right click on Figure Descriptor AttributeFigure and New Child -> Label. In the properties view, assign a name to it. Leave everything else in figure gallery as it is.
|Figure 11. Modified gmfgraph File: This is what the final gmfgraph file will look like. |
- Now we will configure the nodes. Node Entity is auto generated, and we will leave it untouched.
- As Attribute does not have any shape and does not require a separate node to be defined, therefore, from node Canvas EntityModelling, delete node Attribute (AttributeFigure).
- Right click on Canvas EntityModelling, New Child, Labels DiagramLabel. In properties view, name it as AttributeProperty, and point its Figure property to Figure Descriptor AttributeFigure.
- The next step is to make a compartment for Attribute. Right click on Canvas EntityModelling, New Child, Compartment. Give it a name AttributeCompartment, and set the Figure property to EntityFigure.
To summarize, we have the following things in .gmfgraph file (see Figure 11):
- Three figures descriptors EntityFigure, EntityRelationFigure, and AttributeFigure in figure gallery.
- One node for entity.
|Figure 12. Tool Generation Wizard: This screen shot shows some key definitions. |
- One connection for connecting entities.
- One compartment AttributeCompartment which uses EntityFigure and will contain Attributes.
- Two diagram labels: EntityName and AttributeProperty.
Step 6: Define Tooling Definition Model
Tooling definition is used to define palettes and menus in the graphical editor (see Figure 12). Palette consists of tools to draw nodes and links on the editor.
To create tooling definition, right click on ECore file, and create a Simple Tooling Definition Model.
Click next, assign a name, and a page will come up in the wizard where we will select the tools for the palette.
As creation tool for Entity, Attribute and relationship is required, so check the boxes against these names. Press Finish. A file with .gmftool extension will be created (Figure 13).
|Figure 13. Generated Tooling File: A palette can have more than one tool group. |
In the gmftool file, Creation tool element denotes the tool in palette. The image for tool can also be changed by changing the default image. A palette can have more than one tool group. A tool group contains Creation tool elements for nodes as well as for links. Default options for palette can be customized by changing the properties.
Step 7: Define Mapping Definition Model
This is the most important step in the creation of the graphical editor. GMFMap (Figure 14) binds the information from domain model (ECore), graphical definition (gmfgraph) and tooling definition (gmftool). It maps a particular graphical node with the corresponding domain model and palette tool. So which node to draw when any tool is selected from palette and which domain element should save its state, this is configured in this file.
To create mapping definition model, right click on the ECore file and create a Guide Mapping Model Creation.
|Figure 14. gmfmap Wizard Interface: This step shows the mapping nodes. |
Click Next and assign a name for it. Load the ECore file, select the same root node, load tooling model, and load graphical model. Now a page comes up where the classification of domain model elements as node or link is done. It lists all nodes and links. In our case, Attribute is not a link and it is not a top node (node having shape). It will come inside Entity node so we will remove Attribute from the list and press Finish.
A file with gmfmap extension will be created.
Let’s have a look into the details of .gmfmap file. There is top level map registry node, under which there is Mapping node. Mapping node consists of a Top Node reference (Figure 15), Link Mapping, Canvas Mapping, and few other nodes.
- Top Node reference is used to bind the node with its creation tool and domain model element, and it can contain only a Node Mapping. Node Mapping contains the information about the node which will be drawn on the editor when a tool is selected from the palette and its binding with domain element in metamodel. A Node Mapping can have Constraint, Label Mapping, Feature Label Mapping, etc.
- Label Mapping is used when the label is not to be mapped with any feature and its value is hardcoded in graph.
- Feature Label Mapping is used to put a label on the graphical node and it binds Diagram Label created in graph with the feature of domain element.
- Compartment Mapping is used for compartment creation and mapping it to some domain model element.
|Figure 15. Binding of Domain Element, Tool, and Diagram Node: This step shows the top node reference options. |
- Link Mapping is used to specify information about link, its diagram tool, and domain model element. It contains information about source feature, target feature, diagram node, tool, and many other properties.
- Canvas Mapping maps domain meta information, palette information, and visual representation together.
There is already a top node reference containing entity in the generated one. This top node reference contains mapping between diagram node, domain model element, and tool. It has a feature label mapping pointing to diagram label EntityName. This is a placeholder, where the name of entity will be given on final editor. Now, attribute node will come inside entity so we need to have a compartment for that and a label for displaying the name of attribute. There is also a link mapping which contains information about relation of two entities.
Some part of the requirement is auto-generated. The rest of it, we will create. Let’s see how. Follow the steps to change it:
|Figure 16. Link Mapping: Right click on the node mapping step. |
- As Attribute node has to come under Entity node so we need a compartment mapping for it. Right click on Node Mapping -> New Child -> Compartment Mapping. Set its compartment property to AttributeCompartment (created in graphical model).
- Attribute node is a child node for Entity. So we need to create a Child Reference and a node mapping for Attribute in compartment. For this, right click Node Mapping -> New Child -> Child Reference and set its compartment property to compartment mapping (just created) and point containment property to Entity.attributes:Attribute (Figure 16).
- Right click on child reference, Node Mapping and set its Element, Diagram Node, and Tool property for Attribute.
- We need to have a label also for the node created. So right click on Node Mapping, Feature Label Mapping, and set its Diagram Label to DiagramLabel AttributeProperty and features property to property: EString.
Now after defining all the nodes and links, the next step is to create a generator model.