Skip to main content


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 21:41 Go to next message
SBS  is currently offline SBS Friend
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 21:47 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
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 22:01 Go to previous message
SBS  is currently offline SBS Friend
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:Word wrap capability of control
Goto Forum:
  


Current Time: Wed Apr 24 16:25:47 GMT 2024

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

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

Back to the top