Wednesday, December 06, 2006

the new Faces of JFace (part 1)

Some of you may have noticed JFace provides new API to streamline JFace usage and to support new features like:
  • custom owner draw
  • tooltips for tree/table-cells
  • keyboard editing support for viewers
To provide all those new features we (Tod Creasey, Boris Bokowski and me) decide to refactor the underling JFace code, provide new classes and to move things from specialized classes to more generice ones. The central of the whole refactoring brought up a whole bunch of new classes where the most important are the following:
  • ColumnViewer: Provides all things common to Viewers who deal with the concept of columns and rows
  • ViewerRow: Represents a row in the column viewer and wraps TableItem and TreeItem from SWT
  • ViewerCell: Represents one cell in the table/tree

We decide to create those new classe because it gives us the possibility to push as much code in the widget independent ColumnViewer instead of the widget centric classes derived from it.

All the changes mentionned above might not be interesting to you because most of the time you want use them directly so let's take a look at the more interesting things from a user point of view.

The most interesting thing to most of you might be that JFace has now adopted the programming style from SWT and JFace-Coding feels now much more like SWT-Coding. Look at the next few lines and you understand what I mean:

Composite parent = ...;
TableViewer v = new TableViewer(parent);
v.getTable().setLinesVisible(true);

TableViewerColumn vColumn = new TableViewerColumn(v,SWT.NONE);
vColumn.getColumn().setWidth(200);
vColumn.setLabelProvider(new MyLabelProvider());

v.setContentProvider(new MyContentProvider());
v.setInput(model);