01: package org.apache.jmeter.module.actions;
02:
03: import javax.swing.JMenu;
04: import javax.swing.JMenuItem;
05: import javax.swing.JPopupMenu;
06: import javax.swing.MenuElement;
07: import org.apache.jmeter.module.cookies.JMeterCookie;
08: import org.apache.jmeter.module.integration.JMeterIntegrationEngine;
09: import org.openide.nodes.Node;
10: import org.openide.util.HelpCtx;
11: import org.openide.util.NbBundle;
12: import org.openide.util.Utilities;
13: import org.openide.util.actions.CookieAction;
14: import org.openide.util.actions.Presenter;
15:
16: public final class JMeterSpecificAction extends CookieAction implements
17: Presenter.Popup {
18:
19: protected void performAction(Node[] activatedNodes) {
20: // JMeterCookie c = (JMeterCookie) activatedNodes[0].getCookie(JMeterCookie.class);
21: // // TODO use c
22: }
23:
24: protected int mode() {
25: return CookieAction.MODE_EXACTLY_ONE;
26: }
27:
28: public String getName() {
29: return NbBundle.getMessage(JMeterSpecificAction.class,
30: "CTL_JMeterSpecificAction");
31: }
32:
33: protected Class[] cookieClasses() {
34: return new Class[] { JMeterCookie.class };
35: }
36:
37: protected void initialize() {
38: super .initialize();
39: // see org.openide.util.actions.SystemAction.iconResource() javadoc for more details
40: putValue("noIconInMenu", Boolean.TRUE);
41: }
42:
43: public HelpCtx getHelpCtx() {
44: return HelpCtx.DEFAULT_HELP;
45: }
46:
47: protected boolean asynchronous() {
48: return false;
49: }
50:
51: public JMenuItem getPopupPresenter() {
52: JMenu retValue = new JMenu(getName());
53:
54: Node[] nodes = getActivatedNodes();
55: try {
56: if (nodes.length > 0) {
57: JMeterCookie cookie = (JMeterCookie) nodes[0]
58: .getCookie(JMeterCookie.class);
59: JPopupMenu menu = JMeterIntegrationEngine.getDefault()
60: .getElementMenu(cookie.getElement());
61:
62: boolean submenuAdded = false;
63: for (MenuElement submenu : menu.getSubElements()) {
64: if (submenu instanceof JMenu) {
65: retValue.add(submenu.getComponent());
66: submenuAdded = true;
67: }
68: }
69:
70: if (!submenuAdded) {
71: return null;
72: }
73: }
74: } catch (Exception e) {
75: e.printStackTrace();
76: }
77: //
78: // return rootItem;
79: return retValue;
80: }
81: }
|