Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » problem with virtual table(the first items are re-shown twice)
problem with virtual table [message #508383] Mon, 18 January 2010 15:50 Go to next message
Luca Ferrari is currently offline Luca FerrariFriend
Messages: 159
Registered: November 2009
Senior Member
Hi all,
I've got a virtual table within a viewer declared as follows:

this.tableViewer = new TableViewer( parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.VIRTUAL );


the data is loaded into the table thru a DAO that loads chunks of data (e.g., 20 rows at time). Initially the DAO computes how many rows the table will have, and sets the size of table so to adjust the scrollbars:

this.tableViewer.getTable().setItemCount( this.getTableContentProvider().getDao().countAll() );


Now, the table is associated to a listener that defines the following method:

   public final void handleEvent(Event event) {
        // get the current table item
        TableItem tableItem = (TableItem) event.item;
        // get the index
        int index = event.index;

        
        // now get the next element from the dao
        T nextElement = ((ILazyLoadingDAO<T>) this.getDao()).next();
        // add the element to the list model
        this.getWritableListDataModel(false).add(nextElement);
        
        // set the table item in the table
        tableItem.setData( nextElement );
    }


So when the table needs another row, the next method on the DAO is called, such method loads the next element (or better the next chunk of elements and caches them for faster retrieval) and pass it back to the table, that set it in the table-item.
Now I'm sure the DAO is working well, and I've debugged the handleEvent method ensuring that the next() method always returns a new object from the database.
However, when I scroll the table for the first time I see the first displayed elements again, and then the table shows all different elements. What is happening is this:
*) the table is shown with the first n elements
*) I scroll the table to load elements after n
*) I see the first n elements and then new elements. If I scroll the table enough to force a new loading from the database, I can see new elements.

So only the first shown elements are displayed twice.
Anyone can give me any clue on what is happening?
Re: problem with virtual table [message #508387 is a reply to message #508383] Mon, 18 January 2010 15:57 Go to previous message
Luca Ferrari is currently offline Luca FerrariFriend
Messages: 159
Registered: November 2009
Senior Member
Arghhh!
Fixed: it was a buggy double loading of the first chunk of data, and since the model of the table is a WritableList adding elements to the list produced the double element in the model. I also added a security check in the next method:

    public final void handleEvent(Event event) {
        // get the current table item
        TableItem tableItem = (TableItem) event.item;
        // get the index
        int index = event.index;

        
        // now get the next element from the dao
        T nextElement = ((ILazyLoadingDAO<T>) this.getDao()).next();
        // add the element to the list model
[B]        WritableList model = this.getWritableListDataModel( false );
        if( ! model.contains( nextElement ) )
            model.add( nextElement );
[/B]        
        // set the table item in the table
        tableItem.setData( nextElement );
    }
Previous Topic:How to set the title's color of a group?
Next Topic:Text selection color of StyledText
Goto Forum:
  


Current Time: Sun Dec 08 03:25:56 GMT 2024

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

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

Back to the top