[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [platform-swt-dev] [from e.tools] how to set a checkbox on any Table column?
|
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, displays a checkbox?
<snip>
>> 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);
>> 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.
Steve Northover Mon, 14 Apr 2003 18:53:57 -0400
>> Is the problem you are seeing this:
>> http://bugs.eclipse.org/bugs/show_bug.cgi?id=29910
I believe not, but I could be wrong. What I mean ...
Your code there is
http://bugs.eclipse.org/bugs/show_bug.cgi?id=29910
> for (int i = 0; i < NUM_ROWS; i++)
> {
> TableItem item = new TableItem(table, SWT.NONE);
> item.setText(new String[] { "" + i, "", "" + i});
> }
> TableItem[] items = table.getItems();
> for (int i = 0; i < items.length; i++)
> {
> TableEditor editor = new TableEditor(table);
> Button check = new Button(table, SWT.CHECK);
> check.setBackground(table.getBackground());
> editor.grabHorizontal = true;
> editor.setEditor(check, items[i], 1);
> // editor.grabHorizontal = true;
> /* Use this in 2.1 */
> // editor.layout();
> }
I.e. one has all the data for the table, and is setting TableEditor's
on the TableItem's. This is orthogonal to my scenario, in which there
is (usually) no data at table-creation time (it's an input widget). I
wanna be able to iterate over the columns, set CellEditor's on the
columns, and then, when the user hits the Add button, add a row of
default data, with a checkbox appearing in the appropriate row. This
works with TextCellEditor but not CheckboxCellEditor:
+ for (int i = 0; i < N_COLUMNS; i++) {
+ String cp = columnProperties[i];
+ if (cp.equals(NAME_PROPERTY)) {
+ cellEditors[i] = new TextCellEditor(table);
+ } else if (cp.equals(PATH_PROPERTY)) {
+ cellEditors[i] = new TextCellEditor(table);
+ } else if (cp.equals(CR_PROPERTY)) {
+ cellEditors[i] = new TextCellEditor(table);
- cellEditors[i] = new CheckboxCellEditor(table);
+ }
+ }
I.e. at runtime, when the user adds a row to the table and clicks on
one of the cells,
* TextCellEditor "does what I expect": it puts a Text over the cell,
and allows editing.
* CheckboxCellEditor does not do what I expect: it puts a read-only
Text over the cell, and toggles the String-casted value of the cell.
>>> So
>>> * Is this a CheckboxCellEditor bug?
I.e., are my expectations above wrong?
But this could be the same bug: I dunno. I do know that CellEditor
does not support setEditor(...) or layout(), so the fix cited in
bugzilla doesn't help this scenario.
Alternatively, to make my scenario work, do I need to add
TableEditor-using code like that in bugzilla to my Add-button handler?
Note that the handler is currently like
> protected void handleAddForwardButton(IMappingData amrd) {
> amrd.addForward(amrd.createBlankForward());
> forwardsTableViewer.refresh();
> forwardsTableViewer.editElement(bf, NAME_COLUMN);
> updateButtonStates(amrd);
> }
i.e. not TableItem-aware.