Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » Expanding all nodes in a tree viewer(Not as simple as I had hoped!)
icon5.gif  Expanding all nodes in a tree viewer [message #653213] Tue, 08 February 2011 16:41 Go to next message
SBS  is currently offline SBS
Messages: 57
Registered: January 2011
Member
In the createPartControl() method of a TreeViewer I am trying to create the viewer, load the content and then expand every item in the tree but it is not working.

The code looks like this:

final Tree tree = viewer.getTree();
for (final TreeItem item : tree.getItems()) {
    item.setExpanded(true);
}


The problem is that it seems only the top level items have been created properly at this point as I am getting null pointer exceptions in my label provider when I try to access the item's data for all nested items.

So what's the correct place, time or procedure to expand all nodes at a point where they have all been created and properly initialised?
Re: Expanding all nodes in a tree viewer [message #653221 is a reply to message #653213] Tue, 08 February 2011 16:47 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5294
Registered: July 2009
Senior Member
Yes. Items are created lazily. You can use TreeViewer#expandAll() or th
TreeViewer#expandToLevel().

Tom

Am 08.02.11 22:41, schrieb SBS:
> In the createPartControl() method of a TreeViewer I am trying to create
> the viewer, load the content and then expand every item in the tree but
> it is not working.
>
> The code looks like this:
>
> final Tree tree = viewer.getTree();
> for (final TreeItem item : tree.getItems()) {
> item.setExpanded(true);
> }
>
> The problem is that it seems only the top level items have been created
> properly at this point as I am getting null pointer exceptions in my
> label provider when I try to access the item's data for all nested items.
>
> So what's the correct place, time or procedure to expand all nodes at a
> point where they have all been created and properly initialised?
Re: Expanding all nodes in a tree viewer [message #653231 is a reply to message #653221] Tue, 08 February 2011 17:01 Go to previous message
SBS  is currently offline SBS
Messages: 57
Registered: January 2011
Member
Tom Schindl wrote on Tue, 08 February 2011 16:47
Yes. Items are created lazily. You can use TreeViewer#expandAll() or th
TreeViewer#expandToLevel().



Thanks Tom, that works perfectly.
Previous Topic:TreeViewer setSelection does not work properly
Next Topic:[DataBinding] ComboViewer binding Items and Text in Master/Detail
Goto Forum:
  


Current Time: Thu Aug 28 23:32:23 EDT 2014

Powered by FUDForum. Page generated in 0.01556 seconds