Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Eclipse 4.0 RCP: Selection

DZone's Guide to

Eclipse 4.0 RCP: Selection

· Java Zone ·
Free Resource

The CMS developers love. Open Source, API-first and Enterprise-grade. Try BloomReach CMS for free.

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.

@Inject
private ESelectionService selectionService;

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

tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
  @Override
  public void selectionChanged(SelectionChangedEvent event) {
    IStructuredSelection selection =
       (IStructuredSelection) event.getSelection();
    selectionService.setSelection(selection.getFirstElement());
  }
});

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 used es WritableValue (Eclipse data binding) to as holder for the actual domain object of type IContact.

@Inject
public void setSelection(
  @Optional @Named(IServiceConstants.ACTIVE_SELECTION) IContact contact) {
    if (contact != null) {
      contactValue.setValue(contact);
    }
}

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

Have Fun!

Kai

From http://www.toedter.com/blog/?p=253

BloomReach CMS: the API-first CMS of the future. Open-source & enterprise-grade. - As a Java developer, you will feel at home using Maven builds and your favorite IDE (e.g. Eclipse or IntelliJ) and continuous integration server (e.g. Jenkins). Manage your Java objects using Spring Framework, write your templates in JSP or Freemarker. Try for free.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}