[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: How to filter a TreeViewer to not display the parent, but show the children

Hi,

I have no idea what ViewerFilter is doing. But you can do this very easily in content provider itself.

Am assuming your contentProvider implements ITreeContentProvider,

In getChildren() of ITreeContentProvider

public Object[] getChildren(Object parentElement) {
if (parentElement instanceof DocumentRoot) {
		DocumentRoot documentRoot = (DocumentRoot )parentElement;
	        return documentRoot.getMyExplorer.listTree().toArray();
	}
return new Object[0];
}

And in getElements() of ITreeContentProvider

public Object[] getElements(Object inputElement) {
	if (inputElement instanceof Tree) {
	Tree tree = (Tree)inputElement ;
	return tree.listItems().toArray();
	}
}

This will give the result what your are expecting...

Thanks
Raj




Kyle J Nolan wrote:
My structure has the following (where each level is a different class
type):

DocumentRoot
+- MyExplorer
 +-Tree1
  ---item1
  ---item2
 +-Tree2
  ---item3
  ---item4

I am trying to filter my TreeViewer to only display:
Tree1
  ---item1
  ---item2
Tree2
  ---item3
  ---item4

I can't seem to figure out how to do this with the ViewerFilter--if I
try to filter a parent class, I lose the children.
I would also be happy with a solution to just print the tree starting
at a certain level (if that's simpler)

Thanks