Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Archive for March, 2011

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

Ignite Talks on Persistency Frameworks: EMFStore, 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 25th, 2011Up and running faster… whose idea was that?

Another EclipseCon has come and gone.  As an Eclipse user, community member, contributor and committer, EclipseCon is a chance for me to make new contacts, renew old friendships and help payoff my beer debt.  There are many people who helped make EclipseCon a great event.  The program chair (Chris Anz… no wait… Aniz.. Aniszczyk!), the program committee, conference chair (Donald Smith), the foundation staff (See bug 300500) and the wonderful people at MeetGreen.  However, one of the most important groups at EclipseCon are the sponsors. They’re the ones who give us all that free beer at 7:00pm.

EclipseSource was a sponsor as well this year, and instead of sponsoring something boring like beer at 7:00pm we sponsored running at 7:00am. I’m sure this seemed like a great idea to the suits (that would be Jeff and Jochen) icon smile Up and running faster... whose idea was that?

In all seriousness, thanks to everyone who came out for the early morning runs.  We had between 15-20 most mornings (except for Wednesday when it was pouring… we only had 6).  For those of you who think that buying a beer is the only way to get a committer to agree to fix  your bug, you should try running instead.  Committers will agree to almost anything to get you to stop asking question when they are completely out of breath icon wink Up and running faster... whose idea was that? .

I hope to see you all next year!

5547998031 71c0a520fc z Up and running faster... whose idea was that?

on Mar 25th, 2011Eclipse Runtime out-of-the-box EclipseCon 2011 slides

Today I did a talk at the EclipseCon 2011 which was entitled “Eclipse Runtime out-of-the-box“. With this talk I introduced the EclipseRTP project. So, if you missed it here are the slides icon wink Eclipse Runtime out of the box EclipseCon 2011 slides

on Mar 23rd, 2011p2, 10 common pitfalls and how to avoid them

On Tuesday, Pascal and I presented “p2, your savior or your achilles heel? Everything an Eclipse team needs to know about p2” where we talked about the 10 most common pitfalls developers face when using p2. More importantly, we talked about how you can avoid them.

For those of you who attended the talk, thank-you.  I hope you learned something.  For those of you who could not attend, I’ve attached the slides here.

on Mar 23rd, 2011EclipseCon Excercise update

Big thanks to all  runners who keep showing up for the EclipseCon run each morning. Particularly the brave bunch running in the rain today!

Join us tomorrow at 7am in the Hyatt Lobby (rain or shine) for the last run of the conference.

We will also having a little contest with the chance to win Eclipse.org goodies: (thank you!)

  • two black Eclipse.org long-sleeve shirts
  • two women’s Eclipse.org polo shirts
  • Eclipse.org insulating coffee mugs — battle-tested in arctic Ottawa icon wink EclipseCon Excercise update

EclipseCon 2011 EclipseCon Excercise update

 

on Mar 23rd, 2011EclipseCon Impressions – Tuesday

My highlights on the EclipseCon today were the EMF GWT presentation by Ed Merks, the p2 talk by Ian Bull and Pascal Rapicault and the keynote on Watson by David Gondek:

Ed Merks showed how to use EMF with the Google Web Toolkit. In about a click or two, he had an EMF-based GWT application (or an GWT-based EMF application) up and running. The famous library model application was not only available locally on his demo laptop but also hosted on Google Appspot. It is still available here. Unfortunately Ed did not refresh his running browser instance during the tutorial, although many model updates had been waiting on the server…;)

Ian Bull and Pascal Rapicault presented a bunch of donts concerning p2 in a very entertaining way. I hereby promise, I will no longer unzip features and plugins directly into an Eclipse instance, I will never release with the same version twice or try to edit the p2 metadata icon wink EclipseCon Impressions   Tuesday . Also throwing in 1000+ plugins into the dropin folder seems to be a discouraged practice, at least if you would like to have a speedy Eclipse startup. Seriously, this was a very informative presentation and it showed how to avoid “trouble” with p2, which is in many cases trouble that we caused ourselves.

In his keynote David Gondek explained the mission of Watson and how it works. Today keyword search is widely used, but it comes with the disadvantage of putting the burden of selecting “good” keywords on the user. In general adding more keywords to a search will decrease the quality of the results. Among many interesting statistics, I found the statistics on the top 10 “What is …?” searches in Google particularly interesting. On the first place is the question “What is love?”. Consequently the question “What is autism?” is on the 7th place icon wink EclipseCon Impressions   Tuesday . In contrast to keyword search, Watson uses a comprehensive analysis and reasoning to answer natural language questions. For example Watson has a geographic reasoner which can relate words in terms of the geographic distance. Thereby Watson can even find answers to tricky questions in Jeopardy. The many examples in the keynote provided a lively picture of the problems building the next generation search engine.

 

on Mar 23rd, 2011EclipseCon Impressions – Monday

This is my first blog post under the EclipseSource roof. Thanks for all the greetings and congrats!

I shortly want to summarize my impressions from the EclipseCon yesterday (Monday):

Tutorial: What every developer needs to know about EMF. Since I was one of the authors I am not going to comment on the quality of the tutorial icon wink EclipseCon Impressions   Monday . About 80 people joint the tutorial and the number of participants did not decrease during the 3h tutorial. That should be a good sign. Jonas has blogged the contents of the tutorial here so no need to go into detail.

Efficient, Scalable Notification Handling for EMF. Listening to the changes of huge object graphs in EMF can be tricky, especially if you add adapters to many objects by many different listeners, which only trigger under certain conditions. Currently in EMF you can only register an adapter in general and you cannot specify conditions when the adapter should be notified. This can be a performance issue. The talk showed an event manager for EMF notifications which allows to register listeners including conditions when to notify the listeners. It is really cool that this component exists now, we have already partially developed custom solutions for this problem, now we can use this sophisticated implementation.

Tired of CVS? The talk presented how a streamlined work flow with Git, Gerrit, Mylyn and Hudson could look like. In the work flow a developer uses Mylyn to track requirements and tasks, EGit automatically manages change sets and committing to EGit automatically creates a code review in Gerrit and triggers a Hudson build. Looks like a beautiful new world to me!

Workshop: Tycho Build Conversion I tried to get the EMFStore build running with Tycho and Maven and it worked out pretty good. I did not get the build completed, but I had to leave after 1h. Overall I had the impression that building with Tycho could really be an option and I will definitely go and investigate this further. A good cheat sheet for converting an existing build to Tycho is available here.

Finally I went to the committer reception…meeting people and drinking beer icon wink EclipseCon Impressions   Monday .

 

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.

on Mar 21st, 2011Eclipse Modeling in Germany – now at EclipseSource

I am happy to announce that EclipseSource is finally entering the modeling world and would like to introduce Max and Jonas as our new team members in Munich. Both are well known in the modeling community for leading the Eclipse projects,  EMFStore and EMF Client Platform.

With our expansion to Munich we can now better accommodate our customers in southeast Germany, Austria and Switzerland. But beyond the geographic expansion it is a big step for EclipseSource to enter the world of modeling, as we have been hesitant to get involved deeply with the technology over the last decade.

Two things made us change our minds: EMF’s versatility and the availability of a great team. Max and Jonas have proven their EMF expertise with the EMFStore project and in joint projects with EclipseSource.

Now, you no longer need to hesitate to contact us with your Eclipse Modeling questions and challenges. We are looking forward to it.

on Mar 19th, 2011Why did you close my p2 bug as INVALID?

Have you used p2?  Have you tried to replace plug-in with an updated version, only to find p2  doesn’t find it?  Have you removed an unused plug-in and suddenly Eclipse stopped working?

You’ve probably not only hit these issues, but as a responsible member of the Eclipse community you even filed a  bug about it, thanks.  Why then, did the p2 team close your bug as INVALID?

Join Pascal and I on Tuesday and learn about the 10  most common pitfalls Eclipse developers face when using p2; and more importantly, learn how to avoid them!

screenshot 042 1024x769 Why did you close my p2 bug as INVALID?

© EclipseSource 2008 - 2011