code: public void removeEmptySubtrees(CmsTreeNode<I_CmsContextMenuItem> root) {
  
          List<CmsTreeNode<I_CmsContextMenuItem>> children = root.getChildren();
          if ((root.getData() != null) && root.getData().isLeafItem()) {
              children.clear();
          } else {
              Iterator<CmsTreeNode<I_CmsContextMenuItem>> iter = children.iterator();
              while (iter.hasNext()) {
                  CmsTreeNode<I_CmsContextMenuItem> node = iter.next();
                  removeEmptySubtrees(node);
                  if ((node.getData() != null) && !node.getData().isLeafItem() && (node.getChildren().size() == 0)) {
                      iter.remove();
                  }
              }
          }
      }
docs: Recursively remove subtrees (destructively!) which do not contain any 'leaf' context menu items.<p>
  
  @param root the root of the tree to process