Monday, February 22, 2010

JFace TreeViewer collapses after refresh/setInput

A problem: TreeViewer collapses all nodes of the tree after calling refresh() or setInput().

Solution: Implement equals() and hashCode() functions for the Objects provided by your TreeContentProvider. JFace needs to copy the state of the 'old' input of the tree to new input. In order to do this it needs to find the objects from 'old' input in 'new' input. So, it needs equals and hashCode functions. If you don't implement them, the default Object equals and hashCode are used.

No comments:

Post a Comment