Bug 59140 - [Viewers] Requesting a new method to get all visible elements in the JFace Tree Viewer infrastructure
Summary: [Viewers] Requesting a new method to get all visible elements in the JFace Tr...
Status: RESOLVED DUPLICATE of bug 2713
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 59141 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-19 16:00 EDT by Saurabh Bagrodia CLA
Modified: 2005-11-09 16:46 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Saurabh Bagrodia CLA 2004-04-19 16:00:57 EDT
Currently in the Eclipse JFace Tree Viewer infrastructure we have a method 
called getVisibleExpandedElements that returns all the visible "and" expanded 
object in the view. What I wanted was a method that returned all the visible 
objects (whether expanded or not)

I am not sure if the intention of the getVisibleExpandedElements method was 
getting all visible elements or not but I think this is a much more important 
behaviour from the UI point-of-view.. For example in my case I have 2 label 
providers for my tree view and I need to switch between them from time to time 
and to do the switch in a more optimized manner I need to get the visible 
objects and call update on them instead of calling refresh on the entire view 
which is very expensive execution wise.

I had implemented the method and am pasting it below: 

	public Object[] getVisibleElements(){	
		ArrayList visibleElements = new ArrayList();
		recursiveGetVisibleElements(visibleElements,getTree());
		return visibleElements.toArray();
	}


	/**
	 * @param tree
	 * @return
	 */
	private void recursiveGetVisibleElements(ArrayList visibleElements, 
Widget item) {	
		
		if (!(item instanceof Item) || getExpanded((Item)item)) {
			
			Item[] children = getChildren(item);
			
			for (int i = 0; i < children.length; i++) {
				
				Item child = children[i];
				
				Object data = child.getData();
				if (data != null)
					visibleElements.add(data);	
			
				
				recursiveGetVisibleElements(visibleElements, 
child);
			}
		}		
		
	}


Its very similar to the getVisibleExpandedElements method, the difference 
being here I am checking if the passed object is expanded and if its I add its 
children to the resulting list and then recurse on the children whereas in the 
getVisibleExpandedElements method first the children of the passed element are 
obtained and then the children are checked to see whether they are expended 
and if they are then they are added to the resulting list and the method is 
recursed on them.

Thanks!
Comment 1 Debbie Wilson CLA 2004-04-20 11:25:36 EDT
*** Bug 59141 has been marked as a duplicate of this bug. ***
Comment 2 Tod Creasey CLA 2004-04-20 11:31:30 EDT
Not for 3.0
Comment 3 Tod Creasey CLA 2004-06-28 11:28:22 EDT
Reopening now that 3.0 has shipped
Comment 4 Boris Bokowski CLA 2005-11-09 16:46:14 EST

*** This bug has been marked as a duplicate of 2713 ***