Categories
Eclipse

Model my PDE!

I’ve been working for quite a while on finding solutions to the problems we are having in PDE as soon as we need to add support for new OSGi headers, to create new editors for cheatsheet files, p2 categories, etc.

Declarative Services tooling is a good illustration of all these problems. As part of the Google Summer of Code 2008, Rafael Oliveira worked on the creation of some cool tooling to help people wanting to use OSGi Declarative Services. This tooling is great, and available in Eclipse Galileo as many of you may know but, unfortunately, it introduces a lot of boilerplate code (Java model of what a DS component is, Java model of what the textual representation of a DS component is, JFace label and content providers, etc.)

Indeed, since day 1 of PDE, despite the fact there is a sort of generic framework behind PDE (undo/redo support for operations done both programmatically or through the UI/text editors, compiler to check models consistency and create markers, outline, etc.), it is, and always has been kind of a pain to “instantiate” this framework for each new usecase.

People familiar with EMF, and modeling technologies in general, are probably thinking right now that the framework behind PDE should probably model-based, and of course they are right! That’s exactly the purpose of the ongoing “model my PDE” work being done in the PDE incubator. In this post, I will quickly explain what is currently available in HEAD of the project, further explanations may come in later posts (by the way, feel free to ask precisions on specific topics!).

Generic Forms editor

The org.eclipse.pde.emfforms bundle proposes some abstractions of what is generally needed to create a Forms editor for any kind of EObject. Thanks to EMF.Edit and Databinding framework, it makes it really simple –sometimes you won’t even need to write a single line of code– to create your UI and bind it to the model, display the errors on your model, show an outline, and stuff.

Since the project is still incubating, there is of course no clear API of this bundle at the moment, but if you need to quickly hack a model editor, you should probably have a look at it, and at the “exemplary” implementation which has been done for the “next-gen” DS Component editor.

A non-exhaustive list of the feature provided by this framework (coupled to the features of EMF/EMF.Edit/Databinding and Forms) would be:

  • full undo/redo support
  • full copy/paste support (both locally to the editor, and from an editor instance to another),
  • automatic refresh of the editor if the model is changed on disk,
  • model live-validation; displaying error(s) in front of the “guilty” controls, in the forms header, and on the nodes of the elements displayed in Master/Details blocks,
  • full drag&drop support in Master/Details blocks’ viewers,
  • generic Outline view,
  • generic Properties view,
  • … 😎

Extensibility

There are many OSGi vendors who work on their own implementation of the standard, and they obviously need tooling for these specificities. In an ideal world, they should be able to extend vanilla PDE instead of reinventing the wheel. We, at PDE, expose some APIs for people to do that (SpringSource Tool Suite proposes tooling for SpringDM, and it is built on top of PDE), but there are many things that are still internal. Our models, our editors, our compilers, are not really designed to be extensible. A model-based approach is the right solution to this lack of extensibility:

  • An EMF model is very easily extensible. In order to extend the “Declarative Services” model, create you own, let’s say scr-equinox.ecore, referencing just take the scr.core model. You can now have an EquinoxComponent, extending the standard Component, and bringing some nice Equinox-specific additions. When you will generate the corresponding Java code, you’ll end up with a model which will be 100% editable in the “legacy” Component editor.

scr-equinox-1.1

  • It is very easy to add new validation rules, either enhancing the EValidator generated by EMF, or, way better, using the EMF Validation framework which allows to contribute new rules in a declarative fashion. Not only it allows anybody to “plug” additional rules on top of an existing model, but it also avoids to clutter the model API with dependencies needed only for validation purposes. Indeed, to perform a meaningful validation of a Declarative Services component, you have to query JDT and PDE to check method signatures, visibility of referenced services, etc. For people interested in how an EMF Validation constraint extension, here is an example taken from the incubator code:
<extension point="org.eclipse.emf.validation.constraintProviders">
      <category
            id="org.eclipse.pde.ds.builder.validation"
            mandatory="true"
            name="Declarative Services Validation">
      </category>
      <constraintProvider cache="true">
         <package
               namespaceUri="http://www.osgi.org/xmlns/scr/v1.1.0">
         </package>
         <constraints
               categories="org.eclipse.pde.ds.builder.validation">
            <constraint
                  class="o.[...].ComponentMethodsAreValidAndAccessible"
                  id="o.[...].constraintComponentMethodsAreValidAndAccessible"
                  lang="Java"
                  mode="Live"
                  name="Components methods validation"
                  severity="ERROR"
                  statusCode="2">
               <message>
                  Method {0}: {1}
               </message>
               <target class="Component">
                  <event name="Set">
                     <feature name="activate">
                     </feature>
                  </event>
                  <!-- ... -->
               </target>
            </constraint>
         </constraints>
      </constraintProvider>
   </extension>
  • EMF allows to version models, and has solutions to ensure compatibility between an N-1 and an N model instance. This way, we could probably be a bit less shy when it comes to updating old APIs. Tooling would be written to handle models in version N, but APIs for N-1, N-2, etc. would still be available, and mappers to convert from N-X to N would be too.

Model-aware builder

In order to report errors to the end-user, the editor performs live validation (thus the nice Forms decorators in the screencast below), but there is also a specific builder (once again, designed to be extensible) listening for model changes, and calling EMF Validation behind the scene to check the consistency and create resource markers for every encountered problem.

Screencast

A screencast being IMHO worth a thousand words, here is a live demo of the DS Editor:

pde modeling

If you want to play with this  “experimental” tool, you can install in your SDK the experimental feature served by build.eclipse.org and corresponding to the result of continuous integration of the HEAD of the project, thanks to Hudson and Athena!

I guess the next important step is now to find an elegant way to propose a Source tab which, as you may have noticed, is almost the only feature being present in the Galileo editor and not in this prototype. Another important step will also be to write the Xtext grammar of an OSGi Manifest, and leverage this “EMF-Forms” framework to propose a cool and extensible editor on top of a Manifest 🙂

Categories
IT

GWT 1.5 est de sortie !

lgo-gwt3 mois, presque jour pour jour, après la RC1, voici enfin la version 1.5 de GWT, qui devrait mettre du piment dans la vie de pas mal de développeurs (private joke inside) !

Vous le savez peut-être, mais l’apport majeur de cette nouvelle version du framework Google de développement d’applications Web est le support de Java 5 : generics, boucles “for each”, etc.

Même si certaines APIs peuvent vous manquer (impossible de faire de l’introspection par exemple 🙁 ), l’émulation de la JRE est particulièrement complète et d’une utilisation tout à fait transparente.
La compatibilité est d’ailleurs telle que l’on peut tout à fait faire tourner le noyau d’EMF (oui oui !) sur GWT.

Parmi les autres nouveautés, il faut noter :

  • amélioration des performances (tant au niveau de la compilation que de l’exécution),
  • mécanisme de styling simplifié
  • support du BiDi (inversion de l’IHM de droite à gauche pour des langues comme l’arabe)
  • couche d’interaction Javascript, pour accéder en Java à des librairies Javascript legacy

De plus amples information sur le blog officiel.