| Free tutorials for Java, Eclipse and Web programming |
Version 1.8
Copyright © 2008 - 2009 Lars Vogel
16.12.2009
| Revision History | ||
|---|---|---|
| Revision 0.1 | 01.07.2007 | Clemens Muessener |
| Created Article | ||
| Revision 0.2 | 12.09.2007 | Lars Vogel |
| Revised Article | ||
| Revision 0.3 | 20.03.2008 | Hendrik Still |
| Added Editors, navigation via tab | ||
| Revision 0.4 | 12.10.2008 | Marcus Rieck |
| Added Sort Columns / Show Hide Columns and | ||
| Revision 0.5 | 21.03.2009 | Lars Vogel |
| Re-worked article, added explanation about the general concept of JFace | ||
| Revision 0.6 | 22.03.2009 | Lars Vogel |
| Correct usage of setInput() in View.java | ||
| Revision 0.7 | 23.03.2009 | Lars Vogel |
| Changed project and package name | ||
| Revision 0.8 | 24.03.2009 | Lars Vogel |
| Fixed the sorter coding | ||
| Revision 0.9 | 29.03.2009 | Lars Vogel |
| Added filter | ||
| Revision 1.0 | 30.03.2009 | Lars Vogel |
| Added StyledCellLabelProvider | ||
| Revision 1.1 | 20.04.2009 | Lars Vogel |
| Minor clean-up in PersonEditingSupport | ||
| Revision 1.2 | 20.05.2009 | Lars Vogel |
| Show / Hide using the menu on the table using Eclipse 3.5 | ||
| Revision 1.3 | 27.07.2009 | Lars Vogel |
| Fixed StyledLabelProvider | ||
| Revision 1.4 | 05.08.2009 | Lars Vogel |
| Fixed sorter for Persons | ||
| Revision 1.5 | 02.09.2009 | Lars Vogel |
| removed hard-coded image location against Activator.getImageDescriptor() | ||
| Revision 1.6 | 08.09.2009 | Lars Vogel |
| Fixed incorrect import in LabelProvider | ||
| Revision 1.7 | 10.09.2009 | Lars Vogel |
| added TreeNodeContentProvider and LabelProvider explanation | ||
| Revision 1.8 | 16.12.2009 | Lars Vogel |
| LabelProvider is also template for ITableLabelProvider | ||
Table of Contents
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.
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.
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
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
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
| Interface | Template class | Description |
|---|---|---|
| ILabelProvider | LabelProvider | Used for lists and trees, displays per element a icons and / or a text element. |
| ITableLabelProvider | LabelProvider | Used for tables, displays per element and column a icons and / or a text element |