Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 258736

Summary: [Viewers] [JFace] setUseHashLookUp() and multiple occurrences of same domain object in TreeViewer
Product: [Eclipse Project] Platform Reporter: Mário Guimarães <mljrg>
Component: UIAssignee: Boris Bokowski <bokowski>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: ob1.eclipse
Version: 3.4.1Keywords: helpwanted
Target Milestone: 3.5 M5   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Mário Guimarães CLA 2008-12-13 12:35:08 EST
Build ID: I20080617-2000

Steps To Reproduce:
If a domain object appears twice or more in a TreeViewer, client code must call viewer.setUseHashLookUp(true) so that viewer.update(domain_object, null) refreshes all occurrences, instead of only the first found.

This behavior is not documented in the javadoc for either setUseHashLookUp() or update() !

More information:
Using setUseHashLookUp(true) seems to be a side effect since this method's javadoc only refers its use for speed optimization. Otherwise, the javadoc should be updated to reflect this important feature.

As such, I think there should be update() and refresh() methods accepting elements or treepaths, in the same way there is add(Object parentElementOrTreePath, ...) and remove(Object[] elementsOrTreePaths).

Also, having an update(Object[] elementsOrTreePaths) would improve the speed of finding the right internal widget when TreePaths are given.

Having these new methods (or revising the current ones) would also make the API more consistent than it is now.

(this issue was recently discussed in news://news.eclipse.org:119/ghokuc$hal$1@build.eclipse.org)
Comment 1 Boris Bokowski CLA 2008-12-16 22:35:30 EST
Do you have a suggestion how the Javadoc should be changed?
Comment 2 Mário Guimarães CLA 2008-12-17 05:32:18 EST
I suggest the following javadoc:

---------------
Configures whether this structured viewer uses an internal hash table to speed up the mapping between elements and SWT items. This must be called before the viewer is given an input (via setInput). 

Note: when using an ITreePathContentProvider with a TreeViewer, the internal hash table should be enabled to support the update and refresh of multiple occurrences of the same domain objects in the viewer.
---------------

Regard that I'm not aware of other uses of an internal hash table. However, if they exist, they should be documented too.
Comment 3 Boris Bokowski CLA 2009-01-21 15:12:24 EST
I decided to instead copy the following paragraph from AbstractTreeViewer into the JavaDoc for TreeViewer as well:

 * <p>
 * As of 3.2, TreeViewer supports multiple equal elements (each with a
 * different parent chain) in the tree. This support requires that clients
 * enable the element map by calling <code>setUseHashLookup(true)</code>.
 * </p>


Would you have found this if it had been on TreeViewer (and not just the superclass)?
Comment 4 Mário Guimarães CLA 2009-01-22 04:36:13 EST
Maybe, but to be sure, this feature should also be documented in the javadoc for setUseHashLookup() and ITreePathContentProvider.
Comment 5 Oleg Besedin CLA 2009-01-30 09:51:54 EST
Verified that text from the comment 3 appears in the build  I20090129-0100 (both help and source Javadoc).