Eclipse 4.0 RCP: Selection

One of the objectives of Eclipse 4.0 was to make rich client development easier. One good example is the following use case: One view provides a selection (e.g. using a JFace TableViewer) and another view wants to get notified about a new selection of a domain object to get the chance to react on it.

First the selection provider part. The selection services can be easily injected using dependency injection.

private ESelectionService selectionService;

When using a JFace viewer, the viewer selection has to be forwarded to the selection service:

tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
  public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection =
       (IStructuredSelection) event.getSelection();

On the consumer side, the domain object is injected using an @Optional and @Named active selection. The following code snipped is part of a details view POJO that uses a WritableValue (Eclipse data binding) as holder for the actual domain object (of type IContact).

public void setSelection(
  @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IContact contact) {
    if (contact != null) {

That’s pretty convenient and concise compared with the code needed in Eclipse 3.x.

Have Fun!

Follow me on Twitter

This Post Has 5 Comments

  1. Tom Schindl

    You are right it is but I/we are not happy yet with how we provide the selection (or more common how to push back informations into the context). The problem is that you need the ESelectionService which is less problematic than the 3.x way of doing it but it still ties you to the ESelectionService.

    We are discussing solutions to this problem in

  2. AEHP

    Hi Kai,

    I need your help, please !!!

    I was developed an application using Eclipse RCP that allows to create client’s applications with the integration between swt and awt, but I had one problem when I run my application, the message is the following:

    27 août 2010 08:02:04 sun.awt.X11.XToolkit processException
    ATTENTION: Exception on Toolkit thread
    at sun.awt.X11.XlibWrapper.CallErrorHandler(Native Method)
    at sun.awt.X11.XToolkit.SAVED_ERROR_HANDLER(
    at sun.awt.X11.XToolkit$1.handleError(
    at sun.awt.X11.XToolkit.GlobalErrorHandler(

    I had read a lot of comments in the web about this problem but I did’not find the solution.

    Would you help me, please?


  3. Kai Tödter

    @AEHP, sorry, I have no experience with X11 based UIs…

Leave a Reply

I accept the Privacy Policy