public static void pruneMenus ( BaseComponent parent ) { while ( parent != null && parent instanceof BaseMenuComponent ) { if ( parent . getChildren ( ) . isEmpty ( ) ) { BaseComponent newParent = parent . getParent ( ) ; parent . destroy ( ) ; parent = newParent ; } else { break ; } } }
Recursively remove empty menu container elements . This is done after removing menu items to keep the menu structure lean .