/**
   * method that fill the shortcut set with an object ( this object should be instance of
   * ActionableShortcutedMenuItem but it does nothing if it is an normal Object ). the shortcut of
   * the element if it exists is set to "" if an existing element already uses it. if the object is
   * a menu, then
   *
   * @param objet an Object
   * @param recur true if the method should call itself when the object is a container of menuItem
   */
  protected void assignShortcuts(Object object, boolean recur) {
    if (logger.isDebugEnabled()) {
      logger.debug("entering assignShortCuts(Object, boolean)");
    }
    if (object != null) {
      if (recur) {
        List list = null;
        if (object instanceof Menubar) {
          Menubar bar = (Menubar) object;
          if (bar.getMenus() != null) {
            list = bar.getMenus().getMenu();
          }
        } else if (object instanceof MenuType) {
          list = ((MenuType) object).getMenuOrItemOrCheck();
        } else if (object instanceof TypeMenu) {
          TypeMenu menuType = (TypeMenu) object;
          if (menuType.getItems() != null) {
            list = menuType.getItems().getMenuOrItemOrCheck();
          }
        }

        if (list != null) {
          Iterator it = list.iterator();
          while (it.hasNext()) {
            this.assignShortcuts(it.next(), recur);
          }
        }
      }
      /* it an ActionableShortcutedMenuItem ? */
      if (object instanceof ActionableShortcutedElement) {
          /* try to add the shortcut and if already presents, remove it */
        String shortcut = ((ActionableShortcutedElement) object).getShortcut();
        if (shortcut != null) {
          shortcut = shortcut.trim();
          if (shortcut.length() > 0) {
            if (!this.shortcuts.add(shortcut)) {
              ((ActionableShortcutedElement) object).setShortcut("");
              logger.warn(
                  "the item '"
                      + ((ActionableShortcutedElement) object).getLabel()
                      + "' could not get shortcut '"
                      + shortcut
                      + "' because it's already assignated");
            }
          }
        }
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug("exiting assignShortCuts(Object, boolean)");
    }
  }
  /**
   * return the item named name instance of the given class
   *
   * @param parent where to search for the item ( not recursively ) a Menubar or a Menu
   * @param label the label of an element
   * @param i18nRef the internationalization reference of an element
   * @param allowed class
   * @return a corresponding item or null if nothing was found
   */
  protected Object getItem(Object parent, String label, String i18nRef, Class allowed) {
    Object o = null;
    if (parent != null
        && (parent instanceof Menubar
            || parent instanceof MenuType
            || parent instanceof TypeMenu)) {
      List l = null;
      if (parent instanceof MenuType) {
        l = ((MenuType) parent).getMenuOrItemOrCheck();
      } else if (parent instanceof Menubar) {
        Menubar bar = (Menubar) parent;
        if (bar.getMenus() != null) {
          l = bar.getMenus().getMenu();
        }
      } else if (parent instanceof TypeMenu) {
        TypeMenu typeMenu = (TypeMenu) parent;
        if (typeMenu.getItems() != null) {
          l = typeMenu.getItems().getMenuOrItemOrCheck();
        }
      }

      if (l != null) {
        Iterator it = l.iterator();
        while (it.hasNext()) {
          Object current = it.next();

          if (current != null) {
            if (current instanceof AbstractElement) {
              AbstractElement elt = (AbstractElement) current;

              boolean seemsSame = this.equalsAbstractElts(elt, label, i18nRef);

              if (allowed.isAssignableFrom(current.getClass()) && seemsSame) {
                o = current;
                break;
              }
            }
          }
        }
      }
    }
    return o;
  }