RSS

Search Engine

Monday, June 28, 2010

Eclipse JFace viewers

1.1. Overview

Eclipse JFace viewers allow to display a domain model in a list, tree or table without converting the domain model beforehand.

These viewers provider adaptors which are used to provide the model to the viewer (these are called content provider) and adaptors to define how the model data is displayed in the viewer (these are called label providers).

The Eclipse JFace viewer concept is very flexible as it allows to use the same content provider / label provider in different viewers without changing the underlying data structure.

JFace also allows assign label provider directly to columns instead of one label provider for the whole table.

1.2. Viewer, content and label provider

In working with JFace viewers it is important to understand the concept of viewers, label and content providers. The following provides an overview and lists some typical classes in these areas.

1.3. Viewer

The user interface is represented by the viewer, e.g. in our example the table viewer.

Viewer: Typical viewers are

  • org.eclipse.jface.viewers.ListViewer - Display a simple list

  • org.eclipse.jface.viewers.TreeViewer - Displays a tree

  • org.eclipse.jface.viewers.TableViewer - Displays a table

1.4. Content provider

Responsible for providing objects to the view. It can simply return objects as-is.

Typical content provider are

  • IStructuredContentProvider: Used for lists and tables

  • ITreeContentProvider: Used for trees, has addional methods to determine the children and the parents of elements

1.5. Label provider

Defines how objects are displayed, e.g. which part of the object is used to return the text which is displayed.

Label provider follow usually the template approach; you have an interface which describes and contact and a class which the programmer can use which delivers already reasonable implementations for the interface and the programmer can then choose to override only the relevant methods.

Typical label providers are

Table 1. Label providers

InterfaceTemplate classDescription
ILabelProviderLabelProviderUsed for lists and trees, displays per element a icons and / or a text element.
ITableLabelProviderLabelProviderUsed for tables, displays per element and column a icons and / or a text element

0 comments:

Post a Comment