KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > actions > RefactorAction


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  * RefactorAction.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.refactoring.actions;
30
31 import javax.swing.*;
32
33 import org.openide.util.*;
34 import org.openide.util.actions.NodeAction;
35 import org.openide.util.actions.Presenter;
36 import org.openide.util.actions.SystemAction;
37
38 /**
39  * Action which just holds a few other SystemAction's for grouping purposes.
40  * @author cwebster
41  * @author Jeri Lockhart
42  */

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

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

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