I have a Lazyily loaded JTree but I am facing some problems.
I have a JTree which I load lazily using database query (each node). I have a button on the screen and when user clicks the button I perform some insert/update/delete in database and then add the model back in Jtree with only root and its immediate children using an SQL (this collapses the tree and selection and all expanded nodes collapse which is expected since it is a lazily loaded tree)
What I want to accomplish is before user clicks button to insert/update/delete, I read all the expanded state and save it in memory then when I re-initialize the Jtree I loop through those expanded children and call jtree.expandPath but it does not expand the nodes .
I even added a TreeWillExpandListener and in treeWillExpand event I added code to get the children of the node from database and I see that query does get executed to get the childreen but JTree still shows up as collapsed.
I really need your help. Please advise. Here is the code snippet.
Joined: Jun 06, 2011
I found the solution.
Need an equals method and hashCode in my NodeData class, problem was internally after setting the new Model when I was trying to expand the path the equals returned false as default implementation of equals does a "shallow compare" i.e. only compares references, I had to override the hashCode and equals method and did a "Deep compare" in equals method.