private static void getLeafNodes ( TreeModel treeModel , Object node , Collection < Object > leafNodes ) { if ( node == null ) { return ; } int childCount = treeModel . getChildCount ( node ) ; if ( childCount == 0 ) { leafNodes . add ( node ) ; } else { for ( int i = 0 ; i < childCount ; i ++ ) { Object child = treeModel . getChild ( node , i ) ; getLeafNodes ( treeModel , child , leafNodes ) ; } } }
Recursively collect all leaf nodes in the given tree model that are descendants of the given node .