JavaSwingJTree and TreeModelExpansion: Problems


Problems

Terminology

(where different from JTree, intentionally)

descendant/ancestor include the node itself. proper descendant/ancestor do not.

shown: the node is shown <=> it has a row <=> getRowForPath != -1

open: if it were shown, it would be "expanded", i.e if it had children, they would be shown as well etc. This is (here) a property of a node (and then of the path identifying the node) alone, and independent from "shown". Only non-leaf (TreeModel leaf definition) nodes can be opened.

Then shown := for all proper ancestors a: a is open

Path expansion methods

makeVisible ensures shown

isVisible := visible := shown

isExpanded := expanded := shown && opened <=> all ancestors are open

isCollapsed := collapsed := !shown || !opened <=> there is an ancestor that is not open

expandPath requires !leaf ensures shown && open <=> isExpanded

collapsePath requires !leaf ensures shown && !open <=> shown && isCollapsed

Observations:

"collapse/collapsed" is strangely defined. Why does collapsePath show the node if according to collapsed this is not necessary at all (calling collapsePath on a path that isCollapsed but not shown will have side effects)? Shouldn't either (for consistency with collapsePath) isCollapsed only be true for shown nodes or (for consistency with isCollapsed) collapsePath not open all ancestors?

There can be open paths that are not expanded (if at least one proper ancestor is not open), but there is no method to find out whether they are or to change this: expanded will be false if any of the ancestors is not open expand-/collapsePath also show the node.

getExpandedDescendants := all expanded (not: open!) nodes that are descendants.

Row expansion methods

For the rows there is no such problem: for the row to exist, its node/path must be shown.

isExpanded(row)

isCollapsed(row)

expandRow requires !isLeaf ensures isExpanded(row)

collapseRow requires !isLeaf ensures isCollapsed(row)

Further

hasBeenExpanded

getDescendantToggledPaths (pr)

clearToggledPaths (pr)

removeDescendantToggledPaths (pr)

Reaction to TreeModelEvents

treeNodesRemoved: all descendants of the removed nodes are silently removed, also the parent if it has become a leaf.

treeStructureChanged: all proper descendants of the change-root are silently removed. If the event was for the root (i.e. both new-root and just structureChanged!), it is silently expanded. The latter is incorrect (TreeModelEvent/-Listener distinguish explicitly between these types of events)

setModel: root also is silently expanded.

TreeExpansionEvents

As TreeExpansionEvents currently are only sent for shown nodes,...


(C) 2001-2009 Christian Kaufhold (swing@chka.de)