View Javadoc

    1   package net.sourceforge.pmd.util.viewer.gui.menu;
    2
    3   import java.text.MessageFormat;
    4
    5   import javax.swing.JMenu;
    6
    7   import net.sourceforge.pmd.lang.ast.Node;
    8   import net.sourceforge.pmd.util.viewer.model.ViewerModel;
    9   import net.sourceforge.pmd.util.viewer.util.NLS;
    10
    11
    12  /**
    13   * submenu for the simple node itself
    14   *
    15   * @author Boris Gruschko ( boris at gruschko.org )
    16   * @version $Id$
    17   */
    18  public class SimpleNodeSubMenu
    19          extends JMenu {
    20      private ViewerModel model;
    21      private Node node;
    22
    23      /**
    24       * constructs the submenu
    25       *
    26       * @param model model to which the actions will be forwarded
    27       * @param node  menu's owner
    28       */
    29      public SimpleNodeSubMenu(ViewerModel model, Node node) {
    30          super(MessageFormat.format(NLS.nls("AST.MENU.NODE.TITLE"), node.toString()));
    31          this.model = model;
    32          this.node = node;
    33          init();
    34      }
    35
    36      private void init() {
    37          StringBuffer buf = new StringBuffer(200);
    38          for (Node temp = node; temp != null; temp = temp.jjtGetParent()) {
    39              buf.insert(0, "/" + temp.toString());
    40          }
    41          add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ABSOLUTE_PATH"), model, buf.toString()));
    42          add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ALLDESCENDANTS"), model,
    43                  "//" + node.toString()));
    44      }
    45  }
    46
    47