Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Jonas Helming

on Sep 7th, 2011Eclipse Stammtisch Europe

Sorry for the eye catcher, I meant “München” icon smile Eclipse Stammtisch Europe

To shorten the time until EclipseCon Europe, we cordially invite you to the Eclipse Stammtisch München on October 4th. The Stammtisch is always a good opportunity to meet the community in your region and talk about Eclipse and of course, non-Eclipse topics.

If you would like to attend, please register for this event, as we will make a reservation based on the number of registered people. Currently, we plan to meet at Sappralott. But, as the location might change, please provide a valid mail address so that we can notify you about the details.

Based on your feedback from the last Stammtisch, we would like to give people a forum to present interesting things. However, since this is not a democamp, there will be no stage or agenda. People who want to show something can bring their laptop. We will distribute the presenters around the tables and people can walk around to see what they are showing. That means you can present something, you can watch something, but if you are not in the mood, you can just sit there, have a conversation and drink beer icon smile Eclipse Stammtisch Europe

If you want to present, please register as a presenter and send me a short description of what you are planning: jhelming@eclipsesource.com

stammtisch Eclipse Stammtisch Europe

 

on Jun 27th, 2011Target provisioning with Yoxos

Some of you may have seen Yoxos 5 at EclipseCon 2011.  For those who aren’t familiar with it, Yoxos 5 is a tool that enables the creation of a profile that describes your Eclipse installation. Another developer can start the same Eclipse installation by clicking on a .yoxos file. Yoxos will download and install all necessary plugins, set the preferences, connect to the source code repository and even show you the tasks from your bug tracker. These items are continuously updated with changes.  For example,  if you add a new plugin to your daily development environment, all team members will automatically get an update. Ian’s talk at EclipseCon 2011 showed how this can be used to get developers working on an open-source project quickly, e.g. for a “bugday”. The full team service is freely available for open-source projects.

In the latest release, we’ve added another much-requested feature:  the provisioning of target platform definitions. The basic idea is that you can provision target platform definitions with Yoxos and set one target platform to activate by default. The target platform itself can be on an update site, in your workspace or anywhere else. Using a local folder or an Eclipse installation may not make too much sense, unless these sources can be downloaded by other users. You can configure the target definition in the normal way, using the PDE UI. Once you have added it to your profile, it can be used by all developers on the team.

You can activate Target Provisioning in the launcher from the tab “Workspace Provisioning”

2011 05 03 1116 Target provisioning with Yoxos

Then,  you’ll see a new tab in the application:

2011 05 03 1117 Target provisioning with Yoxos

Once you have set your target platform definitions, you can import them from your IDE into a profile (via the magnet button).

2011 05 03 1119 Target provisioning with Yoxos

By checking one of the target definitions in the table, you’ve set the default that will be activated on start-up of the installation.

2011 05 03 1120 Target provisioning with Yoxos

Note that you should remove the target platform definition file from plugins that are provisioned by the team provider. Otherwise you will get the the same target platform twice, once provisioned by the SCM, once provisioned by Yoxos. The Yoxos provisioned target definition always has a postfix “provisioned by Yoxos” to distinguish them. In general, moving the target definition out of your workspace might be good practice, as changes to the target platform can then be managed by the same person who configures the Yoxos profile.

You can give Yoxos 5 a test drive – visit http://eclipsesource.com/yoxos5. Let us know what you think about Yoxos and target provisioning.

on May 10th, 2011And the winner is…

The results of the evaluations for the EclipseCon 2011 talks and tutorials is out. I thought it would be interesting to know which talks and tutorials were rated best. So I took the data from the PDF and did a little calculation.

Disclaimer / Government Health Warning: Any of these calculations may or may not be statistically significant.  They may include huge biases such as time of day, my personal decisions on how to do it and there might be errors in the data. So be forewarned, this is not an official ranking.

What I did was to count the +1′s, ignore the 0′s and substract the -1′s. The result was divided by the total number of votes resulting in an average value between -1 and 1. A very important decision is the cut point for being excluded from the sample, as there were a lot of sessions with very few votes. Some of them have an average of 1, but with very few votes this is quite arbitrary. So I decided to ignore sessions with less then 25 votes. That does not mean they were not great, I just don’t think it makes sense to include them from a statistical point of view. Further, if the average only differed 1%, I rated sessions equally to the next higher one.

To make a long story short, here are the results:

Keynotes

  1. What is Watson? – 0.96
  2. On Apache Hadoop – 0.92
  3. Java Renaissance – 0.57

Top Five Talks

  1. Case Study: NASA Ames uses Eclipse RCP for situational awareness of remote… – 0.98
  2. Modularity Wars Episode IV: A New Hope – 0.95
  3. Catch that bug before it happens! Improve code quality with static analysis – 0.94
  4. Put it in reverse: using eclipse to understand code that has already been… – 0.92
    Android development with Eclipse
    Building web apps with EMF and GWT
    A busy year for the Eclipse platform
  5. Cross-platform mobile development with eclipse - 0.91
    Dawn-Rise of the collaborative user interface

After the first 5 places there is a huge group of almost equally great talks between 0.9 and 0.8. So this is really only the tip of the iceberg.

Top Five Tutorials

  1. Hands on with C/C++ IDE - 0.95
  2. Developing Rich Clients with Eclipse 4.x RCP - 0.88
  3. Architecture patterns and code templates for enterprise RCP apps – 0.87
  4. Functional test automation for eclipse apps with Jubula – -0.85
    Style It! The eclipse 4 styling tutorial
    Pragmatic DSL Design with Xtext, Xbase and Xtend 2
  5. What every Eclipse Developer should know about EMF – 0.74

I would also like to mention the following sessions, which had very close to 25 attendees and had a very high ranking:

  • Building a great community for your open source project (23 attendees) – 1.00
  • The business of selling free software (21 attendees) – 1.00
  • Developing Machine Control Systems with eTrice – live demo (24 attendees) – 0.91

Congratulations to the speakers who gave these great talks.  I hope no one feels offended at not being listed and I’d be glad to hear from you if you think there is something wrong or unfair with regards to the method.  And, don’t forget to hold to the disclaimer icon smile And the winner is...

Here is the raw data:

EclipseCon evaluation

on Mar 31st, 2011What every Eclipse developer should know about EMF – Part 2

This is the second part of the tutorial presented at EclipseCon. We’ll be building on the model created in the first part of the tutorial, which you can find  here.   We’ll give you an overview of available technologies through links to several Ignite talks that introduced various frameworks building on EMF.  If you would like to have your framework included, please let me know.

4 EMF API

In this part of the tutorial, we will explore EMF’s API, including the generated code, as well as EMF’s utility classes. Let’s have a look at the generated code first. In the model plugin from our tutorial org.eclipse.example.bowling you will find interfaces and implementations for all entities of the model. A look at the outline of an entity’s interface reveals that it contains getters and setters for the attributes we have defined in the model, as well as access to the references. All entities of the generated EMF model are sub-classes of EObject. EObject contains basic functionality – for example, a change notification mechanism. outline What every Eclipse developer should know about EMF – Part 2 The model plugin contains factories to create model element entities. Please note that the constructor of EObjects is usually not public. Please also note, that factories are used by many frameworks for their functionality, e.g.  deserialization.  Changing these methods successfully requires some careful planning. Let’s use the factories to programmatically create some entities and use their API to modify them. We will use the pre-generated test plugin to run this example code. In this very simple example, we use the BowlingFactory to create a Matchup and a Game, adding a reference to the Matchup and checking the bi-directional update on the Game. tescase01 What every Eclipse developer should know about EMF – Part 2The super class EObjects offers many methods to access an entity in a more generic way. As an example, we will test the containment between Matchup and Game by accessing the EContainer instead of the getMatchup() method. testcaseone What every Eclipse developer should know about EMF – Part 2 EObjects offer reflective access to their attributes using the methods eSet() and eGet(). This can be useful in modifying an entity in a generic way. testcase3 What every Eclipse developer should know about EMF – Part 2 Information about the available EAttributes and EReferences, as well as all additional concepts we have modeled before, can be accessed either through the EClass or through the EPackage. The following test checks whether the only EReference of League is a multiplicity greater than one. testcase4 What every Eclipse developer should know about EMF – Part 2 EMF also supports the validation of  model instances. As an example, we can validate the constraint of the model that a matchup must always consist of two games: testvalidation What every Eclipse developer should know about EMF – Part 2 Finally EMF provides a lot of utility classes. A very important one is EcoreUtil. It is worthwhile browsing through the available methods of EcoreUtil. As an example, we will use the copy method to create a copy of an EObject. tesecoreutil What every Eclipse developer should know about EMF – Part 2

5 Import Sample Solution

Before we continue with the tutorial, please import the sample solution. Please switch to an empty workspace (File => Switch Workspace), select “Import” => ”General” => ”Existing Projects into Workspace”. Please select “exampleSolution.zip” and import all projects. select projects to import 300x282 What every Eclipse developer should know about EMF – Part 2

6 AdapterFactories

For the next steps of the tutorial it is important to understand the concept of AdapterFactories. We will give a quick introduction and you can see this documentation for more information. The basic idea of AdapterFactories is to provide you with an interface IX you need for an arbitrary purpose, e.g. a LabelProvider needed in the UI. EMF generates a lot of these classes for you. To retrieve the right class you can use an AdapterFactoryX, which implements the interface you need. The AdapterFactoryX will retrieve the generated classes using an AdapterFactory. adapterfactories 300x158 What every Eclipse developer should know about EMF – Part 2

7 EMF Data-Management

In the previous sections we have shown how to generate a structured data model with EMF. In a typical application, these data models have to be stored and maybe even versioned or distributed. There are a couple of frameworks that support different use cases. By default EMF provides the ability to serialize EObjects to XMI files. In the following example, we will load EObjects from a file and save them afterwards. EMF also offers commands to make modifications on the model. Commands can be easily undone. In the example we will load a XMI file containing a Tournament. The user can add new Matchups to that Tournament and undo these changes. At the end, the user can save the changes back to the file. For the tutorial, we have prepared an example dialog in the plugin org.eclipse.example.bowling.tutorial, which should be imported from the example solution. You can open this dialog by right-clicking a file and selecting “Tutorial”=>”Open Example Dialog”. After implementing the following two parts of the tutorial, it will look like this: example view 300x134 What every Eclipse developer should know about EMF – Part 2 Everything that is not relevant for this tutorial is implemented in an abstract base class called AbstractExampleDialog. In the subclass ExampleDialog, there are empty method stubs to be implemented in this tutorial. The dialog can be shown in the runtime Eclipse instance by right-clicking on a file and selecting “Open Tournament Example view”. (Please note that for the tutorial we have focused on simplicity over perfect design.)

Please open the class ExampleDialog. We will implement the loadContent method, which is triggered by opening the example view. The purpose of this method is to get a Tournament from the file which is then displayed in the example view.  To keep it simple, we assume that the file contains a Tournament and this Tournament is the first element in the file. You can easily create a file like this with the generated example editor. First we create an editing domain. An editing domain manages a set of interrelated models and the commands that are run to modify them. For example, it contains the stack of all former commands. An editing domain can create a resource, which is a container for storing EObjects. Resources can be saved and loaded and contents can be added to them. In the example we get the first EObject in the resource, assume it is a tournament and make it a member of our superclass. loadContent What every Eclipse developer should know about EMF – Part 2 After loading the content, we will implement a save. This will be triggered by pressing OK in the dialog and will serialize the model and apply all changes to the file. save What every Eclipse developer should know about EMF – Part 2 Now we want to implement the addition of a matchup to a tournament. We will use a command for this. First we create a matchup using the appropriate factory. The factory, by convention has the name of the base package of the model. Then we create a command which adds the newly created matchup to the existing tournament that we retrieve from our superclass. Finally, we run the command on the command stack of the editing domain. addmatchup What every Eclipse developer should know about EMF – Part 2 At this point, the changes will not be reflected in the UI of the dialog, but we will implement the necessary code in the next step of the tutorial. To implement undo, we just need to call undo on the command stack of the editing domain, this will undo the last command. undo What every Eclipse developer should know about EMF – Part 2 Now, start the bowling application and create a XMI file with the example editor. It should contain a Tournament and several Matchups and Games. Please right-click the file and select “Tutorial” => ”Open Example Tournament View”. In this view you can add new Tournaments, undo this operation and save by clicking on “OK”. You can validate the result by opening the file in the Ecore editor. Please note again, that the UI of the View will not be updated yet, but we will initialize the UI also in the next step of the tutorial.

Additional Information

EMFStore – A Model Repository (Server for EMF Model instances)

CDO (coming soon)

8 EMF UI

In this step we will fill the example view with two basic UI elements. First, we will bind the Label on top showing the number of Matchups in the opened Tournament to the model. We will use the notification mechanism to update the Label whenever the number of Matchups changes. Second we will fill the TreeViewer with a list of the Matchups also displaying their Games as children. For updating the Label we will register a listener on the Tournament EObject, which is opened in the view. This listener will always be notified by the EMF runtime if there is a change in the Tournament EObject. initialize listener What every Eclipse developer should know about EMF – Part 2 In the second step we implement the listener itself. In the notify method, we check first whether the change was on the EReference to Matchups and therefore influences the number of Matchups. If this is the case, we update the Label (implemented in the AbstractExampleView). updateNumberOfMatchups What every Eclipse developer should know about EMF – Part 2 Please note that this is how you manually implement listeners. For creating UIs with bi-directional updates between UI elements and data-models, we recommend using data-binding that’s also available for EMF. In Eclipse databinding, you can bind a certain UI element to a certain EAttribute or EReference and it will take care of bi-directional updates.

Finally, we will initialize the TreeViewer to display the Matchups of the current Tournament and their Games as children. A TreeViewer needs three things to be initialized. The ContentProvider is responsible for the structure of the Tree by providing the method getChildren(). The LabelProvider is called to get an Icon and the displayed text for one node. The input of a TreeViewer is the invisible root element of the Tree. The elements displayed in the root of the tree are the children of that element. In our case, the input is the Tournament.

provider 300x103 What every Eclipse developer should know about EMF – Part 2

ContentProvider and especially LabelProvider usually depend on a certain EClass. EMF generates providers for several purposes including Content- and LabelProvider. We will use the AdapterFactory concept explained previously to retrieve the right provider for every element. Finally we set the Input to the Tournament which is currently open.

initializeTreeViewer What every Eclipse developer should know about EMF – Part 2

Now you’ll need to re-start the bowling example application to test the implemented UI features. To modify the appearance of a Label you can simply modify the ItemProvider of the respective class. Let’s modify the LabelProvider for Matchup. To modify the appearance of EObjects in the TreeViewer you can adapt the generated ItemProvider GameItemProvider. In the example, we will show the number of Games contained in a Matchup Game. Mark the method as “generated NOT” to prevent it from being overridden during the next generation.

adaptLabelprovider What every Eclipse developer should know about EMF – Part 2

In the running application, the new LabelProvider is displayed in the Example view as well as in the Ecore Editor:

labelproviderexample What every Eclipse developer should know about EMF – Part 2

As a last step, you should remove all listeners when closing the view. Please note that LabelProvider and ContentProvider are registered listeners on the model, so you should delete them.

Additional UI Frameworks

There are several frameworks for displaying data from an EMF model instance. In this tutorial, the following were introduced in Ignite talks:

9 Additional EMF-based Technologies

In this last part of the tutorial we want to give you a short overview of additional EMF-based technologies for different purposes:

I hope you found the tutorial helpful. In case you have any feedback or you are missing a certain framework or part, please feel free to contact me or leave a comment.

on Mar 22nd, 2011What every Eclipse Developer should know about EMF – Part 1

So this is my first post at the new location. As Jochen announced earlier, Maximilian and me are joining EclipseSource in Munich. We are very happy about this and look forward to the collaboration.

Today, we have presented the Tutorial “What every Eclipse Developer should know about EMF” at EclipseCon. I will blog the tutorial here step by step. You can download a PDF version of this tutorial here.

Foto 300x224 What every Eclipse Developer should know about EMF   Part 1

So let`s get started

Abstract

You did not use EMF before? What is EMF anyway? What is all this modeling stuff about? And who is this Ed guy?

This tutorial introduces the use of EMF and explains the basics. We show how to build a very simple data-centric application based on EMF including the UI. We explain how to define a model in EMF and how to generate code from it. We explore the API of the generated code to create, navigate and modify model instances. We demonstrate how to build an UI based on this model. As an example we build an application to manage a bowling league and tournaments.

In the first step of the tutorial we will create the underlying model of our example application.

To follow this tutorial, please use a (fresh) instance of the Eclipse Modeling Tools Helios for your OS.

Later in the tutorial, we will use this example solution: exampleSolution

Authors:

  • Jonas Helming (Basic Tutorial, EMF CP Ignite), jhelming@eclipsesource.com
  • Maximilian Koegel (Basic Tutorial, EMFStore Ignite), mkoegel@eclipsesource.com
  • Markus Herrmannsdoerfer (Edapt Ignite)
  • Eike Stepper (CDO Ignite)
  • Saurav Sarkar (EMF Query Ignite)
  • Mariot Chauvin (EEF and GMF Ignites)
  • Cedric Brun (EMF Compare Ignite)

 

Table of Contents

1     Introduction

2     Example Model

3     Modeling

3.1      Code Generation

3.2      Model refinement

3.3      Why is this better than writing POJOs?

4     EMF API

5     Import Sample Solution

6     AdapterFactories

7     EMF Data-Management

8     EMF UI

9     Additional EMF-based Technologies

 

1        Introduction

For the question “What is EMF” we borrow the description from the EMF website:

“The EMF project is a modeling framework and code generation facility for building tools and other applications based on a structured data model. From a model specification described in XMI, EMF provides tools and runtime support to produce a set of Java classes for the model, along with a set of adapter classes that enable viewing and command-based editing of the model, and a basic editor.”

It is noteworthy that EMF has also been a stable standard for many modeling technologies.

We suggest using EMF for any structured data model you have to create in Eclipse, especially if it gets stored, displayed and modified in UIs. The basic EMF workflow is very pragmatic; a model is created defined in the Ecore format. Ecore is basically a sub-set of UML Class diagrams. From an Ecore model, you can generate Java code.

ecoreWorkflow1 300x167 What every Eclipse Developer should know about EMF   Part 1

Later in this tutorial we will have two running instances of Eclipse. In the first instance, the “IDE”, we will define the model and generate code from it. The second instance, the “Runtime”, will be started from the IDE and contain instances of the generated model.

idevsruntime 300x123 What every Eclipse Developer should know about EMF   Part 1

2        Example Model

In this tutorial we will create an example model for managing a bowling league and tournaments. A League contains an arbitrary number of Players. A Tournament consists of an arbitrary number of Matchups. A Matchup always contains of two Games. A Game is a list of frames (the score) and is assigned to a certain Player. Finally a Tournament has an Enumeration determining the type of the Tournament.

bowling 300x150 What every Eclipse Developer should know about EMF   Part 1

In the next step, we will show how to create this model and generate code form it.

3        Modeling

We will create our example model in EMF to generate the entity classes for our application. The first step is to create an empty modeling project in your workspace:

1newEmptyEMFProject 300x285 What every Eclipse Developer should know about EMF   Part 12nameProject1 300x172 What every Eclipse Developer should know about EMF   Part 1

The essential part of the modeling project is the model itself, defined in the format “Ecore”. Please create a new “ecore” file in the model folder in your new modeling project. We will name the file “bowling.ecore”:

3newecore 300x285 What every Eclipse Developer should know about EMF   Part 1 4namemodel 300x263 What every Eclipse Developer should know about EMF   Part 1

Click finish to create the model. It will be opened in the default Ecore editor. This editor allows defining Ecore models in a tree-based view. There are several additional possibilities to define Ecore models, including graphical modeling, textual modeling, Java annotations and import from UML tools. We will stick to the default editor in this tutorial and shortly demonstrate the graphical editor for Ecore.

In the tree of the Ecore editor you can create and delete model elements as well as modify the structure of your model via drag and drop. Properties of model elements can be modified in a second view, which opens up on double-click or right-click => “Open Properties View”.

First, give the root package of your new model a name and an URI. This is used to identify the model later on. Name the package “bowling”, set the Ns Prefix to “org.eclipse.example.bowling” and the Ns URI to http://org/eclipse/example/bowling ”:

5namerootpackage 300x156 What every Eclipse Developer should know about EMF   Part 1

Now, we can define our model elements as children of the root package. Please right click the root package and create a new EClass and name it Player.

createPlayer 300x191 What every Eclipse Developer should know about EMF   Part 1

From the context menu of an EClass, you can add EAttributes and EReferences to it. Create an EAttribute and open the Property view for it. The properties of an EAttribute define its name, its data-type and other properties, which we will cover later in this tutorial. Add an EAttribute to the Player, name it “name” and assign the EType “EString” (java.lang.string). Repeat this step and add a second EAttribute named “dateOfBirth” of type “EDate”.

nameattribute 300x239 What every Eclipse Developer should know about EMF   Part 1

EMF models usually build up a structured hierarchy, meaning model element instances, e.g. the Player “Jonas” are contained in a specific container object. This provides a tree-structure, which is useful for navigability and allows for serialization. This tree structure is often referred to as containment tree. In our model, Players are contained in a League. Please note that this also implies that every Player is referenced by exactly one League, thus cannot be part of more than one League. Therefore EMF will automatically take care that a player cannot have more than one league. If you add a player to another league, its reference to the original league vanishes.

leagueplayer What every Eclipse Developer should know about EMF   Part 1

Create a second EClass and name it “League”. To identify the League, also create a EString attribute called name. The next step is to create a EReference between League and Player by right-clicking on the League model element. Name the references “players”. Set the EType of the reference to “Player”. As a League can contain an arbitrary number of Players, set the upper bound to “-1”, equivalent to “many”. Finally set the property Containment to “true” determining that the EReference is a containment reference.

referenceplayers 204x300 What every Eclipse Developer should know about EMF   Part 1After this first model iteration, we can already generate code from it. EMF provides an example editor to create and modify model instances. This allows us, to initially test the created model, before we further refine and add more EAttributes and EReferences in a second iteration to complete the example model.

 

3.1      Code Generation

In this step, we will generate the entities from the Ecore file we have created. Please note that you can regenerate the entities again, if you need to change you model. EMF can deal with simple changes like adding model elements or EAttributes. If you have complex changes, like moving an attribute to another class, you would have to migrate existing instances of the model. This is supported by the EDAPT framework.

To generate entities, we have to create a generator model file first. This file allows configuring properties for the generation, which are not part of the model itself, for example the plugin and subfolder, the source code is generated to. Please create a new generator file in the model folder and select our previously created Ecore as a source model.

creategenmodel 300x285 What every Eclipse Developer should know about EMF   Part 1

nameGenModel 283x300 What every Eclipse Developer should know about EMF   Part 1selectecore 300x255 What every Eclipse Developer should know about EMF   Part 1choosemodel 300x161 What every Eclipse Developer should know about EMF   Part 1In the root node of the generator model, you can set the properties for the code generation. In the tree of the generator model, we can set properties for every generated entity. For the first code generation, we just use the default settings. Based on the generator model, we can now generate the source code. EMF allows generating four different plugins for a defined model:

  • Model: The model contains all entities, packages and factories to create instances of the model.
  • Edit: The edit plugin contains providers to display a model in an UI. For example the providers offer a label for every model element, which can be used to display an entity showing an icon and a name.
  • Editor: The editor plugin is a generated example editor to create and modify instances of a model.
  • Test: The test plugin contains templates to write tests for a model.

To generate the plugins, right click on the root node of the generator model and select the plugin. For our tutorial, please select “generate all”.

Before we look at the generated code, let’s first start the application and create an entity of our model. Please right click on the model plugin and select “Debug as => Eclipse Application”.

Please create a new empty project and a bowling model. This file will contain a serialized version of our model instance.

createproject1 300x248 What every Eclipse Developer should know about EMF   Part 1createbowlinginstance 300x285 What every Eclipse Developer should know about EMF   Part 1namemodelinstance 300x271 What every Eclipse Developer should know about EMF   Part 1

Select League to be the model object. This determines the root object of the model instance we are about to create.

seletcroot 300x227 What every Eclipse Developer should know about EMF   Part 1

The generated editor for model instances works similar to the Ecore editor. Model element instances can be created via a right-click, EAttributes can be modified in the properties view. Please name the League and create two Players. On save, all created instanced are serialized in the XMI file “league.bowling”.

ecore editor 300x148 What every Eclipse Developer should know about EMF   Part 1

3.2      Model refinement

Let`s switch back to our IDE Eclipse environment, complete the model and regenerate the source code. In this second model iteration we will add different type of EReferences, as well as EEnums and Multi-EAttributes. First please add the following classes to the bowling model:

  • Tournament
  • Matchup
  • Game

These classes model the results of bowling tournaments build up a second tree in our model. Therefore we add containment EReferences from Tournament to Matchup and from Matchup to Game. Following the bowling rules, a Matchup consists of two Games (each from one Player). We model this by setting the upper bound and lower bound of the EReference “games” of the EClass Matchup to “2”.

multiplicitytwo 300x189 What every Eclipse Developer should know about EMF   Part 1

Furthermore we defined that the EReference between Matchup and Game is bi-directional. That means, the reference can be navigated from both ends. Therefore we have to create a second EReference from Game to Matchup and bind both EReferences. EMF will take care of the bidirectional synchronization. In other words adding a matchup to a game will automatically add the game to the matchup.

Please add a EReference to Game called “matchup” with the EType “Matchup”. By setting the EOpposite to the EReference “games”, both EReferences are coupled bi-directionally. Note, that the property “Container” will automatically be set to true.

bidirectionalreference 300x198 What every Eclipse Developer should know about EMF   Part 1

The next step is to add a cross-EReference. In contrast to containment EReferences, cross-referenced model elements do not contain each other. In our model we add a cross EReference from Game to Player named “player”. Let both, container and containment properties “false”. An arbitrary number of games can be assigned to a Player now; the Player is still contained in a League.

gameplayerref 300x194 What every Eclipse Developer should know about EMF   Part 1

As a final mandatory step, we will create an EEnumeration for the type of a tournament. A tournament can be of type “Pro” and “Amateur” in our model. Please create a EEnum by right-clicking on the root bowling model package, just like creating a class. Add two EEnum Literals to this EEnum.

enum 300x136 What every Eclipse Developer should know about EMF   Part 1

Please add an EAttribute to the EClass Tournament, name it “type” and set the EType to “TournamentType”.

The extended example model contains more EAttributes and EReferences to be added including all basic types and some special cases as the Multi-Integer EAttribute in Game. Depending on your time, please model the following features:

Player

  • height: EDouble
  • isProfessional: EBoolean

Game

  • frames: EInt, UpperBound = 10

After applying complex changes to the model it is always a good idea to validate it, done with a right-click on the model root in the Ecore editor. Let`s do something wrong in the model and set the lower bound of the EAttribute “games” (in Matchup) to 3. As the upper bound is 2, this model doesn`t make too much sense. This will be detected by the model validation, something which is impossible in plain Java Code.

validation 300x148 What every Eclipse Developer should know about EMF   Part 1

After this model refinement, we will re-generate the code to reflect our changes. Start the runtime Application again and create a second model “tournament”. Add a Matchup and  two Games. To add assign the Games to Players you will have to load the “league” model created before. Select “Load Ressource” from the menu “Bowling Editor” and select the first model file. Now, link the Games to the Players in the properties view.

3.3      Why is this better than writing POJOs?

You might ask, why to use EMF instead of creating the model just writing plain POJOs. Without considering benefits like the generated editor for rapid testing and all additional frameworks available for EMF, let`s look at two very simple and exemplary benefits.

Before we even look at the generated code (we will do that in a minute), let`s consider the amount of code we have just produced. The Eclipse metrics plugin tells us, we have generated over 1000 LOC, while only 150 is part of utility classes. Even very simple code is considered to be worth 1$ per LOC. So we have just earned 1000$ just by clicking some buttons?

locs 300x86 What every Eclipse Developer should know about EMF   Part 1

In the next part, we will explore the EMF API of the code we have just generated. You can follow this blog to get notified about new posts. You can download a PDF version of this tutorial here.

© EclipseSource 2008 - 2011