Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How listen for check box in JFace Table Viewer

I am using a Table Viewer with check boxes as following:

final TableViewer legendViewer = new TableViewer(parent, SWT.CHECK);

What is THE solution to listen to check boxes selection/unselection in this viewer ?

Thanks in advance, Manu

like image 885
Manuel Selva Avatar asked Jul 01 '11 06:07

Manuel Selva


2 Answers

Take a look at class CheckboxTableViewer derived from TableViewer which simplifies the use of a TableViewer with the SWT.CHECK style.

Add an implementaion of ICheckStateListener to your CheckboxTableViewer via addCheckStateListener(). The only method you have to implement is checkStateChanged(CheckStateChangedEvent event) where event contains all necessary information about the state change.

If you need only one column you can create a CheckboxTableViewer like this:

CheckboxTableViewer myTableViewer = CheckboxTableViewer.newCheckList(parent, style);
like image 103
Claimos Avatar answered Nov 02 '22 11:11

Claimos


You listen for SWT.Selection events on the Table and check for event.detail == SWT.CHECK...

See this example for actual code....

like image 9
Tonny Madsen Avatar answered Nov 02 '22 09:11

Tonny Madsen