Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 314050 - [Viewers] TableViewer with SWT.VIRTUAL and ViewerComparator does not add elements properly
Summary: [Viewers] TableViewer with SWT.VIRTUAL and ViewerComparator does not add elem...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-23 14:38 EDT by npozar CLA
Modified: 2019-11-14 03:36 EST (History)
3 users (show)

See Also:


Attachments
Code that reproduces the bug in TableViewer.add with SWT.VIRTUAL (1.96 KB, text/x-java)
2010-05-23 14:39 EDT, npozar CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description npozar CLA 2010-05-23 14:38:09 EDT
Build Identifier: 20100218-1602

This is a bug in AbstractTableViewer.VirtualManager.notVisibleAdded(element, index) method. This method doesn't trigger the request of a SWT.VIRTUAL Table to update all elements that can be affected by inserting at index. It uses doSetItemCount that triggers the update of the last element only. The bug can be easily fixed by adding doClearAll() as the last statement of the method.   

Reproducible: Always

Steps to Reproduce:
1. Create TableViewer with SWT.VIRTUAL and with ViewerComparator
2. Provide some input ({"b", "c"})
3. add an element ("a") that should appear anywhere else than as the last element
4. table shows b, c, c instead of a, b, c 

See attached snipped
Comment 1 npozar CLA 2010-05-23 14:39:58 EDT
Created attachment 169618 [details]
Code that reproduces the bug in TableViewer.add with SWT.VIRTUAL
Comment 2 Hitesh CLA 2010-07-19 07:38:10 EDT
Yes, the problem appears to be with VirtualManager.notVisibleAdded(Object,int) or createItem(Object element, int index). If we had *sorted* elements 'a','b','c','d','e' where 'd' was already materialized and we now added another element < 'd', the viewer would demonstrate this bug. The index maps to an element, but the method notVisibleAdded does not take that into account.

I guess we'd need to see if adding an item at an index performs well enough for a fix.
Comment 3 Boris Bokowski CLA 2010-07-19 13:39:51 EDT
The SWT.VIRTUAL support in TableViewer assumes that you don't use a ViewerComparator - one of the goals of this support was that the content provider is only asked for elements that are actually being displayed. For this to work, you should do the sorting on your end (e.g. in the content provider, or further below such as SQL "ORDER BY" clauses).

I'd be inclined to just change the JavaDoc to be clearer on this point, instead of trying to support ViewerComparator and SWT.VIRTUAL at the same time.
Comment 4 Hitesh CLA 2010-07-20 06:23:09 EDT
(In reply to comment #3)
> The SWT.VIRTUAL support in TableViewer assumes that you don't use a
> ViewerComparator - one of the goals of this support was that the content
> provider is only asked for elements that are actually being displayed. For this
> to work, you should do the sorting on your end (e.g. in the content provider,
> or further below such as SQL "ORDER BY" clauses).
> 

Hmm. I can see the code reflect the same throughout.

> I'd be inclined to just change the JavaDoc to be clearer on this point, instead
> of trying to support ViewerComparator and SWT.VIRTUAL at the same time.

Ok.Do we update the doc for the method #insert(Object, int) as well, or the current doc will suffice? 

Thanks for the heads-up.
Comment 5 Boris Bokowski CLA 2010-07-20 18:08:10 EDT
(In reply to comment #4)
> Ok.Do we update the doc for the method #insert(Object, int) as well, or the
> current doc will suffice? 

The JavaDoc for insert() should be updated too.
Comment 6 Hitesh CLA 2010-07-21 06:55:49 EDT
(In reply to comment #5)
> (In reply to comment #4)
> > Ok.Do we update the doc for the method #insert(Object, int) as well, or the
> > current doc will suffice? 
> 
> The JavaDoc for insert() should be updated too.

Thanks. Will attach a patch with Jdoc changes.
Comment 7 npozar CLA 2010-07-21 10:20:36 EDT
(In reply to comment #3)
> The SWT.VIRTUAL support in TableViewer assumes that you don't use a
> ViewerComparator - one of the goals of this support was that the content
> provider is only asked for elements that are actually being displayed. For this
> to work, you should do the sorting on your end (e.g. in the content provider,
> or further below such as SQL "ORDER BY" clauses).
> 
> I'd be inclined to just change the JavaDoc to be clearer on this point, instead
> of trying to support ViewerComparator and SWT.VIRTUAL at the same time.

Hi,

I just started using JFace so I don't have much experience, but I think it would be a good idea to allow TableViewer support Table with SWT.VIRTUAL and ViewerComparator and ViewerFilter at the same time. Especially since the code is already there and there's only this small bug that can be fixed easily. The behavior then changes depending on what the client uses as the content provider: IContentProvider or ILazyContentProvider, i.e. if the content provider provides all elements or only visible elements. 

My concern is that Table without SWT.VIRTUAL has a very poor performance if it contains more than a small number elements. I like TableViewer's sorting and filtering ability since I don't have to write this code every time I need another Table.
Comment 8 Boris Bokowski CLA 2010-07-21 10:38:52 EDT
(In reply to comment #7)
> I just started using JFace so I don't have much experience, but I think it
> would be a good idea to allow TableViewer support Table with SWT.VIRTUAL and
> ViewerComparator and ViewerFilter at the same time. Especially since the code
> is already there and there's only this small bug that can be fixed easily. The
> behavior then changes depending on what the client uses as the content
> provider: IContentProvider or ILazyContentProvider, i.e. if the content
> provider provides all elements or only visible elements. 

Would you be able to contribute a patch? The patch should fix the bug but also add the necessary information to the JavaDoc so that users know what to expect. See also http://wiki.eclipse.org/Platform_UI/How_to_Contribute
Comment 9 Lars Vogel CLA 2019-11-14 03:36:05 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.