Introducing e(fx)clipse

UPDATE
Please download the latest version from efxclipse.org

People who’ve read my blog in the last few weeks have seen that I invested some time in getting the Eclipse 4 Application Platform running on top of JavaFX.

One of the key technologies of JavaFX is that one uses CSS to theme the whole application but the default CSS-Editors are not of much help because the properties used are specific to JavaFX (read they are all customized extension starting with -fx).

… and because I decided already some time ago that I had to teach myself how to write my own DSL using Xtext it was the prefect chance to create a CSS-Editor for JavaFX using Xtext.

… and because I was traveling a lot in the last 2 weeks (I’ve been to 3 democamps) I had a lot of spare time to work on something I’d like to call “e(fx)clipse” a start of an Eclipse Tooling for JavaFX.

So what do I have for Release 0.0.1 of the Tooling? Well all I have is a start for a CSS-Editor built using Xtext.

Here are 2 screenshots of the current CSS-Editor running in Eclipse 4.1 (it runs as well in 3.7 naturally).

So as you see the editor has not too many features as of now:

  • Basic Syntax-Highlighting
  • Proposals for CSS-Attributes
  • Support for Attribute value proposals

but I hope to improve the initial features.

BTW one of the main features of the CSS-Editor is that it allows people to plug in their own Property-Rules so e.g. e4 could plug-in their own rules, so one can for mozilla, webkit, … -specific rules.

As of now I have 2 property-sets:

  • CSS 2.1
  • JavaFX

but they are not part of the core plugin but contributed simply as OSGi-Services :-)

So if you want to give the editor a spin. You can download the p2-repo from my github account. Please note this is a very very early release and the editor currently is only registered for .fxcss-Files.

Update:
There’s one JavaFX syntax not yet support by the editor showing an error marker but the problem is not the CSS-Editor but in reality the CSS-Definition speced by JavaFX. I’ve already filed a Jira-Ticket where I describe the problem and proposed a CSS-2.1 compatible definition:

linear from( <size> , <size> ) to( <size> , <size> ) [ stop( <number> , <color> ) ]+ [ repeat | reflect ]?
radial [ center( <size> , <size> ) , ]? <size> [ focus( <size> , <size> ) ] ? [ stop( <number> , <color> ) ]+ [ repeat | reflect ]?

/* Example */
linear from(0%,0%) to(100%,100%) stop(0.0,red) stop(1.0,black)
radial center(25%,25%) , 50% focus(20%,20%) stop(0.0,gray) stop(0.50,darkgray) stop(1.0,dimgray) reflect 

Jax 2011: EMF-Databinding talk

I had the pleasure to present EMF-Databinding to interested people on the Model Day at Jax 2011. I’m desperately sorry that people have been unable to install my sources but there has been a misunderstanding I’ll apologize for.

Everyone who was at the tutorial should already have the slides and sources but for those who don’t.

Here they are:

To make the stuff run you’d ideally use Eclipse SDK 4.1M7 or Eclipse SDK 3.7M7 (and install e4 stuff as mentioned in the slides)

Interesting new feature in EMF-Databinding

I’ve invested sometime into EMF-Databinding to add a new quite interesting feature i guess. Currently we have to problem that if your nested path crosses a multi-valued feature (=java.util.List) at some point the only solution today is to create a volatile transient feature which observes your EList and fire change events but this really clutters your Ecore-Model.

Let’s take a look at an example model

you’d like to present in an UI like this:

Until EMF 2.7M7 you’d have to modify your EMF-model like this:

So that you could e.g. write something like this to get access to the private address’ city property:

import static at.bestsolution.e4.addressbook.model.addressbook.AddressbookPackage.Literals.*;

// ...

IEMFValueProperty mProp = EMFProperties.value(FeaturePath.fromList(PERSON__PRIVATE_ADDRESS,ADDRESS__CITY));

// or in longer builder type syntax
IEMFValueProperty mProp = EMFProperties.value(PERSON__PRIVATE_ADDRESS).value(ADDRESS__CITY);

With the new feature I’ve added to IEMFListProperty#value(ListElementAccess) one now does not have to create those volatile transient features any more but can write the long form like this:

IEMFValueProperty mProp = EMFProperties.list(PERSON__ADDRESSES).value(
  new ElementAccessImpl(AddressType.PRIVATE)
);

// ...
private class ElementAccessImpl extends ListElementAccess<Address> {
 private AddressType type;

 public ElementAccessImpl(AddressType type) {
  this.type = type;
 }

 @Override
 public int getReadValueIndex(List<Address> list) {
  int i = 0;
  for (Address o : list) {
   if (o.getType() == type) {
    return i;
   }
   i++;
  }
  return -1;
 }

 @Override
 public int getWriteValueIndex(List<Address> list) {
  int i = 0;
  for (Address o : list) {
   if (o.getType() == type) {
    return i;
   }
   i++;
  }
  return -1;
 }
}

I’d like to note that this feature is an experimental one and we don’t guarantee to break it e.g. by pushing it upstream to Eclipse Databinding but you are free to give it a try and report usefulness, problems, like, dislike, … .

BTW did you notice that the screenshot from the above application was taken from a Swing-Application? How can that be? Isn’t Eclipse Databinding (and because of that EMF Databinding ) only useful within SWT driven apps (e.g. Eclipse RCP ones)?

Without saying too much: No – because many core Eclipse technologies OSGi, Databinding, EMF, Eclipse 4 Application Platform to name some can be used with any UI-Technology

Navigating/Querying EMF-Models using XPath

To make the new e4 way of building a complete model from small model pieces – named fragments – more flexible in 4.1, I’ve been developing a JXPath extension which works ontop of the reflective EMF-API.

I know that there’s already the possibility to query models using OCL but there are many more people familiar with XPath than the sometimes very cryptic OCL syntax. Some code samples might make clear why I think querying and navigating through EMF-Models using XPath is a very useful thing.

As an example model I’m using the Library-Model which is well known to most people who’ve worked with EMF.

An instance of the model would probably look like this:

The XML-Source helps probably to understand the references:

<?xml version="1.0" encoding="ASCII"?>
<extlib:Library xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:extlib="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0" xsi:schemaLocation="http:///org/eclipse/emf/examples/library/extlibrary.ecore/1.0.0 ../org.eclipse.emf.examples.library/model/extlibrary.ecore">
  <stock xsi:type="extlib:Book" borrowers="//@borrowers.1" title="Mystery Book 1" author="//@writers.0"/>
  <stock xsi:type="extlib:Book" borrowers="//@borrowers.0" title="Sience Book 1" category="ScienceFiction" author="//@writers.0"/>
  <stock xsi:type="extlib:Book" borrowers="//@borrowers.1" title="Mystery Book 2" author="//@writers.1"/>
  <stock xsi:type="extlib:Book" borrowers="//@borrowers.0" title="Sience Book 2" category="ScienceFiction" author="//@writers.1"/>
  <writers address="Hometown" firstName="Tom" lastName="Schindl" books="//@stock.0 //@stock.1"/>
  <writers address="Homecity" firstName="Boris" lastName="Bokowski" books="//@stock.2 //@stock.3"/>
  <borrowers address="Hometown" firstName="Paul" lastName="Webster" borrowed="//@stock.1 //@stock.3"/>
  <borrowers address="Homecity" firstName="Remy" lastName="Suen" borrowed="//@stock.0 //@stock.2"/>
</extlib:Library>

Now let’s try to answer some questions:

  • Find all “Mystery Books”
  • Authors of “Mystery Books”
  • Find all writers and borrowers in “Hometown”
  • Find all borrowers “Mystery books”

The XPath-Code one can use with the new support is like this.

  • Load the model and setup a context for the XPath-Query
    public class Application implements IApplication {
      public Object start(IApplicationContext context) throws Exception {
        ResourceSet resourceSet = new ResourceSetImpl();
        resourceSet.getResourceFactoryRegistry()
          .getExtensionToFactoryMap()
          .put(Resource.Factory.Registry.DEFAULT_EXTENSION,new XMIResourceFactoryImpl());
    
        URI uri = URI.createPlatformPluginURI("/testxpath/Library.xmi",true);
        Resource resource = resourceSet.getResource(uri, true);
    
        Library l = (Library) resource.getContents().get(0);
        XPathContextFactory<EObject> f = EcoreXPathContextFactory.newInstance();
        XPathContext xPathContext = f.newContext(l);
        // Execute the XPaths
      }
    }
    
  • Find all “Mystery Books”
    {
      System.out.println("Mystery Books:");
      Iterator<Book> it = xPathContext.iterate("/books[category='Mystery']");
      while( it.hasNext() ) {
        System.out.println("	" + it.next().getTitle());
      }			
    }
    
  • Authors of “Mystery Books”
    {
      System.out.println("Mystery Book Authors:");
      Iterator<Writer> it = xPathContext.iterate("/books[category='Mystery']/author");
      while( it.hasNext() ) {
        Writer w = it.next();
        System.out.println("	" + w.getFirstName() + "," + w.getLastName());
      }
    }
    
  • Find all writers and borrowers in “Hometown”
    {
      System.out.println("Borrower/Writer in Hometown:");
      Iterator<Person> it = xPathContext.iterate(
        "/borrowers[address='Hometown']|/writers[address='Hometown']"
      );
      while( it.hasNext() ) {
        Person b = it.next();
        System.out.println("	" + b.getFirstName() + "," + b.getLastName());
      }	
    }
    
  • Find all borrowers “Mystery books”
    {
      System.out.println("Borrower of Mystery books:");
      Iterator<Borrower> it = xPathContext.iterate(
        "/borrowers[borrowed/category='Mystery']");
      while( it.hasNext() ) {
        Borrower b = it.next();
        System.out.println("	" + b.getFirstName() + "," + b.getLastName());
      }
    }
    

Executing the code leads to the following output:

Mystery Books:
	Mystery Book 1
	Mystery Book 2
Mystery Book Authors:
	Tom,Schindl
	Boris,Bokowski
Borrower/Writer in Hometown:
	Paul,Webster
	Tom,Schindl
Borrower of Mystery books:
	Remy,Suen

I think the above shows how easy it is to navigate/query an EMF-Model-Instance using JXPath and using this new EMF-extension.

I hope we’ll manage to integrate this support into one of the next Eclipse 4.1 I-builds until then you can access the source from the e4-cvs-repository. I’m also thinking about moving the code at some point to EMF directly because there’s no dependency on e4 and such an implementation could be of use for others as well.

ESE 09 – My Slides

Back from ESE 09 – once more a nice event and got to know even more people. I was quite busy this year taking part in 5 Sessions so a short review from my side:

EMF Tutorial

I think Ed, Eike and me did a good job though there’ve been too many people so working through examples was not possible. The next time (EclipseCon 09) we need probably skip some parts. Beside that I think I could demostrate fairly good how flexible Eclipse-Databinding can be used in RCP-Applications.

E4 Symposia

Boris and me had many people in our symposia and I think we could explain those people our vision of e4 and how the internals are structured. Boris gave a short overview about the 20 things, how DI is working using the IEclipseContext and WebUI and I talked about our EMF-driven Application model and our flexible rendering story.
I think people start to get our point that E4 is a flexible Application Framework they can build any UI-Application (the UI technology doesn’t really matter) if you start accepting that rendering is just another service like it is the selection, logging, … service.

What’s in E4

This was an overview talk given by Boris, Kai, Hallvard, Yves and me on e4. I gave a short overview about the reasoning and how the application platform is designed around our EMF-Model. I think we could at least reduce the confusion in the community.

e4 in Detail – The model workbench and it’s possibilities

In this talk I tried to explain in more detail how the e4-application platform uses EMF, DI and the rendering services to create a flexible UI-Application. The slides are available here.

UFaceKit – A uniform UI development model for different UI and Runtime platforms

This was my last talk where I explain the reasons and various cool things you can with UFaceKit which since a week before can be optionally backed up by an Ecore-Model so that Application can developed (and of needed deployed) using EMF-Technologies. The slides are here.

Build for Databinding4GWT available

Following an discussion on stackoverflow.com where people stated that we don’t offer binary builds I sat down yesterday and wrote a short ant script to create binary builds people can consume out of the box easily.

I didn’t use the Eclipse build system but a simple ant script which fetches the sources from SVN and builds them. I also could figure out how to promote this stuff to the eclipse-download servers so I released them to our official page.

You can fetch the latest binary gwt builds from here or find a link to them on our release page. I’m going to add binary builds for other UFaceKit stuff hopefully soon though I’d prefer to put them on Eclipse.org Servers if I can figure out how to do it.

Please don’t forget to give us feedback on problems you encounter. We can’t fix problems you are not reporting to us.