code: private void mapTreeHierarchy(final WComponent currentComponent,
  			final StringTreeNode currentNode, final WText selectedMenuText) {
  		if (currentNode.isLeaf()) {
  			WMenuItem menuItem = new WMenuItem(currentNode.getData(), new ExampleMenuAction(
  					selectedMenuText));
  			menuItem.setActionObject(currentNode.getData());
  			if (currentComponent instanceof WMenu) {
  				((WMenu) currentComponent).add(menuItem);
  			} else {
  				((WSubMenu) currentComponent).add(menuItem);
  			}
  		} else {
  			WSubMenu subMenu = new WSubMenu(currentNode.getData());
  			subMenu.setSelectMode(SelectMode.SINGLE);
  
  			if (currentComponent instanceof WMenu) {
  				((WMenu) currentComponent).add(subMenu);
  			} else {
  				((WSubMenu) currentComponent).add(subMenu);
  			}
  
  			// Expand the first couple of levels in the tree by default.
  			if (currentNode.getLevel() < 2) {
  				subMenu.setOpen(true);
  			}
  
  			for (Iterator<TreeNode> i = currentNode.children(); i.hasNext();) {
  				mapTreeHierarchy(subMenu, (StringTreeNode) i.next(), selectedMenuText);
  			}
  		}
  	}
docs: Recursively maps a tree hierarchy to a hierarchical menu.
  
  @param currentComponent the current component in the menu.
  @param currentNode the current node in the tree.
  @param selectedMenuText the WText to display the selected menu item.