View Javadoc

1   package net.sourceforge.pmd.util.viewer.gui.menu;
2   
3   import java.awt.event.ActionEvent;
4   import java.awt.event.ActionListener;
5   
6   import javax.swing.JMenuItem;
7   
8   import net.sourceforge.pmd.util.viewer.model.ViewerModel;
9   
10  
11  /**
12   * adds the given path fragment to the XPath expression upon action
13   *
14   * @author Boris Gruschko ( boris at gruschko.org )
15   * @version $Id$
16   */
17  public class XPathFragmentAddingItem extends JMenuItem implements ActionListener {
18      private ViewerModel model;
19      private String fragment;
20  
21      /**
22       * constructs the item
23       *
24       * @param caption  menu item's caption
25       * @param model    model to refer to
26       * @param fragment XPath expression fragment to be added upon action
27       */
28      public XPathFragmentAddingItem(String caption, ViewerModel model, String fragment) {
29          super(caption);
30          this.model = model;
31          this.fragment = fragment;
32          addActionListener(this);
33      }
34  
35      /**
36       * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
37       */
38      public void actionPerformed(ActionEvent e) {
39          model.appendToXPathExpression(fragment, this);
40      }
41  }