Bug 2713

Summary: [Viewers] Feature request: API to traverse tree viewer (1GIIFW8)
Product: [Eclipse Project] Platform Reporter: Darin Wright <darin.eclipse>
Component: UIAssignee: Platform UI Triaged <platform-ui-triaged>
Status: ASSIGNED --- QA Contact:
Severity: enhancement    
Priority: P5 CC: bagrodia, chris.mh3, habeck
Version: 2.0Keywords: api, helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Darin Wright CLA 2001-10-10 22:42:01 EDT
DW (8/15/01 12:24:09 PM)
	We would like API to traverse the visible elements in a tree viewer, given
	a starting object. Use of the visitor would work well. The traversal should
	traverse the starting object and its visible subtree.

	This will help implement features such as "copy to clipboard".
Comment 1 Kevin Haaland CLA 2002-02-01 11:00:29 EST
Defer
Comment 2 Randy Giffen CLA 2002-08-08 15:16:10 EDT
Reopen for investigation
Comment 3 Boris Bokowski CLA 2005-11-07 15:56:44 EST
Is this still an issue? Is getExpandedState(Object element) not sufficient?

I'm trying to clean up old bugs...
Comment 4 Darin Wright CLA 2005-11-08 10:32:20 EST
I don't think this solves the entire problem, as we'd like to traverse the 
visible, items - not just exapanded. For example, if a parent is expanded, the 
children are visible, but the children are *not* expanded.
Comment 5 Boris Bokowski CLA 2005-11-08 16:20:52 EST
Are you asking that something like the code below should be added to
AbstractTreeViewer?  Since the code does not need access to internals, you could
implement it yourself. Why should it be API?

public static void collectVisibleElements(TreeViewer tv, ITreeContentProvider
cp, Object[] elements, List result) {
  for(int i=0; i<elements.length; i++) {
    Object element = elements[i];
    result.add(element);
    if(tv.getExpandedState(element)) {
      collectVisibleElements(tv, cp, cp.getChildren(element), result);
    }
  }
}
Comment 6 Darin Wright CLA 2005-11-09 09:55:53 EST
Yes, we can do that in our viewer. Thought it might be generally useful.
Comment 7 Boris Bokowski CLA 2005-11-09 16:45:23 EST
*** Bug 102104 has been marked as a duplicate of this bug. ***
Comment 8 Boris Bokowski CLA 2005-11-09 16:46:14 EST
*** Bug 59140 has been marked as a duplicate of this bug. ***
Comment 9 Boris Bokowski CLA 2005-11-09 16:49:07 EST
Upping priority. In fact, this seems to be generally useful, and easy enough to do.
Comment 10 Christian Mathis CLA 2005-12-18 11:14:16 EST
(In reply to comment #5)

> public static void collectVisibleElements(TreeViewer tv, ITreeContentProvider
> cp, Object[] elements, List result) {
>   for(int i=0; i<elements.length; i++) {
>     Object element = elements[i];
>     result.add(element);
>     if(tv.getExpandedState(element)) {
>       collectVisibleElements(tv, cp, cp.getChildren(element), result);
>     }
>   }
> }

A little bit more than this would be great. This code returns all children of the visible and expanded elements, even the children that are not visible.

I seems like there is no way to get only the visible children of a tree without touching internals.
Comment 11 Boris Bokowski CLA 2007-04-27 08:52:58 EDT
deferring
Comment 12 Boris Bokowski CLA 2009-11-26 09:52:39 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 13 Eclipse Webmaster CLA 2019-09-06 16:08:01 EDT
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.