View Javadoc

1   package net.sourceforge.pmd.util.viewer.gui.menu;
2   
3   import net.sourceforge.pmd.ast.Node;
4   import net.sourceforge.pmd.ast.SimpleNode;
5   import net.sourceforge.pmd.util.viewer.model.ViewerModel;
6   import net.sourceforge.pmd.util.viewer.util.NLS;
7   
8   import javax.swing.*;
9   import java.text.MessageFormat;
10  
11  
12  /***
13   * submenu for the simple node itself
14   *
15   * @author Boris Gruschko ( boris at gruschko.org )
16   * @version $Id: SimpleNodeSubMenu.java,v 1.7 2005/08/23 17:17:49 tomcopeland Exp $
17   */
18  public class SimpleNodeSubMenu
19          extends JMenu {
20      private ViewerModel model;
21      private SimpleNode 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, SimpleNode node) {
30          super(MessageFormat.format(NLS.nls("AST.MENU.NODE.TITLE"), new Object[]{node.toString()}));
31  
32          this.model = model;
33          this.node = node;
34  
35          init();
36      }
37  
38      private void init() {
39          StringBuffer buf = new StringBuffer(200);
40  
41          for (Node temp = node; temp != null; temp = temp.jjtGetParent()) {
42              buf.insert(0, "/" + temp.toString());
43          }
44  
45          add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ABSOLUTE_PATH"), model, buf.toString()));
46  
47          add(new XPathFragmentAddingItem(NLS.nls("AST.MENU.NODE.ADD_ALLDESCENDANTS"), model,
48                  "//" + node.toString()));
49      }
50  }
51  
52