Ejemplo n.º 1
0
 private String details(final ModuleInfo info) {
   if (info == null) return "<null>";
   String className, classLocation;
   try {
     final Class<?> c = info.loadDelegateClass();
     className = c.getName();
     classLocation = ClassUtils.getLocation(c).toString();
   } catch (final ClassNotFoundException exc) {
     className = info.getDelegateClassName();
     classLocation = "<invalid>";
   }
   return info.getMenuPath() + " : " + className + " [" + classLocation + "]";
 }
Ejemplo n.º 2
0
  private ShadowMenu addChild(final ModuleInfo info, final int depth) {
    final MenuPath menuPath = info.getMenuPath();
    final MenuEntry entry = menuPath.get(depth);
    final boolean leaf = isLeaf(depth, menuPath);

    // retrieve existing child
    final ShadowMenu existingChild = children.get(entry.getName());

    final ShadowMenu child;
    if (existingChild == null) {
      // create new child and add to table
      final String menuName = entry.getName();
      final ShadowMenu newChild = new ShadowMenu(getContext(), info, depth, this);
      children.put(menuName, newChild);
      child = newChild;
    } else {
      // fill in any missing menu properties of existing child
      final MenuEntry childMenuEntry = existingChild.getMenuEntry();
      childMenuEntry.assignProperties(entry);
      child = existingChild;
    }

    // recursively add remaining child menus
    if (!leaf) child.addChild(info, depth + 1);
    else if (existingChild != null) {
      if (log != null) {
        final ModuleInfo childInfo = existingChild.getModuleInfo();
        if (childInfo != null && info.getPriority() == childInfo.getPriority()) {
          log.warn(
              "ShadowMenu: menu item already exists:\n"
                  + //
                  "\texisting: "
                  + details(childInfo)
                  + "\n"
                  + //
                  "\t ignored: "
                  + details(info));
        } else {
          log.debug(
              "ShadowMenu: higher-priority menu item already exists:\n"
                  + "\texisting: "
                  + details(childInfo)
                  + "\n"
                  + //
                  "\t ignored: "
                  + details(info));
        }
      }
    }
    return child;
  }
Ejemplo n.º 3
0
 private ShadowMenu(
     final Context context,
     final ModuleInfo moduleInfo,
     final int menuDepth,
     final ShadowMenu parent) {
   setContext(context);
   if (moduleInfo == null) {
     this.moduleInfo = null;
     menuEntry = null;
   } else {
     final MenuPath menuPath = moduleInfo.getMenuPath();
     // preserve moduleInfo reference only for leaf items
     final boolean leaf = menuDepth == menuPath.size() - 1;
     this.moduleInfo = leaf ? moduleInfo : null;
     menuEntry = menuPath.get(menuDepth);
   }
   this.menuDepth = menuDepth;
   this.parent = parent;
   children = new HashMap<>();
 }
Ejemplo n.º 4
0
 private ShadowMenu addInternal(final ModuleInfo o) {
   if (o.getMenuPath().isEmpty()) return null; // no menu
   return addChild(o, 0);
 }