View Javadoc

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