code: public static BaseMenuComponent addMenuOrMenuItem(String path, BaseMenuComponent ele, BaseComponent parent,
                                                        BaseComponent insertBefore) {
          String pcs[] = path == null ? NULL_PATH : path.split("\\\\");
          int last = pcs.length - 1;
  
          for (int i = 0; i < last; i++) {
              parent = findMenu(parent, pcs[i], insertBefore);
          }
  
          ele = ele == null ? createMenuOrMenuitem(parent) : ele;
          ele.setLabel(pcs[last]);
          parent.addChild(ele, insertBefore);
          return ele;
      }
docs: Adds an element (menu or menu item) to the main menu.
  
  @param path Determines the position of the element in the menu tree.
  @param ele The element to be added. If null, a new element of the specified type is created.
  @param parent The parent to receive the new element.
  @param insertBefore The sibling before which the new element is to be inserted. If null, or
  the specified component is not at the same level as the element to be added, the
  new element will be added after any existing siblings.
  @return The element that was added.