AttributesSubMenu.java
01 package net.sourceforge.pmd.util.viewer.gui.menu;
02 
03 import java.text.MessageFormat;
04 
05 import javax.swing.JMenu;
06 
07 import net.sourceforge.pmd.lang.ast.Node;
08 import net.sourceforge.pmd.lang.ast.xpath.Attribute;
09 import net.sourceforge.pmd.lang.ast.xpath.AttributeAxisIterator;
10 import net.sourceforge.pmd.util.viewer.model.AttributeToolkit;
11 import net.sourceforge.pmd.util.viewer.model.ViewerModel;
12 import net.sourceforge.pmd.util.viewer.util.NLS;
13 
14 
15 /**
16  * contains menu items for the predicate creation
17  *
18  @author Boris Gruschko ( boris at gruschko.org )
19  @version $Id: AttributesSubMenu.java 6102 2008-05-06 21:42:36Z rgustav $
20  */
21 public class AttributesSubMenu
22         extends JMenu {
23     private ViewerModel model;
24     private Node node;
25 
26     public AttributesSubMenu(ViewerModel model, Node node) {
27         super(MessageFormat.format(NLS.nls("AST.MENU.ATTRIBUTES"), node.toString()));
28         this.model = model;
29         this.node = node;
30         init();
31     }
32 
33     private void init() {
34         AttributeAxisIterator i = new AttributeAxisIterator(node);
35         while (i.hasNext()) {
36             Attribute attribute = i.next();
37             add(new XPathFragmentAddingItem(attribute.getName() " = " + attribute.getValue(), model,
38                     AttributeToolkit.constructPredicate(attribute)));
39         }
40     }
41 }