Bug 172640 - [Viewers] Virtual TreeViewer/ILazyTreePathContentProvider: preservingSelection and refresh not always working
Summary: [Viewers] Virtual TreeViewer/ILazyTreePathContentProvider: preservingSelectio...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P1 normal (vote)
Target Milestone: 3.3 M7   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 167668
  Show dependency tree
 
Reported: 2007-02-02 05:49 EST by Patrick Streule CLA
Modified: 2007-05-04 09:43 EDT (History)
3 users (show)

See Also:


Attachments
Plugin-in with a sample view demonstrating the problem (16.89 KB, application/zip)
2007-02-02 05:52 EST, Patrick Streule CLA
no flags Details
work in progress (tests don't pass yet) (8.38 KB, patch)
2007-04-11 17:04 EDT, Boris Bokowski CLA
no flags Details | Diff
updated patch (still got an endless loop in the test) (13.43 KB, patch)
2007-04-12 16:46 EDT, Boris Bokowski CLA
no flags Details | Diff
updated patch, to be tested on GTK and MacOS (14.33 KB, patch)
2007-04-16 12:47 EDT, Boris Bokowski CLA
no flags Details | Diff
updated patch, tests are green on MacOS (14.05 KB, patch)
2007-04-16 13:45 EDT, Boris Bokowski CLA
no flags Details | Diff
Standalone snippet (7.02 KB, text/plain)
2007-04-16 13:50 EDT, Boris Bokowski CLA
no flags Details
latest patch (13.98 KB, patch)
2007-04-17 12:19 EDT, Boris Bokowski CLA
no flags Details | Diff
updated patch, hopefully no longer causing GPs (17.70 KB, patch)
2007-04-19 14:30 EDT, Boris Bokowski CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Streule CLA 2007-02-02 05:49:39 EST
Build ID: I20061214-1445

This is with 3.3M4 using a TreeViewer with SWT.VIRTUAL and a ILazyTreePathContentProvider.

The scenario is as follows:
There are a couple of root elements in the tree that can be sorted (in the model). After the sorting, the viewer is refreshed. Observed: In this situation the selection is often not preserved. If there are expanded elements in the tree, blank children are visible and the child count doesn't seem to be correct for some elements, which in turn can lead to AIOOBEs in the content provider.

Steps To Reproduce:
I have attached a plug-in that allows to reproduce the behaviour. Open the SampleView and follow these steps:

For the preservingSelection part:
1. Select the first element in the tree
2. Press the Sort action repeatedly

-> The selection will go away

For the refresh part:
1. Expand some elements in the tree
2. Press Sort
-> There are blank children


More information:

The problem both for the preservingSelection and the refresh artifacts seems to be that lazily updating single items leaves the tree temporarily in a state where multiple equal elements exist on the same level. An example to illustrate:

1. Original state:
[element 1]
[element 2]
[element 3]

2. Reverse sort order of the model elements and refresh the viewer

3. Callback to update the first element leads to the following state
[element 3]
[element 2]
[element 3]

In this situation, the selection cannot be restored as [element 1] is temporarily missing.
Comment 1 Patrick Streule CLA 2007-02-02 05:52:02 EST
Created attachment 58104 [details]
Plugin-in with a sample view demonstrating the problem
Comment 2 Philipe Mulet CLA 2007-04-03 11:36:43 EDT
Are we doing anything for 3.3 ?
Comment 3 Boris Bokowski CLA 2007-04-03 12:16:47 EDT
Darin, could this be related to bug 173898?
Comment 4 Darin Wright CLA 2007-04-03 12:34:02 EDT
Yes, I think this is related to bug 173898. As part of my patch to that problem, I overrode replace(...) in the tree viewer to "clearAll" children when an item gets mapped to a new element - that way we are asked to refresh the children again for that element.
Comment 5 Boris Bokowski CLA 2007-04-11 16:32:05 EDT
I have a fix for the refresh case (no blank children anymore), but preserving the selection (and expansion state) is difficult, if not impossible for virtual trees. We should discuss this when you have time.
Comment 6 Boris Bokowski CLA 2007-04-11 16:57:16 EDT
(In reply to comment #0)

> ...which in turn can lead to AIOOBEs in the content provider.

The content provider should tolerate this - see the Javadoc: "If the content provider knows the child element for the given parent at this index, it should respond by calling {@link TreeViewer#replace(Object, int, Object)}"

I.e. if the content provider does not have anything at that index, it should not respond, and certainly not throw exceptions.
Comment 7 Boris Bokowski CLA 2007-04-11 17:04:59 EDT
Created attachment 63551 [details]
work in progress (tests don't pass yet)
Comment 8 Boris Bokowski CLA 2007-04-12 16:46:11 EDT
Created attachment 63669 [details]
updated patch (still got an endless loop in the test)

Isn't it fun?
Comment 9 Boris Bokowski CLA 2007-04-16 12:47:26 EDT
Created attachment 63923 [details]
updated patch, to be tested on GTK and MacOS

The endless loop was a problem in the tests.  With TreeViewer and SWT.VIRTUAL, you have to be very careful not to put two equal elements under the same parent.
Comment 10 Boris Bokowski CLA 2007-04-16 13:45:53 EDT
Created attachment 63926 [details]
updated patch, tests are green on MacOS
Comment 11 Boris Bokowski CLA 2007-04-16 13:50:20 EDT
Created attachment 63930 [details]
Standalone snippet

for manual testing
Comment 12 Boris Bokowski CLA 2007-04-16 14:01:13 EDT
The tests pass on GTK, but by running the snippet, I was able to crash SWT, see bug 182598.
Comment 13 Boris Bokowski CLA 2007-04-16 14:06:44 EDT
The tests pass on Windows XP too.  Darin, Patrick, could you give this patch a try please?
Comment 14 Boris Bokowski CLA 2007-04-16 14:12:16 EDT
The snippet works on the Mac and on Windows XP.
Comment 15 Darin Wright CLA 2007-04-16 15:25:37 EDT
The debugger still works with the patch. It doesn't fix the debugger's problem noted in bug 182008, but that could be due to debug specific code.
Comment 16 Darin Wright CLA 2007-04-16 15:26:13 EDT
(Note, with this patch, I can remove my workaround to clear items when they are replaced in the tree).
Comment 17 Boris Bokowski CLA 2007-04-17 12:19:02 EDT
Created attachment 64058 [details]
latest patch

Do not call clearAll() from setChildCount() any more.
Comment 18 Boris Bokowski CLA 2007-04-19 14:30:22 EDT
Created attachment 64333 [details]
updated patch, hopefully no longer causing GPs
Comment 19 Boris Bokowski CLA 2007-04-19 14:52:21 EDT
Today's patch tested on the Mac (tests pass, snippet works).  Found bug 183254.
Comment 20 Boris Bokowski CLA 2007-04-19 15:36:10 EDT
Tested on GTK, tests pass, snippet works, found bug 183267.
Comment 21 Boris Bokowski CLA 2007-04-19 15:39:41 EDT
Patch released >20070419.
Comment 22 Darin Wright CLA 2007-04-20 16:59:03 EDT
This fix is causing expanded nodes in the debug viewers to flash on each refresh. The viewer is supressing setData callbacks on expanded nodes which does not allow us to preserve lables.

See bug 183463. We can workaround it, but the workaround is not optimal (requires copying private methods from TreeViewer). Perhaps the viewer could preserve labels rather than set the text to empty? (also requires preserving images, etc). Or perhaps the viewer could provide a method to preserve labels for an item that we could override?
Comment 23 Boris Bokowski CLA 2007-04-20 20:46:33 EDT
(In reply to comment #22)
> This fix is causing expanded nodes in the debug viewers to flash on each
> refresh. The viewer is supressing setData callbacks on expanded nodes which
> does not allow us to preserve lables.

This was necessary to prevent blank children - upon refresh, the viewer needs to traverse all expanded nodes to let the content provider update the corresponding elements and child counts.

Let's continue the discussion on bug 183463.
Comment 24 Boris Bokowski CLA 2007-05-04 09:43:24 EDT
Verified on Windows XP using I20070503-0842.