I have a TableViewer
widget with a single column, where each row in the table's contents is a Composite
with a number of child widgets. The column has a label provider that is a subclass of OwnerDrawLabelProvider
. The label provider is supposed to render the Composite
children in the table cell, but when paint()
is called, nothing is rendered.
I have found a number of examples on how to draw plain or styled text items, or primitives using the GC
in the Event
object passed in, but nothing on drawing the contents of a Composite
in the cell's area.
Is this possible, and if so, what am I doing wrong?
Here is the code to create the table:
viewer = new TableViewer(container, SWT.NONE);
final Table table = viewer.getTable();
TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.LEFT);
TableColumn tableColumn = viewerColumn.getColumn();
tableColumn.setText(Messages.getString("column.header.name"));
tableColumn.setResizable(true);
tableColumn.setMoveable(false);
tableColumn.setWidth(500);
viewerColumn.setLabelProvider(new CompositeLabelProvider());
Here are the measure
and paint
methods for the custom label provider, CompositeLabelProvider
:
@Override
protected void measure(Event event, Object element) {
CompositeTableItem row = rowMap.get(element);
Composite contents = row.getContents(viewer.getTable().getParent());
Point size = contents.computeSize(SWT.DEFAULT, SWT.DEFAULT);
event.setBounds(new Rectangle(event.x, event.y, size.x, size.y));
}
@Override
protected void paint(Event event, Object element) {
CompositeTableItem row = rowMap.get(element);
Composite contents = row.getContents(viewer.getTable().getParent());
contents.redraw(event.getBounds().x, event.getBounds().y, event.getBounds().width, event.getBounds().height, true);
contents.update();
}