[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] [performance] When is updateElement called for a Virtual TableViewer's ILazyContentProvider?

I've developed a virtual table viewer that uses an ILazyContentProvider to 
retrieve the table items (in this case address book contacts) from a 
database.
To fetch batches of contacts from the database using SQlite, the 
updateElement method looks as follows:

public void updateElement(int index)
{
 int start = (index / PAGE_SIZE) * PAGE_SIZE;
 System.out.println("Fetching index " + start + " for query " + index);

 DatabaseManager dm = AddressBookPlugin.getDefault().getDatabaseManager();
 dm.setLimit(start, PAGE_SIZE);
 ArrayList<ArrayList<String>> data = dm.getData();

 int end = Math.max(data.size(), PAGE_SIZE);

 for (int i = 0; i < end; i++)
  viewer.replace(data.get(i), start + i);
}

However, performance is still poor, and looking at the console I'm seing 
this when scrolling in the viewer:

Fetching index 0 for query 0
Fetching index 0 for query 0
Fetching index 0 for query 0
Fetching index 2048 for query 2338
Fetching index 2048 for query 2338
Fetching index 2048 for query 2338
Fetching index 4096 for query 4676
Fetching index 4096 for query 4676
Fetching index 4096 for query 4676

Apparently, updateElement is called three times with the same index when 
scrolling (an in turn hits the DB in my case). This seems strange as the 
methods doc says:
"Called when a previously-blank item becomes visible in the TableViewer". I 
was assuming that a previously-blank item is no longer blank after updating 
once.

I assume this could be caused by the implementation of the viewer's refresh 
method:

public void replace(Object element, int index) {
 if (checkBusy())
  return;
 Item item = doGetItem(index);
 refreshItem(item, element);
}

If the checkBusy() is the problem- then what could be a cure??

Thanks,
Andi