35
Chetan Kumar K, RBEI jointly with Annamalai C, ANCiT

EMF - The off beat path

Embed Size (px)

DESCRIPTION

This is a presentation of EMF from the ground up during Eclipse India Summit, Bangalore July 2009. This was a joint session from me and Annamalai, ANCiT.

Citation preview

Page 1: EMF - The off beat path

Chetan Kumar K, RBEIjointly with Annamalai C, ANCiT

Page 2: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

In-memory dbase contentD-

Base

UI display

What is a model ???

That is a model!

Page 3: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

What is model ???

Placeholder of data Can “get” and “set” data

Get data

Set dataGet dataData

In memory representation of data

Can be derived from a design

Page 4: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

… and so on

Will you spend time writing each class ??

Map design and code (model)

PIM PSM

Or be smart and generate them ??

UML Java

Page 5: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

PIM Generator Model

Code Generation Engine

Code generation templates

PSMPSM

Typical code-generation flow

Page 6: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF a code generator. EMF is one such code-generator Let’s you generate concrete classes based on a design

(UML)

Let’s look at an example…

Page 7: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

PIM(ecore)

Generator Modelgenmodel

EMFCode Generation

Engine

Code generation Templates

(JET)

PSM(Java)

Code generation flow – EMF way

Page 8: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Tap along guys…

First look of EMF as a code-generator…

Page 9: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

The complete Example UML

Page 10: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Properties of (E)Attribute

Property Meaning

Volatile No associated storage (value can be calculated)

Transient Attribute isn’t persisted

Changeable Value can be changed or not

Unsettable Find out if an attribute was touched

Default value Literal

Default value assigned when containing class is instantiated

EType Data type of attribute

Page 11: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

M-V-C architecture thru EMF

Page 12: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

…EMF first impressions. EMF generates code – will it steal my job!

EMF generates UI stuff – why pay a UI developer ?

Oh god! Something new – too much learning curve

Should I learn “Modeling” or write code now ?

Points 3, 4 courtesy Ed Merks

It will be great if these points are myths … wat say ?

Page 13: EMF - The off beat path

EMF.Edit

Control how model elements are displayed, edited.

Page 14: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit – bird’s eye view.

Contains UI Providers for each Model Element.

Content Provider

Label Provider

Property Source

Item Provider

Generated implementation for different providers

Page 15: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit control flow – Content Providers

“+” clicked

Item provider code

eGet api calls

Generated api getter(s)

Page 16: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit control flow – Label Providers

Item provider code

eGet api callsGenerated

api getter(s)

Page 17: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit control flow – Property Source

Tree item selected

Item provider code

Individual feature’s property descriptor

built

Property descriptors

Page 18: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit providers – one for all, all for one Content, Label, Image, and Property source

providers all through one provider instance!!

Now that’s called … convenience.

Page 19: EMF - The off beat path

EMF.Edit commands

Command based model editing support

Page 20: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit CommandsCommand based editing of model instances

Model object

Editing domainUI display

“Set” event as

Command Command stack

setXXX()

undoable

Page 21: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit – How do I create/use Commands ?

Model object

EMF Editing Domain

•Contains command stack

•Factories to create commands

Page 22: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit – commands, a deeper look

Command interface Existing Command implementations

Do you need to implement this interface ??

Page 23: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF.Edit – “Change… is here!”Should I have one command per operation ?

Can I “record” changes done to a model ?

Oooo yess!!

Works on change notofications given on each operation

ChangeRecorder recoreds these notifications from individual setters. Hence, bulk undo is possible

Can I perform many operations in one command ?

Page 24: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Should I always generate EMF.xxx code ?

Nope … can work with “Dynamic EMF” Ecore – instantiate model (load) – edit – persist … is possible

Responsible code: EMF Reflective API, EMF Reflective Item Providers

Page 25: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Model xml / xmi

loadsave

UI display

What after you edit ?? – can ya persist ?

Page 26: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF serialization

Model object

EMF Resource

EMF Resource Set

xml / xmi

Page 27: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Load and save flows

Model object

xml / xmi

loadsave

EMF Reosource

Typical code snippet:

Page 28: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

EMF Serialization – behind the scenes

•EAnnotations stores mapping b/w XML and Ecore

•Any model element can have EAnnotations

Page 29: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Can I directly persist EMF Objects into dbase ?

Yes, u can – using EMF Teneo (http://www.eclipse.org/modeling/emf/?project=teneo)

Create HbDataSt

ore

Create Hibernate Session,

Transaction

Begin Transaction

Create EMF Model root

object, make it persistent

Create sub-tree under

persistent rootCommit Tx

Page 30: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Get all students aged > 5

Model Navigation and search

Isn’t there a better way than loops ?Can’t I “Query” an EMF model ??

The cool “Query way”

Page 31: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

In the end… what is EMF ?

•Code generator based on a design (UML)

•Means of Java XML binding with Inbuilt persistence mechanism

•Command based model editing support, with generated item providers

•All in all, a base for applications based on MDA

Page 32: EMF - The off beat path

EMF Transaction

Thread-safe editing of a single Model InstanceTransaction style editing of model instances

Page 33: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

Model editing through multiple threads

Model object

Thread 1

Change name :

“Jimmy Bend”

Thread 2

Change name

“James Bond”

Model objectname: Harry Potter

name: ???

Page 34: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

“A mind once stretched by a thought never regains its original dimensions”

Page 35: EMF - The off beat path

Chetan Kumar K | Annamalai C | Eclipse India Summit, Bangalore, 17th July 2009

References EMF newsgroups: http://www.eclipse.org/newsportal/thread.php?

group=eclipse.tools.emf

EMF book: Eclipse Modeling Framework by Ed Merks et.al

EMF Refcard on DZone: http://refcardz.dzone.com/refcardz/essential-emf

Articles on Dynamic EMF - IBM developerWorks (http://www.ibm.com/developerworks/library/os-eclipse-dynamicemf/)

- devX.com (http://www.devx.com/Java/Article/29093/0/page/1 )

Blogs: http://tweakeclipse.blogspot.com/ http://eclipseo.blogspot.com/ and many more!!