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