Tables And Trees And NativeControls
People often face the problem that they want to show native controls into Tables and Trees.
Common use cases are:
- CheckBox-Widget in column other than the first 1
- Radio-Boxes, Buttons
The Solutions to the problem
SWT: Place SWT-Controls into the Tree/Table-Widget Snippet
This solution has the draw-back to that you'll allocate a resource for every cell you'll display this control in even if the row is not shown because SWT doesn't inform you which controls are in/out of your view-area. For discussion and a possible solution take a look at this Blog-Entry. There's a feature request for JFace to provide support for native-controls in TreeViewer/TableViewer (see JFace-Feature-Request). The JFace 3.3 API provides the needed bits for as a the example attached to the bug shows but to summerize using Native-Controls is not a good solution.
SWT: Use Images instead of Widgets
This solution is fairly straight forward if you provide Images instead of Native-Widgets you'll only have to allocate the image once and reuse it everywhere. This way your resource allocation count is very low and table/tree performance is much better. Many people have not used this possibility because they thought that this would break the platform L&F which was one of things they abandoned Swing and switched to SWT. But this limitation can be overcome fairly easy by caputuring a Screen-Shot from the Control on the fly and presenting it. So the Widget looks as native as possible (without the hover-effects currently). The solution is presented in this Blog-Entry. Another advantage is that this plays nicely with the JFace-Viewer-Framework.
SWT: Use Owner Draw
Since 3.2 you can but your Table/Tree into OwnerDraw mode and draw the cell contents yourself. This way you can draw a faked button, ... in any control. Since 3.3 JFace provides API to easily use OwnerDraw in combination with LabelProviders. For more information on Owner Draw please refer to this Article and JFace Snippets
Nebula: Use CompositeTable
The nebula project contains a control who mimics a Table using native widgets and to try to bring the resource allocation count down to a useable number it reuses controls and only holds these ones currently shown. For more detailed information and status of this widget please ask at the nebula-newsgroup (search the newsgroup and nebula-dev-mailing list about known limitations and possible work-arounds). A known draw back currently is that CompositeTable doesn't provide a JFace-Viewer-API. Examples can be found here
Nebula: Use Grid
The Grid-Control is also custom drawn and you can even customize it by deploying your own renders (besides that it has many other cool features not part of SWT-Tree/SWT-Table). When using 3.3 you even have the possibility to use JFace-Viewers. For more information and status please ask at the nebula-newsgroup. For examples can be found here and here. Checkboxes in arbitary columns are supported out of the box.