Dynamically recreating a Table/Tableviewer

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Dynamically recreating a Table/Tableviewer

Postby IanHarac » Tue Nov 03, 2009 8:21 am

I have been trying to do what I thought would be easy, but it turns out to be very difficult, or I'm missing something very obvious, despite a lot of Google searches.

I have a form with a table. I want the viewer to open a file (such as a CSV file, though it's not relevant), and the table shows the user what's in the file. Then they can open a different file.

The first part works. The second...

Since each file has a different structure (column names, column types), I have to redo the table each time.

I can't (that I can tell) delete columns from a table in SWT.
I can't (that I can tell) set the table associated with a TableViewer.

So I try to recreate the TableViewer/Table combo.

However, this results in a blank table on the screen. It appears the table associated with the viewer is being covered up/not drawn, and even using MoveAbove() doesn't help. Looking at the getChildren() stack, it seems the table that is created by the call to new TableViewer() is never disposed, i.e, if I call it three times, I will see three Tables as children. Explictly disposing it via:

Table t=myTableViewer.getTable();
t.dispose();

Doesn't seem to work either.

What is the optimal way to dynamically create and view tables using SWT? This is such a common procedure in programming that I can't believe it's giving me such difficulty.

Is the problem that the other controls are still "connected" via the layoutData? Is there a way to "detach" a control?
IanHarac
 
Posts: 27
Joined: Wed Jan 10, 2007 7:04 am

Re: Dynamically recreating a Table/Tableviewer

Postby Eric Clayberg » Tue Nov 03, 2009 9:19 am

Never had a reason to do anything like that, but this would be a great question for the Eclipse SWT newsgroup.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Dynamically recreating a Table/Tableviewer

Postby IanHarac » Tue Nov 03, 2009 12:46 pm

I believe it is a rule that one always finds the answer right after one asks for help.

I was not calling layout() after adding the controls programmatically. (I tried update and redraw).
IanHarac
 
Posts: 27
Joined: Wed Jan 10, 2007 7:04 am

Re: Dynamically recreating a Table/Tableviewer

Postby Eric Clayberg » Tue Nov 03, 2009 1:21 pm

That would do it. The layout() method is very important.

It is also always a good idea to post an example. It is much easier to try to get an existing example to work than to construct one from scratch (that might not even be accurate).
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Re: Dynamically recreating a Table/Tableviewer

Postby IanHarac » Tue Nov 03, 2009 1:29 pm

Eric Clayberg wrote:That would do it. The layout() method is very important.

It is also always a good idea to post an example. It is much easier to try to get an existing example to work than to construct one from scratch (that might not even be accurate).


What I did was copy the code which generated the table and viewer (from CreateContents()) to a new method. It took me a bit to notice the layout() call after the CreateContents() call, as I generally try to leave any code generated by WindowBuilder alone. All in all, it was a Learning Experience TM.

Basically, I had solved the problem two days ago, except for the call to layout(), and have spent a lot of time trying increasingly baroque "solutions" that were, of course, unnecessary. So it goes. OTOH, I've learned a lot more about the structures of tables, viewers, and so on.
IanHarac
 
Posts: 27
Joined: Wed Jan 10, 2007 7:04 am

Re: Dynamically recreating a Table/Tableviewer

Postby Eric Clayberg » Tue Nov 03, 2009 7:42 pm

I'm glad you got it working.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: Google [Bot] and 2 guests