Exemplo n.º 1
0
  /**
   * Calls the extension to get the right menu item. This is already wrapped for errors in the
   * caller. It is right for it to create a new wrapped object each time. We do not want extensions
   * to share objects. It is here since it can access all constructors directly.
   *
   * @param attachedObject Description of the Parameter
   * @return The menuItem value
   */
  JMenuItem getMenuItem(Object attachedObject) {
    if (currentMenuGen == null) return null;

    if (attachedObject == null) {
      JMenuItem anItem = currentMenuGen.getToolsMenuItem(null);
      if (anItem != null) return anItem;

      // Try to use the old deprecated method.
      return currentMenuGen.getMenuItem();
    }

    if (attachedObject instanceof Package) {
      Package attachedPkg = (Package) attachedObject;
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg);
      return currentMenuGen.getToolsMenuItem(new BPackage(anId));
    }

    if (attachedObject instanceof ClassTarget) {
      ClassTarget aTarget = (ClassTarget) attachedObject;
      String qualifiedClassName = aTarget.getQualifiedName();
      Package attachedPkg = aTarget.getPackage();
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg, qualifiedClassName);
      return currentMenuGen.getClassMenuItem(new BClass(anId));
    }

    if (attachedObject instanceof ObjectWrapper) {
      ObjectWrapper aWrapper = (ObjectWrapper) attachedObject;
      return currentMenuGen.getObjectMenuItem(new BObject(aWrapper));
    }

    return null;
  }
Exemplo n.º 2
0
  /** Post a notification of a menu going to be display */
  void postMenuItem(Object attachedObject, JMenuItem onThisItem) {
    if (currentMenuGen == null) return;

    if (attachedObject == null) {
      // Only BPackages can be null when a menu is invoked
      currentMenuGen.notifyPostToolsMenu(null, onThisItem);
      return;
    }

    if (attachedObject instanceof Package) {
      Package attachedPkg = (Package) attachedObject;
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg);
      currentMenuGen.notifyPostToolsMenu(new BPackage(anId), onThisItem);
    }

    if (attachedObject instanceof ClassTarget) {
      ClassTarget aTarget = (ClassTarget) attachedObject;
      String qualifiedClassName = aTarget.getQualifiedName();
      Package attachedPkg = aTarget.getPackage();
      Identifier anId = new Identifier(attachedPkg.getProject(), attachedPkg, qualifiedClassName);
      currentMenuGen.notifyPostClassMenu(new BClass(anId), onThisItem);
    }

    if (attachedObject instanceof ObjectWrapper) {
      ObjectWrapper aWrapper = (ObjectWrapper) attachedObject;
      currentMenuGen.notifyPostObjectMenu(new BObject(aWrapper), onThisItem);
    }
  }
Exemplo n.º 3
0
  /**
   * Adds menu item into menu.
   *
   * <p>Returned menu generator will have the same settings as current one. You can modify them if
   * you need though.
   *
   * @param icon menu icon, can be either String icon name, ImageIcon, Image, image File or image
   *     URL
   * @param text menu text
   * @param enabled whether menu is enabled or not
   * @param actionListener menu action listener
   * @return menu generator for newly created menu
   */
  public MenuGenerator addSubMenu(
      final Object icon,
      final String text,
      final boolean enabled,
      final ActionListener actionListener) {
    final WebMenu menu = createSubMenu(icon, text, enabled, actionListener);
    getMenu().add(menu);

    // Creting sub-menu generator
    final MenuGenerator menuGenerator = new MenuGenerator(menu);
    menuGenerator.setNearClass(nearClass);
    menuGenerator.setPath(path);
    menuGenerator.setExtension(extension);
    menuGenerator.setLanguagePrefix(languagePrefix);
    return menuGenerator;
  }