Graphical Modeling Framework/Models/GMFMap
- Show children elements from non-containment feature
- Generally, Containment Feature of Node Reference specifies where to put newly created child to, while Children Feature is there to find out where to take children from to display them. It's quite often that these two are the same, hence Children Feature defaults to value of Containment Feature.
- To show children from feature different from the one they are contained with, simply set it as Children Feature. You'll need to specify Containment Feature as well.
- Endless/recursive hierarchies
- ChildReference not necessarily owns node mapping, it's possible to point to existing NodeMapping, defined elsewhere. Reusing NodeMapping allows to create endless hierarchies of elements, e.g. StateMachine owns State (via states containment ref), and State owns other States (via substates containment). To get endless State hierarchy define TopNodeReference with states set as Containment Feature, which owns NodeMapping (referencing State and appropriate diagram node and palette element). ChildReference of the NodeMapping specifies substates as Containment Feature and the owning NodeMapping as its Referenced Child. That's it.
- [Newsgroup post] with set of models illustrating this approach (there's no domain model, still, the concept of NodeMapping reuse is depicted).
- Use same creation tool to create various diagram elements
- Few mappings can point to same tool definition in the .gmftool model. Transformation (.gmfmap -> .gmfgen) is smart enough to recognize that and creates only one tool capable of creating several metamodel types. It's not possible to use the same tool to create both nodes and links, though.
- Specialize domain element
- Sometimes you may find EClass only not sufficient and there's need to further nail down what domain element to use. For example, ECore diagram's aggregation and association references - EReference with containment attrubute set to true should be visualized differently from those with containment set to false. In such case add Constraint to as MappingEntry.domainSpecialization. Though constraint may not be the best term, it's just what specialization is about - constrain domain element to particular kind. OCL is default language to express specialization, although Java and few others are supported.
- Note, with specialized domain elements there's often need to perform initializations that set appropriate attributes on element creation, see next session for details
- Init Diagram File Action doesn't work with nested container!
- Imagine, there's a simple domain model with Entity and Container, both non-abstract classes. Container has containment reference to and extends Entity (think of well known GoF Composite pattern). GMFMap model then defines NodeMapping for Container, and two child references, one for Entity, another for nested Containers. Both child references use same containment reference. With that, creating diagram from palette works fine, though init diagram file action appears not to get deeper than first level (i.e. nothing below nested container is shown). Plus (and this is another evident sign of the problem), nested container itself looks like Entity, not like Container. The reason is the action can't tell Container from Entity without explicit help from you as model author. To resolve this, add Constraint to Entity, with oclIsTypeOf expression (e.g. self.oclIsTypeOf(metamodel::Entity)). With this constraint, generated code will be capable to distinguish between elements.
- In case you don't want to use OCL or anything else, and would prefer to do it in code, method XXXVisualIDRegistry.isNode<MetaclassName>_<VisualID>() is the place to put it.
- Initialize domain element
- Constrain link creation
- Validating domain model during edit ('Live' constraints)
- TopNodeReference and ChildReference. The major difference is that top node references may only own child NodeMapping, not reuse existing as it seems confusing to allow for that. If you like to reuse some child NodeMapping for top node, you can do it other way round, i.e. reuse top node for child. Reusing another top node is not possible (are there models with different containments/children features for same elements to justify this use-case?). Also, there's no much sense to define compartments for diagam immediate children (hmm, that might be enhancement request, though I never saw such uses...), hence another difference from ChildReference. Last, TopNodeReference has no parent node.
- EClass, not ElementType/whatever as domainElement?
GMFMap's POI (points of interest)
Node and Link Mapping
These elements tie visual, tooling and metamodel element together. It's essentially a diagram element, with visual icon to show, tool to create and domain element to back up. Node Mappings are kept separate from Node References because same diagram element (described with Node Mapping) may appear in different parent-child relationships (both domain and visual).
Concept of Node References
- Containment Feature
- - EReference with containment attribute set to true.
- Children Feature
- - generally, non-containment EReference, the same as Containment Feature unless explicitly set. Usually, this feature is read-only filtering view to values in Containment Feature(Think of EClass.eAttributes and EClass.eOperations - both EOperation and EAttribute are owned via eClass.eStructuralFeatures). Though this EReference may be containment reference different from Containment Feature, it doesn't sound like reasonable use-case
- Shows actual node mapping taken as child (either from ownedChild or referencedChild)
- There's no much sense to set both ownedChild and referencedChild properties.
Label Mapping Properties
- View Pattern -
- Edit Pattern -