Eclipse und EMF'Edit Tutorial - PowerPoint PPT Presentation

1 / 26
About This Presentation
Title:

Eclipse und EMF'Edit Tutorial

Description:

Chair Software Design and Quality. Institute for Program Structures and Data ... ItemProviderFactory Deja vu. Where do the item providers come from? ... – PowerPoint PPT presentation

Number of Views:221
Avg rating:3.0/5.0
Slides: 27
Provided by: K2169
Category:
Tags: emf | deja | eclipse | edit | tutorial | und | vu

less

Transcript and Presenter's Notes

Title: Eclipse und EMF'Edit Tutorial


1
Eclipse und EMF.Edit Tutorial
Steffen Becker (sbecker_at_ipd.uka.de)
2
Eclipse
  • Eclipse SDK is in fact two parts
  • Eclipse RCP
  • Eclipse JDT
  • When programming Eclipse plugins most of the work
    deals with RCP and related plugins
  • Examples from the PCMBench
  • Tabbed Property Sheets
  • EMF
  • GEF
  • Actions
  • Resource Plugin
  • Workbench

3
Eclipse Plugin Concept
  • Eclipse RCP defines the concepts of Extensions
    and Extension Points
  • Extension Points are point where functionality
    can be added by other plugins
  • Extensions contribute functionality to extension
    points
  • Plug and Socket Icons

4
Reading Code
  • When reading plugin code, take a look at
    extensions
  • Extensions often declare a implementing class for
    the added functionality
  • Look in the extension point docu to find out
    about the semantics

5
Examples
  • Go to Eclipse and look at examples in the
    PCMBench
  • Hands-on demo
  • Ask, if anything seems unclear

6
Eclipse EMF
  • EMF can be regarded as EMOF implementation
  • Code generation facilities from ECORE to
  • Model code
  • Editor support code (platform independent)
  • Sample Eclipse Editor (platform dependent)
  • Unit test stubs
  • Optionally OCL constraint checks, requires
    modified generator

7
EMF Model code
public interface Book extends EObject String
getTitle() void setTitle(String value) int
getPages() void setPages(int value)
public class BookImpl extends EObjectImpl
implements Book ... protected static final
int PAGES_EDEFAULT 0 protected int pages
PAGES_EDEFAULT public int getPages() return
pages public void setPages(int newPages)
int oldPages pages pages newPages if
(eNotificationRequired()) eNotify(new
ENotificationImpl(this, Notification.SET,
..., oldPages, pages)) ...
8
References
public void setAuthor(Writer newAuthor) Writer
oldAuthor author author newAuthor
if(eNotificationRequired()) eNotify(new
ENotificationImpl(this, ...))
9
References
public Writer getAuthor() if (author ! null
author.eIsProxy()) Writer oldAuthor
author author(Writer)eResolveProxy((InternalE
Object)author) if (author ! oldAuthor)
if (eNotificationRequired()) eNotify(new
ENotificationImpl(this, Notification.RESOLVE
, ...)) return author
10
So much to it
  • There is more about EMF Generator
  • Examples
  • Factories
  • Switch Classes
  • Adapter Factories
  • Refer to the EMF bible or online tutorials or
    links in SDQ wiki
  • Lets have a look at code again
  • Questions?

11
EMF Edit
  • EMF Edit supports writing editors for EMF Models
  • What is needed for this?
  • GUI Support
  • Observer Pattern
  • Labels
  • Model part of the MVC pattern (for list boxes,
    tables, etc)
  • Property Sheet support
  • Commands
  • For Undo/Redo-Editing
  • Well look at all of them now

12
Observer
  • We have seen this in the model code already
  • Interface Notifier
  • List of observer is called adapter
  • Reasons for this name given soon

13
Observer
  • listeningAdapter new EContentAdapter()_at_Overri
    de
  • public void notifyChanged(Notification
    notification)
  • super.notifyChanged(notification)
  • if (notification.getFeature().equals(attribute)
    notification.getEventType()
    Notification.SET)
  • doSth()
  • emfObject.eAdapters().add(listeningAdapter)

14
Label
  • Label need mainly two methods getText and
    getLabel
  • Interface IItemLabelProvider
  • Instead of adding IItemLabelProvider to the model
    class directly, a different class is used

ItemProviderAdapter
EMFModelObject
EMFModelObject
EMFModelObjectItemProvider
EMFModelObject
IItemLabelProvider
15
ItemProviderFactory
  • Where do the item providers come from?
  • A factory is generated for thisEMFModelPackage
    ItemProviderAdapterFactory
  • The factory always provides ItemProviderAdapter
  • Pass in a known EMFModelObject of Package
    EMFModelPackage

xxItemProviderAdapterFactory
ltltcreategtgt
EMFModelObject
EMFModelObject
EMFModelObjectItemProvider
EMFModelObject
IItemLabelProvider
ItemProviderAdapter
16
Eclipse Labels
  • IItemLabelProvider is Eclipse independent
  • ILabelProvider is needed for the Eclipse GUI
    elements
  • Result Another adapter is needed
  • AdapterFactoryLabelProvider converts
    IItemLabelProvider into ILabelProvider

ILabelProvider
AdapterFactoryLabelProvider
xxItemProviderAdapterFactory
EMFModelObject
17
Delegation
IContentProvider
IContentProvider
DelegatingAdapterFactoryContentProvider
AdapterFactoryContentProvider
  • Delegation is the standard method to change
    behaviour while keeping the interface
  • Especially, if some participants are generated
  • You only need the capability to change the
    factory. Sometimes this can be done via
    inheritance and overriding

18
Content (for Listboxes, TreeControls, )
  • Content needs methods to get the structure
    getParent, getChildren,
  • Interface IItemContentProvider
  • Again, instead of adding IItemContent Provider to
    the model class directly, a different class is
    used
  • The idea is to use the same adapter as before

ItemProviderAdapter
EMFModelObject
EMFModelObject
EMFModelObjectItemProvider
EMFModelObject
IItemContentProvider
19
ItemProviderFactory Deja vu
  • Where do the item providers come from?
  • A factory is generated for thisEMFModelPackage
    ItemProviderAdapterFactory
  • The factory always provides ItemProviderAdapter
  • Pass in a known EMFModelObject of Package
    EMFModelPackage

xxItemProviderAdapterFactory
ltltcreategtgt
EMFModelObject
EMFModelObject
EMFModelObjectItemProvider
EMFModelObject
IItemxxxProvider
ItemProviderAdapter
20
Eclipse Content
  • IItemContentProvider is Eclipse independent
  • IContentProvider (or special subclasses) are
    needed for the Eclipse GUI elements
  • Result Another adapter is needed
  • AdapterFactoryContentProvider converts
    IItemContentProvider into IContentProvider

IContentProvider
AdapterFactoryContentProvider
xxItemProviderAdapterFactory
EMFModelObject
21
Now it becomes boring
  • The same is true also for
  • IEditingDomainItemProvider
  • IStructuredItemContentProvider
  • ITreeItemContentProvider
  • IItemLabelProvider
  • IItemPropertySource

22
PropertySources
  • public interface IItemPropertySource
  • /
  • This does the same thing as
  • IPropertySource.getPropertyDescriptors.
  • /
  • List getPropertyDescriptors(Object object)
  • /
  • This returns the property descriptor with
    the given ID.
  • /
  • IItemPropertyDescriptor getPropertyDescriptor(
    Object object, Object
    propertyID)
  • /
  • This returns the value to be edited.
  • /
  • Object getEditableValue(Object object)

23
EditingDomain/Commands
ResourceSet
Resource
Resource
Command
Command-Stack
Model-Instance
  • EditingDomains contain a CommandStack and a
    ResourceSet
  • Commands can be executed via the command stack
    with undo/redo support
  • Commands can be created using the EditingDomain
    as factory or directly

24
TransactionalEditingDomain
ResourceSet
Resource
Resource
Command
RO wo/ Transaction
Command-Stack
Model-Instance
  • TransactionalEditingDomain ensure consistent
    multiple access
  • Writing wo/ transaction results in an exception
  • For reading a transaction is optional
  • There is a registry of all TransactionalED
  • Important RecordingCommand

25
RecordingCommand
  • RecordingCommand recCommand new
    RecordingCommand(editingDomain)
  • _at_Override
  • protected void doExecute()
  • element.eSet(attribute, valueText.getText())

Also note the use of InnerClasses! This is very
common in Eclipse GUI and Command Programming
26
Hands-on
  • We now take a tour through the code again
  • Also lets define code to review
  • TabPropertySheets
  • CommonNavigatorView
  • Some RCP integration classes
  • Wizard
  • ProjectNature
Write a Comment
User Comments (0)
About PowerShow.com