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 but it doesn't work.
Object[] expandedElements = viewer.getExpandedElements();
TreePath[] expandedTreePaths = viewer.getExpandedTreePaths();
viewer.setInput();
viewer.setExpandedElements(expandedElements);
viewer.setExpandedTreePaths(expandedTreePaths);
(as seen in the
You need to make sure that your TreeViewer's content provider provides objects that have their
hashCodeandequalsmethods properly defined.AbstractTreeViewerneeds to be able to compare the old and new objects to determine their expansion state. IfhashCodeandequalsaren't provided, it's a simple reference check, which won't work if you've recreated your contents.