Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » [JFace] setting a checkbox in a Table
[JFace] setting a checkbox in a Table [message #7757] Wed, 23 April 2003 21:12 Go to next message
Tom Roche is currently offline Tom RocheFriend
Messages: 160
Registered: July 2009
Senior Member
[If this is really an SWT issue, please lemme know, and I'll ask in
e.p.swt.]

How does one programmatically check a box in a Table, based on the
state of the underlying model, when using a CheckboxCellEditor?
Specifically:

I've got a wizard that creates a thing (a foo), which can contain a
list of other things (bars). Bars have properties, most of which are
text (String), but one of which is boolean. I use a Table to represent
the bars (1 row per bar), and use attached Add and Remove buttons to
manage the rows.

The wizard can be invoked in 2 ways:

* "create": As a New Wizard, it creates a new foo, with no bars. If
the user hits my Add button, I create a new, blank bar, the boolean
property of which is false by default (as decreed by an external
DTD).

* "modify": From an editor, the wizard can be invoked on a
pre-existing foo in which one or more bars may already exist, with
each property (including the boolean) already set.

Formerly I only handled the text properties, but now I'd like to
handle the boolean, using a checkbox. I create the Table control
(more-or-less :-) thusly:

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 the "create" context

+ the box is unchecked, but the boolean property is false, so that's
correct

+ the appropriate listener toggles the property when the box is
un/checked

but not in the "modify" context: the box always comes up unchecked,
even if the boolean property in the model is true. So how do I make
the box initially appear checked, if the corresponding bar's
boolean property is set?
Re: [JFace] setting a checkbox in a Table [message #9143 is a reply to message #7757] Thu, 24 April 2003 11:21 Go to previous message
Eclipse UserFriend
Originally posted by: genadyb.inter.net.il

I'm not sure it will help, but did you try
CheckboxTableViewer class ?

Tom Roche wrote:
> [If this is really an SWT issue, please lemme know, and I'll ask in
> e.p.swt.]
>
> How does one programmatically check a box in a Table, based on the
> state of the underlying model, when using a CheckboxCellEditor?
> Specifically:
>
> I've got a wizard that creates a thing (a foo), which can contain a
> list of other things (bars). Bars have properties, most of which are
> text (String), but one of which is boolean. I use a Table to represent
> the bars (1 row per bar), and use attached Add and Remove buttons to
> manage the rows.
>
> The wizard can be invoked in 2 ways:
>
> * "create": As a New Wizard, it creates a new foo, with no bars. If
> the user hits my Add button, I create a new, blank bar, the boolean
> property of which is false by default (as decreed by an external
> DTD).
>
> * "modify": From an editor, the wizard can be invoked on a
> pre-existing foo in which one or more bars may already exist, with
> each property (including the boolean) already set.
>
> Formerly I only handled the text properties, but now I'd like to
> handle the boolean, using a checkbox. I create the Table control
> (more-or-less :-) thusly:
>
> 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 the "create" context
>
> + the box is unchecked, but the boolean property is false, so that's
> correct
>
> + the appropriate listener toggles the property when the box is
> un/checked
>
> but not in the "modify" context: the box always comes up unchecked,
> even if the boolean property in the model is true. So how do I make
> the box initially appear checked, if the corresponding bar's
> boolean property is set?
>
Previous Topic:CompareViewerSwitchingPane
Next Topic:Eclipse on LinuxPPC ?
Goto Forum:
  


Current Time: Tue Oct 01 11:22:23 GMT 2024

Powered by FUDForum. Page generated in 0.03675 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top