Menu

ManualLayerTableSupport

Remo

Table Support Layer

The table support layer builds on the model adapter and standard converters to offer easy to set up table support.

Features

  • create an editable table just by configuring the column properties, no coding needed
  • converters from data binding are automatically used to render and edit table data, including dates and numbers
  • binding of multi selection state of a checkbox table to a list
  • binding of multi selection state of a normal table to a list
  • automatic creation of a table cursor if the table contains editable columns, making keyboard navigation easy
  • disabling rows in the table if {@link RCPTableFormToolkit} is used
  • automatic update on changes if you use a WritableList of beans as input to the table
  • cell editing support for text fields, combos and boolean cell editors

If you read the feature list and are new to SWT/JFace, you might wonder why there is no component supporting all this stuff out of the box.
A lot of people wonder, that's why I started RCPForms.

The Sandbox example delivered with RCPForms has a class SandboxTablePart which demonstrates most of the features of the TableSupport layer. This is a definitive must to get an idea how it works.

Table Creation Example

A table example is shown below. An RCPCheckboxTable is created and added to a section using a builder.
The wrapper automatically creates a CheckboxTableViewer, which is configured using the main class of the Table Support Layer, TableUtil.
You pass a list of column configurations, which define header text, property to display in the column, size, alignment, if the column should use additional space when the table is resized and the cell editor type.

Everything else is handled by the table support layer, which is a lot if you know SWT and JFace,
since plain swt tables which support editing are quite ugly to use.

The input should be a WritableList, since this list can fire change notifications; if you want to use a plain list, you need to handle refresh yourself.

    private void createTableViewer(final GridBuilder sf)
    {
        RCPCheckboxTable table = new RCPCheckboxTable("Table:");
        sf.addLine(table);
        TableViewer tableViewer = (TableViewer) table.getViewer();
        TableUtil.configureTableViewer(tableViewer, new ColumnConfiguration[]{
                new ColumnConfiguration("Name", TestModel.P_Name, 100, SWT.LEFT, false,
                        ECellEditorType.TEXT).setGrabHorizontal(true),
                new ColumnConfiguration("Birthdate", TestModel.P_BirthDate, 80, SWT.LEFT, false,
                        ECellEditorType.TEXT),
                new ColumnConfiguration("Gender", TestModel.P_Gender, 60, SWT.LEFT,
                        net.sf.rcpforms.test.TestModel.Gender.values()),
                new ColumnConfiguration("Overdraw", TestModel.P_OverdrawAccount, 50, SWT.CENTER,
                        false, ECellEditorType.CHECK),}, TestModel.class, true);
        WritableList list = new WritableList();
        list.add(new TestModel("Schmitz", 55));
        list.add(new TestModel("Meier", 33));
        tableViewer.setInput(list);
    }

How it works

All the tedious setup you have to do to get an editable table using JFace is done by TableUtil.configureTableViewer() based on the declarative column configurations:

  • for each column a TableColumn is created and configured
  • editing support is created for each column and connected to the provider created below
  • an instance of the framework class PropertyLabelProviderAndCellModifier is created which does all the work behind the scenes, which is set as LabelProvider and CellModifier on the viewer
  • create a special content provider ObservableListBeanContentProvider which attaches to the WritableList and all beans in it to update the table on changes.
  • if the table is editable, i.e. at least one column has a cell editor type != null, a TableCursor is created to navigate the table with the arrow keys. Pressing return on a cell starts cell editing, pressing return again ends it.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.