Thursday, October 18, 2012

Enabling UUIDs in an EMF ECore model

Enabling UUIDs in an EMF ECore model

A while back we ran into the need to start using UUIDs in our ECore models. Googling a bit led me to this nice blog on the topic. But still one little piece of the puzzle was missing, so here I go with the full recipe and example code as well.

Update: The above link is broken, try this instead!

Adding UUIDs to your favorite model

We start out using the classic Library example. 
  1. Get started by cloning it from here - checkout the "master" branch.
  2. Open the /emf.uuid.library.example/model/emf.uuid.library.example.genmodel
  3. Generate All code
  4. Run the editor and create an example library model with some elements and save it
  5. Open the save library with Text Editor and note how the references are stored:

<?xml version="1.0" encoding="UTF-8"?>
<emf.uuid.library.example:Library xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:emf.uuid.library.example="https://github.com/fredrikattebrant/emf.uuid.library.example/1.0" name="The library">
  <writers books="//@books.0" name="Fredrik Attebrant"/>
  <books author="//@writers.0" title="Using UUIDs in ECore models"/>
</emf.uuid.library.example:Library>
  1. Now, to add support for using UUIDs instead, open the genmodel and select the Library element
  2. Set the Model > Resource Type property to XMI (btw, this was the missing piece in the recipe...)
  3. Regenerate the Model code
  4. Add org.eclipse.emf.ecore.xmi to the plug-in dependencies
  5. Follow the steps described in the blog:
    1. Create a LibraryResourceImpl class (Override the useUUIDs() method)
    2. Create a LibraryResourceFactory
    3. Hook into the org.eclipse.emf.ecore.extension_parser extension point
  6. Generate All code
  7. Run the Library Editor again
  8. Open the previously save library model
  9. Make a change and save the model
  10. Open it with Text Editor again and note how all elements now have UUIDs
  11. Note how references are now stored using the UUID of the referenced elements:
<?xml version="1.0" encoding="UTF-8"?>
<emf.uuid.library.example:Library xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:emf.uuid.library.example="https://github.com/fredrikattebrant/emf.uuid.library.example/1.0" xmi:id="_sQQSEBj-EeKqFILuf-WxiA" name="The UUID library">
  <writers xmi:id="_sQQSERj-EeKqFILuf-WxiA" books="_sQQSEhj-EeKqFILuf-WxiA" name="Fredrik Attebrant"/>
  <books xmi:id="_sQQSEhj-EeKqFILuf-WxiA" author="_sQQSERj-EeKqFILuf-WxiA" title="Using UUIDs in ECore models"/>
</emf.uuid.library.example:Library>

You'll find the example library models in the "librarytests" project and in the uuid branch, you'll find the completed example with UUIDs enabled.

Happy UUID-based modeling!

References


Monday, April 2, 2012

EclipseCon 2012

EclipseCon2012 Cover

This year's EclipseCon was especially exciting because my colleague Anders and I had a talk accepted and was one of a few highlighted sessions.

Our talk was about sharing our experiences of migrating one of FindOut's tools to the new Rich Client Platform "RCP 2.0" in Eclipse 4.2:



Here are the highlights from the conference:

Monday:

The conference started out with an excellent tutorial on writing rich client applications with Eclipse RCP 4.x by Kai Toedter. He also showed that the default SWT rendering engine in the platform can be replaced with Swing. He used the Napkin theme for his contacts demo. Very impressive!


Tuesday:

Tom Schindl explained the new application platform and showed how to easily pool resources and a locale support service that he connected to google translate. The audience was asked for a language to translate to, and without restarting the application "Hello World" was switched to "Hallo Verden" (Norwegian). Impressive!

Brian de Alwis showed how to style your 4.x application with CSS. He also demoed the nifty CSS Spy and editors. For us who had little knowledge of CSS this tool came in real handy.

Alexander Nyßen gave a comprehensive overview and history of GEF. He also explained GEF4 and the main priorities to introduce there. We were especially glad that one of the bullets was to migrate GEF to use the new 4.x application platform.

Wednesday:

e4 compatibility layer sketch
Figuring out the compat layer
Tom Schindl talked about e(fx)clipse which is a distribution of Eclipse for creating JavaFX applications. He also showed that the default SWT rendering engine in can be replaced with JavaFX.

After lunch it was time for us to present.  We were happy to see that we had about 60-70 attendees in the room. The presentation and demo went very well and we had a very good discussion with the audience during the Q/A.
Eclipse 4 BOF signup
In the evening we attended the e4 BOF which was well attended with all the key people from development and a number of users. One interesting topic was how the solve the problem of having multiple dependency injection frameworks. One example is that Xtext uses Guice. It was also noted that 4.2 is lacking a documented API, something that will be addressed in 4.3. Many of the common UI components such as the Properties view, the Project Explorer and the Preference dialog need to be migrated to the new platform services.




Thursday:

Eclipse 4 meets CDO - inspiring demo of what you can do with the modeled application. Since the application model is implemented using EMF, CDO can be used to share it between multiple users. Think instant content sharing and collaboration using the application model.

Wrap-up session
In the closing session it was revealed that the conference had 650 attendees with 360 of them first-timers. 36 countries and 41 US states were represented. There were 2972 complaints on the WiFi according to Mike Milinkovic. All of this was washed down with almost 7000 beers.

One valuable thing for us was meeting and mingling with everyone including other swedes from companies such as Ericsson, Sandvik, IAR and Oracle...

It was also great to meet the e4 team face to face. We would especially like to thank Remy Suen for fixing a bug that we ran into when migrating our application.

Finally, a special thanks to the Eclipse Foundation for yet another great Eclipse conference!

References