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.lang.ast.xpath.Attribute;
12  import net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator;
13  import net.sourceforge.pmd.util.viewer.model.AttributeToolkit;
14  import net.sourceforge.pmd.util.viewer.model.ViewerModel;
15  import net.sourceforge.pmd.util.viewer.util.NLS;
16  
17  
18  /**
19   * contains menu items for the predicate creation
20   *
21   * @author Boris Gruschko ( boris at gruschko.org )
22   * @version $Id$
23   */
24  public class AttributesSubMenu
25          extends JMenu {
26      private ViewerModel model;
27      private Node node;
28  
29      public AttributesSubMenu(ViewerModel model, Node node) {
30          super(MessageFormat.format(NLS.nls("AST.MENU.ATTRIBUTES"), node.toString()));
31          this.model = model;
32          this.node = node;
33          init();
34      }
35  
36      private void init() {
37          AttributeAxisIterator i = new AttributeAxisIterator(node);
38          while (i.hasNext()) {
39              Attribute attribute = i.next();
40              add(new XPathFragmentAddingItem(attribute.getName() + " = " + attribute.getValue(), model,
41                      AttributeToolkit.constructPredicate(attribute)));
42          }
43      }
44  }