JTree: reload vs nodeChanged
I want an algorithm that goes through a Tree and updates all Nodes (remove nodes that are here no longer and fill in newcomers)
I have written an algorithm that goes through the tree and hits every Node. But i have the problem what to do then.
if I call nodeChanged ghosts of previously existent treepathes where one part has been deleted stay.
Propably it would help if i remove all parent/child relationships within the whole deleted branch (i haven't tried yet) but i would prefere not to do that since i want to keep the treenode implementations as close as possible to the databse they represent and there i don't want to hack the branch into pieces but keep it intact and it will be added to a "lost nodes storage" as whole.
if i call reload(node) all extended treepathes get closed and i don't want that.
i am using the DefaultTreeModel btw.
[902 byte] By [
arcosh] at [2007-9-26 4:29:20]

If you use the DefaultTreModel to add and remove nodes (insertNodeInto() and removeNodeFromParent()), then you will not have to reload the tree, it will be done "automatically". This is the preferred method.
However, this is not always possible, like when you are completely redoing the tree at one time. In that case, you can override reload (or create a separate method) that maintains a list of the expanded paths in the tree, reloads, and then restores the expanded state. There is a visible flicker, but it works.
tjwojo at 2007-6-29 17:40:36 >

Keep in mind that your not navigating the tree but the model that underlies the tree. The tree is just a view of the data contained in the model (reference MVC).
As long as your operations on the model are done through the model's methods, the tree view should stay in synch. If your model it is updating itself, be sure to fire the proper events so that the view (and any other model listeners) get notified of the changes.
gweedo at 2007-6-29 17:40:36 >

Basically i use twojo's second method now.
Go through all nodes chack their visibility and store the visible pathes.
On the way back i reload the nodes and afterwaards i make all stored pathes visible again.
This requires a lot of things done by foot like making a node to path function but it works. don't even see a flicker but maybe this is because my testree is very small.
thanks for all replies.
arcosh at 2007-6-29 17:40:36 >
