How to filter a TreeViewer to not display the parent, but show the children [message #268492] |
Wed, 11 February 2009 14:21  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.12316 seconds