Java: Swing: JTree and TreeModel: Expansion: Fix
JTree is just private enough that there is no way without duplication.
Except for the silent root expansion, all expansions (but not universe removals) generate events. The most simple way to track the changes seems to adjust the internal set in firePathExpanded/Collapsed (otherwise setExpandedState has to be rewritten somehow). Furthermore on TreeModelEvents signifying removals, the (supposedly) removed nodes have to be removed from this set. This has to be done by a custom TreeModelListener (removeDescendantToggledPaths isn't given enough information, if one can rely on it being called at all).
expanded (=> JTree-open, open): no state to be stored, nothing to be done
!expanded, !JTree-open, !open: state stored, nothing to be done
!expanded, JTree-open, open: state stored, nothing to be done
!expanded, !JTree-open, open: only if !parent expanded; must call expandPath when parent is opened
!expanded, JTree-open, !open: only if !parent expanded; must call collapsePath when parent is opened
open: if expanded, do nothing else if parent expanded, expand. otherwise mark open
close: if expanded, collapse else if parent expanded, do nothing. otherwise mark !open
First step is to create some convenience for listening to TreeModelEvents before/after JTree does (and fix some minor bugs in the JTree TreeModelListener code).
This is done in FTree2.java and needs AbstractTreeModelListener.java. It has nothing directly to do with expansion.
(C) 2001-2009 Christian Kaufhold (swing@chka.de)