Home » Eclipse Projects » Eclipse Platform » [JFace] CheckboxCellEditor has bad UI except in first column
[JFace] CheckboxCellEditor has bad UI except in first column [message #7951] |
Wed, 23 April 2003 20:34  |
Eclipse User |
|
|
|
summary: I would like to be able to populate an arbitrary column of a
Table with checkboxes using a CheckboxCellEditor. I have found that
this results in an incorrect UI unless the CheckboxCellEditor is used
in the first column (only), and then only if the TableViewer (and
therefore the Table) is constructed in a non-generic way. I would like
to know if this is due to a defect in my procedure, a defect in JFace,
or something else. (If not a defect in my procedure, I will put a
defect in Bugzilla on the appropriate component.)
details:
Tom Roche Mon, 14 Apr 2003 17:50:16 -0400
>> The question is: how can one create a Table so that every cell in
>> any specified column(s), not merely the first [column], displays a
>> checkbox?
Consider the following example:
I would like to use a table to display a dynamic list of foo's having
3 properties: 2 properties (call them "bar" and "baz") are String
text, 1 is boolean (so just call it "boolean"). Any number (including
0) of foo's may exist when the table is created. All properties should
be modifiable. I want to display each bar as a TableItem over 3
columns, in order: the bar column, the baz column, and the boolean
column. The boolean property must display as a checkbox, with a check
corresponding to "true," and vv.
>> Both I and another newsgrouper have tried to do this in what
>> appears to be "the obvious way": just iterate over the columns, and
>> put a CheckboxCellEditor on the desired column, e.g.
>> cellEditors[0] = new TextCellEditor(table);
>> cellEditors[1] = new TextCellEditor(table);
>> cellEditors[2] = new CheckboxCellEditor(table);
Done as above,
>> The texts work, but no checkbox displays. Interestingly, one
>> observes (again, not just me) a "checkbox-style" interaction. If
>> one put (boolean) data on a cell in the 3rd column, it displays as
>> text. If one then clicks on a cell in the 3rd column, the strings
>> toggle ("false" <-> "true"), and don't become editable.
By contrast, the TextCellEditor's "do the right thing": they display,
and allow one to edit normally, the String data.
The only way I have found to make a checkbox display, using a
CheckboxCellEditor, requires using the checkbox in the first column
only. My procedure is like:
0 I create an array of column properties, which are basically just the
String's in the column headers. columnProperties[0] corresponds to
the boolean property (see step 2).
1 I create an array of CellEditor's based on the column properties.
cellEditors[0] is a CheckboxCellEditor, and the rest are
TextCellEditor's.
2 I create a TableViewer using TableViewer(Composite, int), where the
int contains the style bits for creating the Table. Among the bits
set is SWT.CHECK, which creates a checkbox in the first column.
(This is the only way I know to create a checkbox in a table that
will work with a CheckboxCellEditor ... but that's a subject for
another post.)
3 I set the arrays of column properties and CellEditor's on the table
viewer.
4 I add listeners to the table and table viewer.
This works, in that un/checking the box toggles the boolean property
in the model, but has its own problems:
- Every checkbox comes up unchecked, even if the boolean property in
the foo corresponding to that TableItem is set to true (about which
I have posted separately).
- Only the first column can have a checkbox. (In my case, details of
the implementation made the third column greatly preferable as a
location.)
So I'm wondering:
* Can one fill any column with checkboxes using CheckboxCellEditor?
If not:
- Is this not a CheckboxCellEditor defect?
- Is there a currently supported alternative?
If so:
+ How can one fill any column with checkboxes using
CheckboxCellEditor?
|
|
|
Re: [JFace] CheckboxCellEditor has bad UI except in first column [message #10748 is a reply to message #7951] |
Thu, 24 April 2003 10:45   |
Eclipse User |
|
|
|
The check style on a table indicates that the entire row is checked or
not checked, not that of an individual column. That is why the visible
check box only shows up in the first column (actually it is treated as
not even part of the first column by the viewer, but as a row property).
And if you really want to use the checkbox concept as described above,
you would use a CheckBoxTableViewer instead. Then the checkbox listener
would be used to be notified when the check box is checked or unchecked.
Since CheckboxCellEditor only works with the value of the column
(returned by the CellModifier that you set into the table viewer), and
since the checkbox that results from the CHECK style is independent of
the value of the column 0, the cell editor has no effect on the check
box itself.
So if you want a check box in your column and not a check row style, you
need:
1) A ITableLabelProvider implementation that will return an image of a
checked checkbox or an unchecked checkbox for the specified column. (You
will need to create your own, I don't know of any that Eclipse provides
for this). PS: Don't create the image on the fly each time it is needed.
If you do then you will be creating a bunch of images that need to be
cleaned up, and all of the same two images. Instead keep the two images
in the instance of the ITableLabelProvider, and in its dispose method,
dispose of the two images. That way they won't hang around when your
table is no longer around.
2) The property value returned by the ICellModifier given to the
TableViewer needs to return a Boolean value for this column.
3) Have a CheckboxCellEditor for that column.
In this way clicking on the cell will cause CellModifier to return the
current Boolean value for the cell, give it to the CheckboxCellEditor,
which will invert the value and this will then be set back through the
CellModifier to change the value in the cell. This will then cause the
ITableLabelProvider to display either the checked or unchecked image.
PS: I gathered all of this from looking through the code (especially at
the one usage of the CheckBoxCellEditor in TaskList), so I haven't
actually done this.
Rich Kulp
|
|
| |
Goto Forum:
Current Time: Fri May 09 22:07:14 EDT 2025
Powered by FUDForum. Page generated in 0.08738 seconds
|