The basics of CompositeTable
The easiest way to learn the CompositeTable application program interface (API) is to review the snippets included in the download. Open CompositeTableSnippet1 and scroll down to the main method. You can see that the widget is created, and Header and Row objects are created. These objects determine how the CompositeTable displays headers and rows. If you look at the Header implementation, you see that it contains two Label widgets positioned using a GridLayout. Run the example, and the window is similar to that shown below.
Figure 9. CompositeTableSnippet1
Next, change the Header class, as shown below.
Listing 3. Header changes
public Header(Composite parent, int style) {
super(parent, style);
setLayout(new GridRowLayout(new int[] { 160, 100 }, false));
Label first = new Label(this, SWT.NULL);
first.setText("First Name");
first.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
first.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
new Label(this, SWT.NULL).setText("Last Name");
} |
Running the example now shows the Header changes, as displayed in Figure 10.
Figure 10. Change the header
The other key component to the display of a CompositeTable is the Row object. Reviewing the Row class definition in CompositeTableSnippet1 reveals two Text widgets positioned using GridLayout. The final piece of the puzzle is the content provider added in the main method. For each row, the CompositeTable calls the refresh method, passing in a row offset and a Row object. The method is then responsible for retrieving the appropriate model data and setting it on the Row object for display.


