Académique Documents
Professionnel Documents
Culture Documents
Slide 1
Lecture Objectives
Explore the Eclipse Modelling Framework
Defining metamodels using Ecore
Creating models that conform to Ecore metamodels
Reflectively
Through a dedicated tree-based editor
Slide 2
Slide 3
Slide 4
Slide 5
Slide 6
ECORE
Slide 7
Self-defined
Ecore's metamodel is specified using Ecore
Model Driven Engineering
Department of Computer Science
Slide 8
Slide 9
EPackage
The top-level object of an Ecore file
In Ecore terminology metamodel === EPackage
Slide 10
Slide 11
EDataType
Represent primitive types
Ecore provides built-in support for some
EDataTypes (EString, EInteger, EBoolean,
EDouble)
Each EDataType needs to define the fullyqualified name of the Java class that can
convert strings to instances of the data type
and vice-versa
Model Driven Engineering
Department of Computer Science
Slide 12
Slide 13
EEnum
Semantically equivalent to a Java enumeration
Defines a fixed set of possible values (literals)
Each literal has a name and an integer value
Integer value is incremental starting from 0
Slide 14
Slide 15
EClass
Semantically similar to a Java class
Can be instantiated to produce model elements
In the same way that Java classes can be instantiated
to produce objects
Except if its abstract or interface properties are set to
true (similar to Java)
Can contain
(E)StructuralFeatures (EAttributes and EReferences)
EOperations
Model Driven Engineering
Department of Computer Science
Slide 16
Slide 17
EStructuralFeature
EAttributes and EReferences are collectively known as
EStructuralFeatures
EAttributes: Provide slots for values of primitive types
(EDataTypes, EEnum)
EReferences: Provide slots for model elements
They only denote structure, in contrast to EOperations which
denote behaviour
Slide 18
EStructuralFeature
EStructuralFeatures can be marked as
derived: the value of the feature is computed and
cannot be changed directly by the user
volatile: the value of the feature is not persisted
when the model is saved
transient: the value of the feature is recomputed
every time it is requested
Slide 19
Slide 20
EReference
Containment
If a model element is deleted from the model, any
elements under its containment EReferences are also
deleted
Each model element can belong to at most one
containment EReference slot
eOpposite
Enables 2-way synchronisation between EReferences
Opposites need to be specified on both participating
EReferences
The opposite of the opposite of an EReference must
be the EReference itself
Model Driven Engineering
Department of Computer Science
Slide 21
No Opposites
class Node {
ref Transition[*] outgoing;
ref Transition[*] incoming;
}
class Transition {
ref Node source;
ref Node target;
}
Slide 22
Added Opposites
class Node {
ref Transition[*]#source outgoing;
ref Transition[*]#target incoming;
}
class Transition {
ref Node#outgoing source;
ref Node#incoming target;
}
Slide 23
Slide 24
EOperation
Semantically equivalent to a Java method
Has a name, typed parameters and a return type
The multiplicy of an EOperation (loweBound,
upperBound inherited from ETypedElement) affect its
return type
For example if the multiplicity of an operation is 0..* and its
return type is EString, it means that the operation will return
a list of Estrings
Slide 25
Slide 26
Slide 27
Emfatic
Textual language for defining Ecore metamodels
Very similar to Java
Language reference
www.eclipse.org/epsilon/doc/articles/emfatic
Model Driven Engineering
Department of Computer Science
Slide 28
Emfatic Editor
Slide 29
Emfatic->Ecore
Generate Ecore model in the context menu of
.emf files
Slide 30
Ecore->Emfatic
Generate Emfatic Source in the context menu
of .ecore files
Slide 31
Slide 32
Slide 33
Slide 34
Slide 35
Other alternatives
OCLInEcore
http://wiki.eclipse.org/OCL/OCLinEcore
Similar to Emfatic but with support for defining
the implementation of derived attributes /
operations using OCL
Xcore
http://wiki.eclipse.org/Xcore
Similar to OCLInEcore but uses a different
language (Xbase) for defining the implementation
of derived attributes / operations
Model Driven Engineering
Department of Computer Science
Slide 36
Slide 37
Creating Models
Once you've defined your Ecore metamodel
you'll want to create models that conform to it
You have (at least) 2 options
Create models in the same Eclipse workspace
through EMF's reflective tree-based editor / API
Generate code / a dedicated tree-editor from your
Ecore metamodel
To use the generated tree-editor you'll need to launch a
new Eclipse instance from within Eclipse (more on this
shortly)
Model Driven Engineering
Department of Computer Science
Slide 38
Slide 39
Metamodel Registration
Before you can create a model that conforms to
your Ecore metamodel, you need to let EMF
know about your Ecore metamodel
i.e. you need to register your metamodel
Slide 40
Slide 41
Tip: The EPackage Registry view does not auto-refresh. You will need to click the
Refresh button (top-right corner) when you launch it for the first time, and every
time you register new metamodels.
Model Driven Engineering
Department of Computer Science
Slide 42
Creating Models
Once EMF knows about your metamodel, you
can create models that conform to it using the
File->New->EMF Model wizard
Need to provide
A filename
The nsURI of the metamodel your model should
conform to
The type (EClass) of the root model element of
your model
Model Driven Engineering
Department of Computer Science
Slide 43
Creating Models
Slide 44
Slide 45
Slide 46
Slide 47
Generating Code
EMF provides tooling that can consume an
Ecore metamodel and generate
A Java API for your metamodel
A dedicated tree-based editor
Slide 48
Generating Code
2-step transformation
Ecore -> GenModel (Model-to-Model)
GenModel -> Java code (Model-to-Text)
GenModel
Intermediate model used to specify code
generation options (e.g. which directory / Java
package the code will be generated under)
Slide 49
Slide 50
Slide 51
Slide 52
Slide 53
Slide 54
Slide 55
Slide 56
Slide 57
Slide 58
Slide 59
3 new projects
.editor: A dedicated tree-based editor for your
metamodel
.edit: Controls the behaviour of the Properties view
You will rarely need to worry about this one
Slide 60
Slide 61
Slide 62
Slide 63
Slide 64
Slide 65
Slide 66
Slide 67
Slide 68
Slide 69
Slide 70
Slide 71
Slide 72
Slide 73
Slide 74
Slide 75
Slide 76
Slide 77
So far
Demonstrated defining Ecore metamodels
Demonstrated creating models that conform to
an Ecore metamodel using
The reflective tree-based editor (same workspace)
The generated tree-based editor (requires new
instance of Eclipse)
Slide 78
Slide 79
GMF
Slide 80
Slide 81
Slide 82
Slide 83
Additional Models
GMF uses 3 additional models to specify this
extra information
.gmfgraph: Defines the shapes involved the editor
e.g. the editor will contain rectangle and diamond nodes,
and connections
Slide 84
Slide 85
Slide 86
GMF Challenges
The GMF-specific models are notoriously hard
to get right
The metamodels they conform to are large
Validation is not great (you may just end up with
errors in the generated code or - even worse with runtime exceptions in your editor)
Slide 87
EUGENIA
Slide 88
Eugenia
A tool that simplifies the development of GMF-based
editors
Information about the graphical syntax of the language
is embedded in the metamodel using readable
annotations
Validation constraints (in EVL) catch common mistakes and
provide sensible feedback
Slide 89
Slide 90
Slide 91
Eugenia
Demonstrated only a small subset of the
supported annotations
Complete list of annotations
http://eclipse.org/epsilon/doc/articles/eugeniagmf-tutorial/
Slide 92
Slide 93
Slide 94
Slide 95
Slide 96
Slide 97
Slide 98
Slide 99
Slide 100
Slide 101
Slide 102
Slide 103
Slide 104
Slide 105
Slide 106
Slide 107
Polishing Transformations
Eugenia provides support for fine-tuning the
generated editor through polishing
transformations
Optional in-place transformations that can be placed
next to your .emf metamodel
Modify the GMF-specific models generated by
Eugenia
2 transformations
Ecore2GMF.eol: Can modify the .gmfgraph, .gmfmap
and .gmftool models
FigGmfGen.eol: Can modify the .gmfgen model
Model Driven Engineering
Department of Computer Science
Slide 108
Ecore2GMF.eol
// Add bold font to action labels
var actionLabel = GmfGraph!Label.all.
selectOne(l|l.name="ActionLabelFigure");
actionLabel.font = new GmfGraph!BasicFont;
actionLabel.font.style =
GmfGraph!FontStyle#BOLD;
Slide 109
Slide 110
Advanced Eugenia
Using images instead of shapes
http://eclipse.org/epsilon/doc/articles/eugenia-nodes-withimages/
Phantom nodes
http://eclipse.org/epsilon/doc/articles/eugenia-phantomnodes/
Slide 111
Graphiti
www.eclipse.org/graphiti
Slide 112
Lecture Summary
Explored the Eclipse Modelling Framework
Defining metamodels using Ecore
Creating models that conform to Ecore metamodels
Reflectively
Through a dedicated tree-based editor
Slide 113