Skip to main content
Jump to: navigation, search

Difference between revisions of "Tables And Trees And NativeControls"

(SWT: Place SWT-Controls into the Tree/Table-Widget [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java?view=co Snippet])
(cleaned up some of the wording in the first paragraph)
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:
  
 
Common use cases are:
 
Common use cases are:
* CheckBox-Widget in column other than the first 1
+
* CheckBox-Widget in column other than the first one
 
* Radio-Boxes, Buttons
 
* Radio-Boxes, Buttons
  
 
== The Solutions to the problem ==
 
== The Solutions to the problem ==
 
=== SWT: Place SWT-Controls into the Tree/Table-Widget [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java?view=co Snippet] ===
 
=== SWT: Place SWT-Controls into the Tree/Table-Widget [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet126.java?view=co 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
+
The main drawback is that you will allocate a resource for every cell that you display, 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 [http://tom-eclipse-dev.blogspot.com/2007/01/what-items-are-visible-in-tabletree.html Blog-Entry].  
+
cell is not shown. This happens because SWT does not inform you which controls are in/out of your view-area. For discussion and a possible solution take a look at this [http://tom-eclipse-dev.blogspot.com/2007/01/what-items-are-visible-in-tabletree.html blog post].  
There's a feature request for JFace to provide support for native-controls in TreeViewer/TableViewer (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=36977 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.
+
There is a feature request for JFace to provide support for native controls in TreeViewer/TableViewer (see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=36977 JFace-Feature-Request]). The JFace 3.3 API provides the needed bits, as the example attached to the bug shows, but to summarize, using Native-Controls is not a good solution.
  
 
=== SWT: Use Images instead of Widgets ===
 
=== SWT: Use Images instead of Widgets ===
Line 17: Line 17:
  
 
=== SWT: Use Owner Draw ===
 
=== 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 [http://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm Aritcle] and [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/ JFace Snippets]
+
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 [http://www.eclipse.org/articles/Article-CustomDrawingTableAndTreeItems/customDraw.htm Article] and [http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/viewers/ JFace Snippets]
  
 
=== Nebula: Use CompositeTable ===
 
=== Nebula: Use CompositeTable ===

Latest revision as of 18:24, 19 May 2009

The Problem

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 one
  • Radio-Boxes, Buttons

The Solutions to the problem

SWT: Place SWT-Controls into the Tree/Table-Widget Snippet

The main drawback is that you will allocate a resource for every cell that you display, even if the cell is not shown. This happens because SWT does not inform you which controls are in/out of your view-area. For discussion and a possible solution take a look at this blog post. There is 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, as the example attached to the bug shows, but to summarize, 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.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.