[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Huge table, records, scrolling, etc.

On Fri, 14 Oct 2005 15:28:13 +0200, Mr. Burns <Mr._Burns@xxxxxx> wrote:

Hello Haris,

I want it to do using SWT instead of AWT/SWING!
But thanks, anyway,

Any other ideas?



Hello Mr. Burns,

I'm struggling with quite the same problem.
At the moment I see two solutions

First is to give KTable a chance. It's kind of a JTable port to SWT.
You might take a look at http://sourceforge.net/projects/ktable
The second is to put a org.eclipse.jface.viewers.TableViewer on top of the SWT Table.
To actually work with a SWT.VIRTUAL table, you must connect a LabelProvider and a ContentProvider to your TableViewer. While the LabelProvider is easy (you stated you're a beginner, so don't hesitate to ask about it, too); the ContentProvider is the interesting one when content is stored in a database. Therefore you have to code a ContentProvider that implements
org.eclipse.jface.viewers.LazyContentProvider. To do so you have to implement the method
void updateElement(int index)
The API doc tells "Called when a previously-blank item becomes visible in the TableViewer. If the content provider knows the element at this row, it should respond by calling TableViewer#replace(Object, int)"
The second parameter is the index again, while the first one is the object that the content provider retrieved from DB (please remind that the presentation is done by the LabelProvider)


So when the user scrolls to the last record (e.g. using the scrollbar) you have to return whatever you consider to be the last object fulfilling the restrictions.

To batch the select statements as you're thinking about, your content provider should cache the retrieved objects.
So when it receives a updateElement (X), it will first look in the cache and if it isn't there,
load it together with N others, that are all reminded in the local cache. You guess the idea.


There's one last pitfall: You must tell the table how much records there are to come (count (*)) by calling TableViewer.setItemCount(int) before displaying the first bunch.

Hope this helps,
Michael