KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > query > actions > QueryAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * QueryAction.java
22  *
23  * Created on May 30, 2006, 11:24 AM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.query.actions;
30
31 import javax.swing.*;
32
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.actions.NodeAction;
36 import org.openide.util.actions.Presenter;
37 import org.openide.util.actions.SystemAction;
38
39 /**
40  * Action which just holds a few other SystemAction's for grouping purposes.
41  * @author cwebster
42  * @author Jeri Lockhart
43  */

44 public class QueryAction extends NodeAction {
45     private static final long serialVersionUID = 1L;
46
47     /**
48      * Get a human presentable name of the action.
49      * This may be
50      * presented as an item in a menu.
51      * <p>Using the normal menu presenters, an included ampersand
52      * before a letter will be treated as the name of a mnemonic.
53      *
54      * @return the name of the action
55      */

56     public String JavaDoc getName() {
57         return NbBundle.getMessage(QueryAction.class,
58                 "LBL_Query");
59     }
60
61     /** List of system actions to be displayed within this one's toolbar or submenu. */
62     private static final SystemAction[] grouped() {
63         return new SystemAction[] {
64             SystemAction.get(FindUnusedAction.class),
65             SystemAction.get(FindCTDerivationsAction.class),
66             SystemAction.get(FindSubstitutionGroupsAction.class),
67 // null
68
};
69     }
70     
71       
72     public JMenuItem getPopupPresenter() {
73         return new LazyMenu(getName());
74     }
75
76     public HelpCtx getHelpCtx() {
77         return HelpCtx.DEFAULT_HELP;
78         // If you will provide context help then use:
79
// return new HelpCtx(PromoteBusinessMethodAction.class);
80
}
81
82     protected boolean enable(org.openide.nodes.Node[] activatedNodes) {
83         return true;
84     }
85
86     protected void performAction(org.openide.nodes.Node[] activatedNodes) {
87          assert false : "Should never be called: ";
88     }
89
90
91     /**
92      * Avoids constructing submenu until it will be needed.
93      */

94     protected class LazyMenu extends JMenu {
95         private final static long serialVersionUID = 1L;
96
97         public LazyMenu(String JavaDoc name) {
98             super(name);
99         }
100
101         public JPopupMenu getPopupMenu() {
102             if (getItemCount() == 0) {
103                 SystemAction[] grouped = grouped();
104                 for (int i = 0; i < grouped.length; i++) {
105                     SystemAction action = grouped[i];
106                     if (action == null) {
107                         addSeparator();
108                     } else if (action instanceof Presenter.Popup) {
109                         add(((Presenter.Popup)action).getPopupPresenter());
110                     } else {
111                         assert false : "Action had no popup presenter: " + action;
112                     }
113                 }
114             }
115             return super.getPopupMenu();
116         }
117
118     }
119
120     
121 }
122
Popular Tags