Enhanced RCP: Usage of TitleAreDialogSupport

Eclipse Databinding comes with many utility classes and one of them is TitleAreaDialogSupport which can be used to show validation errors when running in an TitleAreaDialog.


But the default implementation has some missing features:

  • Once a validation error is shown the default message is not coming back when correcting them
  • The Ok-Button does not get disabled in case of validation errors

So we have to enhance it a bit by subclassing:

TitleAreaDialogSupport.create(this, dbc).setValidationMessageProvider(new ValidationMessageProvider() {
  @Override
  public String getMessage(ValidationStatusProvider statusProvider) {
    if (statusProvider == null) {
      return "Neuanlage/Bearbeitung einer Abteilung";
    }
    return super.getMessage(statusProvider);
  }
			
  @Override
  public int getMessageType(ValidationStatusProvider statusProvider) {
    int type = super.getMessageType(statusProvider);
    if( getButton(IDialogConstants.OK_ID) != null ) {
      getButton(IDialogConstants.OK_ID).setEnabled(type != IMessageProvider.ERROR);
    }
    return type;
  }
});

There’s already a feature request for this open but it is not fixed yet.

Posted in Enhanced RCP | 1 Comment

Improvement Properties-Editor

I’ve lately worked a lot with property files and what always bothered me was that there was no Outline-View shown for it like it is e.g. for the Java-Files.

Typically properties-File e.g. for translations are structured in a hierarchical way e.g. my files look like this:

ListView_FirstName=First Name
ListView_LastName=Last Name

DetailComposite_Title=Title
DetailComposite_Name=Name

Which means we could group the items in the outline a bit by using the _ as a group indicator which makes the editor and outline look like this:

I’ve uploaded the Eclipse Plugin to EclipseLabs and you can install it by pointing your Eclipse Plug-in Installer to http://outlined-property-editor.googlecode.com/svn/trunk/updatesite/.

Posted in 3.x | 13 Comments

Enhanced RCP: How views can communicate

I’ve often seen the question in the eclipse newsgroups when it comes to view communication. People often face the problem that their views have to communicate with each other informing about state changes (selection changes are published best through ISelectionService).
It looks like many people are not familiar with the OSGi-EventAdmin-Service which is a generic Event-System using the publish and subscribe pattern and it can be used really easy in your RCP-Applications.

1. Setup

Add org.eclipse.osgi.services to your MANIFEST.MF and make sure org.eclipse.equinox.event is part of your Launch-Config and Product-Definition.

2. Sending events

public class SenderView extends ViewPart {
  public static final String ID = "viewcommunication.views.SenderView";
  private Button b;
	
  public void createPartControl(Composite parent) {
    parent.setLayout(new GridLayout());
    b = new Button(parent, SWT.PUSH);
    b.setText("Send Event");
    b.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent e) {
        BundleContext ctx = FrameworkUtil.getBundle(SenderView.class).getBundleContext();
        ServiceReference<EventAdmin> ref = ctx.getServiceReference(EventAdmin.class);
        EventAdmin eventAdmin = ctx.getService(ref);
        Map<String,Object> properties = new HashMap<String, Object>();
        properties.put("DATA", new Date());
	
        Event event = new Event("viewcommunication/syncEvent", properties);
        eventAdmin.sendEvent(event);
				
        event = new Event("viewcommunication/asyncEvent", properties);
        eventAdmin.postEvent(event);
      }
    });
  }

  public void setFocus() {
    b.setFocus();
  }
}

3. Receiving Events

public class ReceiverView extends ViewPart {
  private TableViewer viewer;
	
  @Override
  public void createPartControl(final Composite parent) {
    parent.setLayout(new FillLayout());
    viewer = new TableViewer(parent);
    viewer.getTable().setHeaderVisible(true);
    viewer.getTable().setLinesVisible(true);
    viewer.setLabelProvider(new ColumnLabelProvider() {
      @Override
      public String getText(Object element) {
        return DateFormat.getDateTimeInstance().format(element);
      }
    });
		
    BundleContext ctx = FrameworkUtil.getBundle(ReceiverView.class).getBundleContext();
    EventHandler handler = new EventHandler() {
      public void handleEvent(final Event event) {
        if( parent.getDisplay().getThread() == Thread.currentThread() ) {
          viewer.add(event.getProperty("DATA"));
        } else {
          parent.getDisplay().syncExec(new Runnable() {
            public void run() {
              viewer.add(event.getProperty("DATA"));
            }
          });
        }
      }
    };
	
    Dictionary<String,String> properties = new Hashtable<String, String>();
    properties.put(EventConstants.EVENT_TOPIC, "viewcommunication/*");
    ctx.registerService(EventHandler.class, handler, properties);
  }

  @Override
  public void setFocus() {
    viewer.getTable().setFocus();
  }	
}

Not too complex but is it possible in fewer lines or in other words without the many lines of glue code? Then stay tuned for a follow blog entry on how e4 provides easy access to the EventAdmin-Service or visit my Eclipse 2011 talk “Singlesourcing for Eclipse 4.x and Eclipse 3.x” where you’ll learn to apply the Eclipse 4.0 style to your 3.x applications.

Posted in Enhanced RCP | 32 Comments

2010 in review

At the end of the year it’s always good to look back on what has happened the whole year and sometimes you get suprised because your current impression on things you did doesn’t really match with the one you really did when digging into code-repositories, mailing lists, bugzillas and such.
My Eureka moment was when I looked on the dash stats which contraticted my personal feeling about my e4 involvement. My personal expression was that I’ve not contributed too much to e4 because I was quite busy doing company work after 4.0 was released.
But looking at dash I remember that I’ve worked in many areas of e4 this year:


First off all naturally the dash info is a bit missleading – I have not contributed ~30% of the e4 project. The numbers are so high because of 2 facts:

  • Modified LoC: because i’ve been in charge of most model changes where 95% of the code is generated by EMF
  • Number of Commits: I’ve been working on a very isolated branch of e4 (the model tooling) and I’m used to commit very often and because I didn’t had to collaborate and disturbe others with my changes I followed this development scheme

My blog stats

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Wow.

Crunchy numbers

Featured image

Madison Square Garden can seat 20,000 people for a concert. This blog was viewed about 68,000 times in 2010. If it were a concert at Madison Square Garden, it would have performed about 3 times.

In 2010, there were 49 new posts, growing the total archive of this blog to 124 posts. There were 148 pictures uploaded, taking up a total of 73mb. That’s about 3 pictures per week.

The busiest day of the year was July 29th with 728 views. The most popular post that day was Eclipse 4.0 and tutorial on writing e4-RCP-application released.

Where did they come from?

The top referring sites in 2010 were wiki.eclipse.org, eclipse.org, vogella.de, planeteclipse.org, and stackoverflow.com.

Some visitors came searching, mostly for qxwt, eclipse 4.0, eclipse e4 wrting application, emf databinding, and e4 workbenchmodel editor.

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

Eclipse 4.0 and tutorial on writing e4-RCP-application released July 2010
34 comments

2

Galileo: EMF-Databinding – Part 3 June 2009
33 comments

3

Galileo: EMF-Databinding – Part 2 June 2009
3 comments

4

Galileo: EMF-Databinding – Part 1 June 2009
3 comments

5

Galileo: EMF-Databinding – Part 4 June 2009
9 comments

Posted in Uncategorized | 1 Comment

Slides from my latest Talks

I’ve been given some talks about Eclipse 4.0/4.1 lately. For those interested here are the slides:

Posted in e4, Talks & Conferences | Leave a comment

UUID-Generator Plugin

Today it once more was the time where I had to generate Test-Data and for this purpose I had to create UUIDs. My first reaction was to write a small program which was generating some UUIDs i could use like Lars is showing in one of his blog entries which was what I had done before already number-times.

Today I decided against and to fix this problem for all times. So I wrote a highly sophisticated Plug-In 🙂 for my favorite IDE named Eclipse:

Though the Plug-In Code holds a lot of my personal know how I finally decided to make it available to everyone under EPL and upload the code to to EclipseLabs.org in a new project. If you are in need of generating UUIDs inside your Eclipse Env you can simply install the Plug-In using this update-site.

Posted in Announcements | 7 Comments

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.

Posted in e4, EMF | 25 Comments

Article about e4 online

Back in March Boris Bokowski and myself wrote an article about the e4 workbench model. The article has now been published online (it is written in German but probably google-translate at least gives others an idea what we are talking about).

Posted in e4 | Leave a comment

ESE 2010, e4 and my submissions

The submission deadline for ESE 2010 is over and there are many many submission. Let me first of all talk about my submissions:

  • Adopt the e4 progamming model in Eclipse >= 3.6
    This talk discusses how you can make single sourcing for Eclipse 4.0 and Eclipse 3.6 happen without the use of backwards compat layer coming with Eclipse 4.0
  • Can developers adopt e4-RCP for Swing Applications?
    This talk discusses how Eclipse Application Platform 4.0 can be used with other UI-Technologies (e.g. Swing)
  • The way to Eclipse 4.0 and 4.1
    In this talk Boris Bokowski and myself will you provide a summary of the last 2 years of on going development of Eclipse 4. Things we achieved, things we failed, things we work on for Eclipse 4.1.
  • Eclipse 4.0 Hackfest
    If you want to discuss Eclipse 4 with others and some of the committers on the project. I think this is the right thing for you.

Beside that I’m really amazed by the number of talks who are filed under the Eclipse 4.0 category. What I like most is that the submission are not only from Eclipse 4.0 committers (of course many of them are) but also from early adopters (like The thrill of migrating a mission-critical RCP-application to E4: lessons learned from Jürgen Baier) and framework developers like Christian Campo – Riena on e4 aka “RCP 2.0” and Matthias Zimmermann & Andreas Hoegger – Eclipse Scout “Querbeet”, tooling provides like Stephane Begaudeau & Jonathan Musset – Acceleo Code Generator, an experimental transition to e4 to people who apply Eclipse 4.0 technologies in none UI-Environments like Gunnar Wagenknecht – Hot e4 stuff for building cool server applications

Posted in e4, Talks & Conferences | Leave a comment

I’m using Flattr.com

For many of you this might not be new but I’ve just found out about flattr.com which allows me to support blogs, software, … I find useful.

In case you find my blog useful you’ll find the the flattr-button
Flattr this

on the upper right on my blog. It’s a bit unfortunate that I’m not able to use the dynamic one on my wordpress.com-blog because it needs JavaScript.

Posted in Announcements | Leave a comment