views:

386

answers:

2

I'm trying to save jface TreeViewer expansion state to refresh it after calling setInput() method. I tried getExpandedElements, setExpandedElements, getExpandedTreePaths, setExpandedTreePaths methods of TreeViewer bu it doesn't work.

Object[] expandedElements = viewer.getExpandedElements();
TreePath[] expandedTreePaths = viewer.getExpandedTreePaths();
viewer.setInput();
viewer.setExpandedElements(expandedElements);
viewer.setExpandedTreePaths(expandedTreePaths);
+1  A: 
VonC
+2  A: 

You need to make sure that your TreeViewer's content provider provides objects that have their hashset and equals methods properly defined. AbstractTreeViewer needs to be able to compare the old and new objects to determine their expansion state. If hashset and equals aren't provided, it's a simple reference check, which won't work if you've recreated your contents.

daveyc
Thanks, it works after implementing the equals and hashset methods..
penguru