Previous Page
Next Page

5.1.1. Label providers

A label provider is one of the most common adapter types used in list viewers. This provider is used to map a domain model object into one or more images and text strings displayable in the viewer's widget.

The two most common types of label providers are ILabelProvider (see Figure 5-2), used in lists and trees, and ITableLabelProvider (see Figure 5-3), used in tables. The former maps an item into a single image and text label while the latter maps an item into multiple images and text labels (one set for each column in the table). A label provider is associated with a viewer using the setLabelProvider() method.

Figure 5-2. LabelProvider hierarchy.


Figure 5-3. TableLabelProvider hierarchy.


Useful APIs defined by ILabelProvider include:

getImage(Object) Returns the image for the label of the given element.

getText(Object) Returns the text for the label of the given element.

Useful APIs defined by ITableLabelProvider include:

getColumnImage(Object, int) Returns the label image for the given column of the given element.

getColumnText(Object, int) Returns the label text for the given column of the given element.

For an example of label providers, see Section 5.1.6, ListViewer class, on page 192.


Previous Page
Next Page