Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Maintaining a TreeView expansion state after setInput()
Maintaining a TreeView expansion state after setInput() [message #481348] Thu, 20 August 2009 14:57 Go to next message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Hi,

I have a working TreeViewer. My problem is that whenever I call
setInput() the tree view collapses and I have to re-expand the nodes I'm
interested in.

The new input is different but has the same structure as the old input.

I'd like to maintain or reapply the existing tree expansion after the
new input has been applied.

Any hints as to how you might do this would be very much appreciated.

Thanks, Steve.
Re: Maintaining a TreeView expansion state after setInput() [message #481474 is a reply to message #481348] Fri, 21 August 2009 07:55 Go to previous messageGo to next message
Mustufa Kasidwala is currently offline Mustufa KasidwalaFriend
Messages: 60
Registered: July 2009
Member
Get the expanded elements and expanded tree paths using
'getExpandedElements' and 'getExpandedTreePaths' functions of Tree viewer.
After setInput is complete and the tree is refreshed, use the
'setExpandedElements' and 'setExpandedTreePaths' to regain the previous
expansion state.

--
Thanks,

Mustufa
"Steve Jones" <steve@istech.demon.co.uk> wrote in message
news:h6jo88$e4k$1@build.eclipse.org...
> Hi,
>
> I have a working TreeViewer. My problem is that whenever I call setInput()
> the tree view collapses and I have to re-expand the nodes I'm interested
> in.
>
> The new input is different but has the same structure as the old input.
>
> I'd like to maintain or reapply the existing tree expansion after the new
> input has been applied.
>
> Any hints as to how you might do this would be very much appreciated.
>
> Thanks, Steve.
Re: Maintaining a TreeView expansion state after setInput() [message #481791 is a reply to message #481474] Mon, 24 August 2009 10:50 Go to previous messageGo to next message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Hi,

Thanks for the info.

By calling setExpandedElements() after my setInput() the tree view
expansion state is restored.

The only problem I have now is that the view does collapse momentarily
before returning to its old expanded state. I'm looking at how I can
delay the tree tree refresh until after the setExpandedElements() call.

Steve.


Mustufa Kasidwala wrote:
> Get the expanded elements and expanded tree paths using
> 'getExpandedElements' and 'getExpandedTreePaths' functions of Tree viewer.
> After setInput is complete and the tree is refreshed, use the
> 'setExpandedElements' and 'setExpandedTreePaths' to regain the previous
> expansion state.
>
Re: Maintaining a TreeView expansion state after setInput() [message #481818 is a reply to message #481791] Mon, 24 August 2009 12:27 Go to previous messageGo to next message
Steve Jones is currently offline Steve JonesFriend
Messages: 95
Registered: July 2009
Member
Hi,

OK, the following maintains the tree expansion after input change
without any distracting flicker.

TreeViewer viewer = getTreeViewer();

// Turn off redraw and set new input

Object[] elements = viewer.getExpandedElements();
viewer.getControl().setRedraw(false);
viewer.setInput(newRoot);

// Determine and set equivalent expanded nodes in new tree

Object[] newExpansion = expandElements(newRoot,elements);
viewer.setExpandedElements(newExpansion);

// Redraw the tree

viewer.getControl().setRedraw(true);
viewer.getControl().redraw();



Steve.


Steve Jones wrote:
> Hi,
>
> Thanks for the info.
>
> By calling setExpandedElements() after my setInput() the tree view
> expansion state is restored.
>
> The only problem I have now is that the view does collapse momentarily
> before returning to its old expanded state. I'm looking at how I can
> delay the tree tree refresh until after the setExpandedElements() call.
>
> Steve.
>
>
> Mustufa Kasidwala wrote:
>> Get the expanded elements and expanded tree paths using
>> 'getExpandedElements' and 'getExpandedTreePaths' functions of Tree
>> viewer. After setInput is complete and the tree is refreshed, use the
>> 'setExpandedElements' and 'setExpandedTreePaths' to regain the
>> previous expansion state.
>>
Re: Maintaining a TreeView expansion state after setInput() [message #524820 is a reply to message #481818] Fri, 02 April 2010 17:55 Go to previous message
Ritter is currently offline RitterFriend
Messages: 4
Registered: March 2010
Junior Member
I know this is pretty old, but hopefully I get a response without having to repost a similar topic.

I'm running the above situation (more or less), but I have a large number (~2000) paths to expand. This hangs my client for a duration - is there a performance issue I'm not aware of here?

Weirdly, if I use the "Expand all" call, and then save the paths, then restore them, it takes longer to restore than the expand call did... any thoughts here?

-Ritter
Previous Topic:wrong visible table entry
Next Topic:TreeViewer collapses when calling refresh()
Goto Forum:
  


Current Time: Sun Aug 25 12:07:24 GMT 2019

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

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

Back to the top