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

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

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

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}