| 
| Saving and restoring a TreeViewer's expanded state [message #333581] | Wed, 17 December 2008 16:23 |  | 
| Eclipse User  |  |  |  |  | Hello, I have the following problem: 
 I have a view with a TreeViewer that shows some info for an object which
 in the  business model is called a "session". When the user switches
 sessions, I need to redraw the tree, and if the user switches back I need
 to show the tree as it was previous to the switch.
 
 In order to solve that, I am using the getExpandedElements() and
 setExpandedElements() methods from the TreeViewer, to store the expanded
 elements in an array in my model "session" object.
 
 I reasoned that the most natural place to do this is in the inputChanged()
 method of the ContentProvider. However when I tried it it had no effect.
 Apparently the inputChanged() method is called _before_ actually changing
 the input for the viewer. As a workaround I moved this logic to the View
 itself, where I can call these methods after the inputChanged() is
 completed.
 
 Do you have any idea why this is implemented like this?
 Is there a "best practice" for doing this that I'm not aware of?
 
 I would like this responsibility to be in the content provider, because
 that would also mean it's easier to test (than if it were in the view).
 
 Thank you.
 Tomás
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.03187 seconds