«« Is a Hashtable of <String, Vector> Threadsafe? 1 of 1531 »»
blog header image
Selecting with SWT Table and JFace TableViewer

A few nasty bugs were coming up in my GUI code and they were hard to recognize as GUI errors. I'm using the model-view-controller pattern for the three views so far in AudioMan, which use JFace TableViewers. TableViewers are an abstraction around an SWT Table that allow a programmer to use an SWT Table more conveniently.

The problems I ran into dealt with having a selection on an SWT TableViewer. If an item was selected in a TableViewer and I called a method to add to or remove from the model (which would then notify the TableViewer's content provider via a listener), I would get a duplicate of the selected item which would linger around and never go away. The solution was to deselect all of the elements in the TableViewer before doing additions or removals but that has to be done against the interior Table like:

tableViewer.getTable().deselectAll();

So after the operation was finished I wanted to select an item again. If I selected it with the TableViewer's select methods I would fire the selection listener attached to the TableViewer (and cause a stack overflow because of recursion because of the way I called my methods). To get around that I went back down to the interior SWT Table again to select the item, which doesn't fire the TableViewer's selection listener:

tableViewer.getTable().select(0);

It's one of those things that is a "duh!" moment once you figure it out.

By the way, I'm just finishing up the unit testing on the AudioMan stuff I have so far and I should release the first developer build tomorrow afternoon.

Posted at February 12, 2004 at 03:39 AM EST
Last updated February 12, 2004 at 03:39 AM EST
Comments

Interesting, this page was the first result of my search on google for: Jface tableviewer

Congrats!

» Posted by: Ali Echihabi at July 5, 2004 03:15 PM

How to add a check box(SWT.CHECK property) in the last column of a SWT Table?. pls help me ASAP

» Posted by: venkat at February 2, 2005 12:22 AM

This is some very useful stuff. Thanks for sharing your experience.

» Posted by: Ashish Joy at March 3, 2005 11:33 AM

first result on google for "swt table"...

» Posted by: kevin w at April 15, 2005 06:00 PM
Google
 
Search scope: Web ryanlowe.ca