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.lang.ast.xpath.Attribute;
    9   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$
    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  }