Community
Participate
Working Groups
I am utilizing org.eclipse.ui.progress.DeferredTreeContentManager to populate a TreeViewer. The code in the DTCM returns a "place holder" element to be included in the tree while a back ground job actually populates the Tree's contents. After the tree's contents are finished, the place holder object is removed from the Tree to leave only the remaining valid elements. My problem is that I have a long list of items and when the place holder element is removed, the focus/scroll bars are set to the bottom of the list. This is an obvious change in behavior from the old/traditional way of populating the Tree as when the initialization was done the focus was set on the top of the Tree. Since it would be a huge help to get this fixed, I will attach an extremely simple sample project to illustrate the problem.
Created attachment 87694 [details] sample project to illustrate problem This is a simple project with a view. Inside the view there is a boolean value called DEFERRED_MODE. When this value is set to false, the traditional way of populating the Tree is used. When this value is set to true, the DeferredTreeContentManager is used to populate the Tree. You will see when the value is false, when the tree is initialized, the focus is at the top of the Tree. When the value is true, the removal of the "place holder" object in DeferredTreeContentManager sets the focus of the Tree to the bottom. This problem will not only be relevant to PDE, but anyone who tries to use DeferredTreeContentManager with a list of elements long enough to need scroll bars.
Boris, we can look at this together or I can look into it with an SWT only example. It sounds like an SWT bug.
I was able to track this down. SWT has nothing to do with it, it is the sorting. While objects are being added to the viewer, the "Pending" item ends up at the bottom of the table ("Pending" coming after "Object 0"..."Object 99"). The "Pending" item however has the focus, it received it when you created the tree, being the first and only item. So when that item is finally removed after all real items have been added, SWT moves the focus to the item beside it, which happens to be the last item "Object 99". One possible fix is to use a sorter that keeps the pending node at the beginning, for example like this: viewer.setSorter(new ViewerSorter(){ public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof TreeObject && e2 instanceof TreeObject) { return super.compare(viewer, e1, e2); } else if (e1 instanceof TreeObject) { return 1; } else { return -1; } } }); Another solution would be to not set a sorter, if the natural order of the elements as returned by the content provider is the order you want.