Skip to main content



      Home
Home » Newcomers » Newcomers » How to filter a TreeViewer to not display the parent, but show the children
How to filter a TreeViewer to not display the parent, but show the children [message #268492] Wed, 11 February 2009 14:21 Go to next message
Eclipse UserFriend
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
Re: How to filter a TreeViewer to not display the parent, but show the children [message #268507 is a reply to message #268492] Wed, 11 February 2009 22:53 Go to previous messageGo to next message
Eclipse UserFriend
Hello Kyle,

If you filter the parent obviously you will lose the children as the child
nodes are part of the parent node.

From my knowledge, what you can do is to re-create the tree with Tree1 and
Tree2 as parent nodes.

Regards,
Madhu
Re: How to filter a TreeViewer to not display the parent, but show the children [message #268514 is a reply to message #268492] Thu, 12 February 2009 10:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 2/11/2009 2:21 PM, 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)

I don't think ViewFilter can do what you want. Do you already have a
custom content provider for the TreeViewer? I'd think that is the place
to do this kind of thing.

Eric
Re: How to filter a TreeViewer to not display the parent, but show the children [message #268519 is a reply to message #268492] Thu, 12 February 2009 11:51 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: How to filter a TreeViewer to not display the parent, but show the children [message #268522 is a reply to message #268519] Thu, 12 February 2009 13:33 Go to previous message
Eclipse UserFriend
Thanks,

I am using an EMF.edit project generated from my schema, where it is
using an AdapterFactoryContent provider instead of a single
ITreeContentProvider.

It was doing:

navigator.setContentProvider(new
AdapterFactoryContentProvider(adapterFactory));
navigator.setLabelProvider(new
AdapterFactoryLabelProvider(adapterFactory));
getSite().setSelectionProvider(navigator);
....
navigator.setInput(resource);


I was able to get my viewer to skip the DocumentRoot and MyExlporer
levels by inserting the following before the setInput

Object object = resource.getContents().get(0);
navigator.setInput(object);

-Kyle


On Thu, 12 Feb 2009 22:21:42 +0530, Rajkumar
<rajkumar_kandasamy@omniscient.co.in> wrote:

>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
Previous Topic:Java build path plug-in dependencies
Next Topic:Side scrolling with the mouse wheel is annoying.
Goto Forum:
  


Current Time: Fri Jul 18 15:38:11 EDT 2025

Powered by FUDForum. Page generated in 0.12316 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top