emf.edit: a story of adapters

47
EMF.Edit A Story of Adapters Mikaël Barbero Obeo Eclipse Con North America 2014 March 20, 2014 © John Wilhelm http://500px.com/photo/59208448

Upload: mikaelbarbero

Post on 14-Jan-2015

405 views

Category:

Technology


0 download

DESCRIPTION

Slides from my talk at Eclipse Con North America 2014 (https://www.eclipsecon.org/na2014/session/emfedit-story-adapters) So you need to build a Java application for desktop, mobile or web? You already know that EMF could be helpful in many ways because it handles the burden of writing the data classes (entities) and provides RESTful serialization of those data? Yeah, that is perfectly correct. But how does it help you with changing, or editing, your data? What is the point behind the so-called EMF.Edit framework? During this talk, you will learn how to build the foundations for a rich client application in any widget toolkit (SWT, JavaFX...). Among other things you will learn how to customize the generated EMF editor without messing up with the generated classes. You will learn how the content and label providers are working under the hood to help create your own beautiful, robust and maintainable applications. By the end of this talk you will finally untangle the gordian knot between Adapters, ItemProvider, AdapterFactory, ItemProviderAdapterFactory, AdapterFactoryLabelProvider, AdapterFactoryContentProvider, etc. This talk is dedicated to EMF rookies who know EMF as a generator of JavaBeans on Steroids and want to know more about the steroids themselves (the Adapter framework, the ItemProvider framework and the amazing helper classes around those two). This talk will be full of sample code and demo. All of this material is available on Github https://github.com/mbarbero/econ-na-2014-emf-edit.

TRANSCRIPT

Page 1: EMF.Edit: a Story of Adapters

EMF.EditA Story of Adapters

Mikaël BarberoObeo

Eclipse Con North America 2014March 20, 2014

© John W

ilhelm http://500px.com

/photo/59208448

Page 2: EMF.Edit: a Story of Adapters
Page 3: EMF.Edit: a Story of Adapters

Super Java Beans

© Rangizzz http://500px.com/photo/30648317

Page 4: EMF.Edit: a Story of Adapters

On Steroids© Max Ellis http://500px.com/photo/57968110

Page 5: EMF.Edit: a Story of Adapters

© Rangizzz http://500px.com/photo/43660830

Page 6: EMF.Edit: a Story of Adapters

Today’s Workout Routine

Connecting the Viewer

Changing the Labels

Changing the Content

Page 7: EMF.Edit: a Story of Adapters

Connecting the viewers

Exercise 1

Page 8: EMF.Edit: a Story of Adapters
Page 9: EMF.Edit: a Story of Adapters

Model View

Controller

Page 10: EMF.Edit: a Story of Adapters

Listening for Reacting to

CHANGES

Page 11: EMF.Edit: a Story of Adapters

notifies

adapts

Notifier Adapter

Listener pattern Notifier is the observable and Adapter is the observer

Page 12: EMF.Edit: a Story of Adapters

5

Notification Message from the Observable to the Observer

Page 13: EMF.Edit: a Story of Adapters

TreeViewer

Chain of notifications Explains the importance of calling dispose()

Adapter Factory Content

& Label Provider

Item Provider Adapter Factory

Item ProviderEObject

Page 14: EMF.Edit: a Story of Adapters

Update or Refresh Or how to be smart when notifying the viewer

Page 15: EMF.Edit: a Story of Adapters

TreeViewerAdapter

Factory Content & Label Provider

Item Provider Adapter Factory

Item ProviderEObject

#notifyChanged

Update or Refresh Or how to be smart when notifying the viewer

Page 16: EMF.Edit: a Story of Adapters

Provider type Singleton

Book Item

Provider

Book

Book Book

Page 17: EMF.Edit: a Story of Adapters

Provider type Stateful

Book Item

ProviderBook

Book

Book

Book Item

Provider

Book Item

Provider

Page 18: EMF.Edit: a Story of Adapters
Page 19: EMF.Edit: a Story of Adapters

TreeViewer

Composed Adapter Factory Look for the proper adapter factory for each type of object

Item Provider Adapter Factory

Item Provider Adapter Factory

Item Provider Adapter Factory

Adapter Factory Content

& Label Provider

Item Provider Adapter Factory

Item ProviderEObject

Page 20: EMF.Edit: a Story of Adapters
Page 21: EMF.Edit: a Story of Adapters

Code is Available

https://github.com/mbarbero/econ-na-2014-emf-edit

Tags demo1 and demo2

Page 22: EMF.Edit: a Story of Adapters

Changing the Labels

Exercise 2

Page 23: EMF.Edit: a Story of Adapters

XXXItemProvider#getText(Object) Easy

Page 24: EMF.Edit: a Story of Adapters
Page 25: EMF.Edit: a Story of Adapters

src

src-gen

Generation gap pattern Treat generated code as byte code

Page 26: EMF.Edit: a Story of Adapters

Item

Book Periodical BookOnTape

Video Cassette

Page 27: EMF.Edit: a Story of Adapters

TreeViewerAdapter

Factory Content & Label Provider

Item Provider Adapter Factory

Item ProviderEObject

Decorators of AdapterFactory and ItemProvider

Page 28: EMF.Edit: a Story of Adapters

TreeViewer

Decorators of AdapterFactory and ItemProvider

ItemAdapter

Factory Content & Label Provider

Item Provider Adapter Factory

ItemItem ProviderEObject

Page 29: EMF.Edit: a Story of Adapters
Page 30: EMF.Edit: a Story of Adapters

Code is Available

https://github.com/mbarbero/econ-na-2014-emf-edit

Tag demo3

Page 31: EMF.Edit: a Story of Adapters

Changing the Contents

Exercise 3

Page 32: EMF.Edit: a Story of Adapters

XXXItemProvider#getChildren(Object) Easy

Page 33: EMF.Edit: a Story of Adapters
Page 34: EMF.Edit: a Story of Adapters

TreeNode

Tree Model Wrap EObjects

EObjectdata

Page 35: EMF.Edit: a Story of Adapters

TreeViewer

Tree Model Wrap EObjects

ItemAdapter

Factory Content & Label Provider

Item Provider Adapter Factory

Item ItemItem ProviderEObject

Page 36: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

EObjectEObject

EObject

Page 37: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

Tree Node

Tree Node

Tree Node

Page 38: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

Tree NodeItem Provider

Tree NodeItem Provider

Tree NodeItem Provider

Page 39: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

EObject ItemProvider

Page 40: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

EObject ItemProvider

Page 41: EMF.Edit: a Story of Adapters

Beware of too many notifications Make your item providers stateful

Page 42: EMF.Edit: a Story of Adapters
Page 43: EMF.Edit: a Story of Adapters

Code is Available

https://github.com/mbarbero/econ-na-2014-emf-edit

Tag demo4

Page 44: EMF.Edit: a Story of Adapters

Connecting the Viewer

Changing the Labels

Changing the Content

Recap

Page 45: EMF.Edit: a Story of Adapters
Page 46: EMF.Edit: a Story of Adapters

Q & A

Page 47: EMF.Edit: a Story of Adapters

Mikaël Barbero [email protected] +Mikaël Barbero @mikbarbero

Obeo http://www.obeo.fr