Java – save treeviewer state before setinput()

I tried to save the Jface treeviewer extension state to refresh it after calling the setinput () method I tried the setexpandedtreepaths method of getexpandedelements, setexpandedelements, getexpandedtreepaths, treeviewer, but it didn't work

Object[] expandedElements = viewer.getExpandedElements();
TreePath[] expandedTreePaths = viewer.getExpandedTreePaths();
viewer.setinput();
viewer.setExpandedElements(expandedElements);
viewer.setExpandedTreePaths(expandedTreePaths);

Solution

You need to ensure that your treeviewer's content provider provides objects that correctly define its hashcode and equals methods Abstracttreeviewer needs to be able to compare old and new objects to determine their extended state If hashcode and equals are not provided, it is a simple reference check, which will not work if you have recreated the content

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>