You can create a table that has entries that can be categorized, or that display hierarchically, such as the documents and responses that comprise a thread in a discussion view, by using a tree provider to define the structure of the table control.

The tree label provider that you implement creates labels that can do either of the following:

Span more than one column.

Display a +/- sign to indicate that the item is expandable and has child documents that can be displayed.

Adding listeners to expandable table rows enables you to track changes to rows, which can be expanded in the following ways:

Users can click the +/- sign displayed beside an entry that is hierarchical to expand or collapse the row.

Applications can programmatically expand or collapse a row.

To create a tree table:

Implement the com.ibm.rcp.jface.viewers.ITreePagedContentProvider interface to indicate that you want the table to be implemented as a tree control that has expandable columns. The ITreePagedContentProvider interface inherits from the IPagedContentProvider interface.

Implement the com.ibm.rcp.jface.viewers.IExtendTableLabelProvider.

For example:

public int columnSpan(Object element, int columnIndex) {

if (arg0 instanceof GroupedMetadata){

if (element instanceof Categories){

switch(columnIndex){

case 0:

return _viewer.getTable().getColumnCount();

}

}

return 0;

}

public boolean isExpandable(Object element, int columnIndex) {

if (element instanceof Categories){

switch(columnIndex){

case 03:

return true;

}

}

return false;

}

Register a listener to the table that listens for the expansion or collapse of a table row.