KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SafelyRenameAction.java
22  *
23  * Created on May 25, 2006, 12:20 PM
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 org.netbeans.modules.xml.refactoring.RefactorRequest;
32 import org.netbeans.modules.xml.refactoring.RefactoringManager;
33 import org.netbeans.modules.xml.refactoring.RenameRequest;
34 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil;
35 import org.netbeans.modules.xml.refactoring.ui.ReferenceableProvider;
36 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.RenameRefactoringUI;
37 import org.netbeans.modules.xml.refactoring.ui.j.ui.RefactoringPanel;
38 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
39 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
40 import org.netbeans.modules.xml.xam.Model;
41 import org.netbeans.modules.xml.xam.Nameable;
42 import org.netbeans.modules.xml.xam.Referenceable;
43 import org.openide.nodes.Node;
44 import org.openide.text.CloneableEditorSupport;
45 import org.openide.util.HelpCtx;
46 import org.openide.util.NbBundle;
47 import org.openide.util.actions.CookieAction;
48 import org.openide.windows.TopComponent;
49
50 /**
51  *
52  * @author Jeri Lockhart
53  */

54 public class SafelyRenameAction extends CookieAction {
55     
56     private static final long serialVersionUID = 1L;
57     
58     private static final Class JavaDoc[] COOKIE_ARRAY =
59             new Class JavaDoc[] {ReferenceableProvider.class };
60     
61     /** Creates a new instance of SafelyRenameAction */
62     public SafelyRenameAction() {
63         
64     }
65     
66     
67     /**
68      * Perform the action based on the currently activated nodes.
69      * Note that if the source of the event triggering this action was itself
70      * a node, that node will be the sole argument to this method, rather
71      * than the activated nodes.
72      *
73      *
74      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
75      */

76     protected void performAction(Node[] nodes) {
77         System.out.println("Safely reaname called");
78         if (nodes.length!=1)
79             return;
80         Referenceable referenceable = AnalysisUtilities.getReferenceable(nodes);
81         assert referenceable instanceof Nameable:"Only Nameables can be safely renamed.";
82         WhereUsedView wuv = new WhereUsedView(referenceable);
83         RenameRefactoringUI ui = new RenameRefactoringUI(wuv, (Nameable.class.cast(referenceable)));
84         TopComponent activetc = TopComponent.getRegistry().getActivated();
85         if (activetc instanceof CloneableEditorSupport.Pane) {
86           // new RefactoringPanel(ui, activetc);
87
} else {
88           // new RefactoringPanel(ui);
89
}
90     }
91     
92     
93     /**
94      * Test whether the action should be enabled based
95      * on the currently activated nodes.
96      *
97      *
98      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
99      * @return <code>true</code> to be enabled, <code>false</code> to be disabled
100      */

101     protected boolean enable(Node[] nodes) {
102         if (!super.enable(nodes))
103             return false;
104         Referenceable ref = AnalysisUtilities.getReferenceable(nodes);
105         return ref instanceof Nameable &&
106                 RefactoringUtil.isWritable(RefactorRequest.getModel(ref)) &&
107                 RefactoringManager.getInstance().canChange(
108                 RenameRequest.class, ref);
109     }
110
111     
112     /**
113      * Get a human presentable name of the action.
114      * This may be
115      * presented as an item in a menu.
116      * <p>Using the normal menu presenters, an included ampersand
117      * before a letter will be treated as the name of a mnemonic.
118      *
119      * @return the name of the action
120      */

121     public String JavaDoc getName() {
122         return NbBundle.getMessage(SafelyRenameAction.class, "LBL_Rename");
123     }
124     
125     /**
126      * Get a help context for the action.
127      *
128      * @return the help context for this action
129      */

130     public HelpCtx getHelpCtx() {
131         return HelpCtx.DEFAULT_HELP;
132     }
133     
134     /**
135      * If true, this action should be performed asynchronously in a private thread.
136      * If false, it will be performed synchronously as called in the event thread.
137      * <p>The default value is true for compatibility reasons; subclasses are strongly
138      * encouraged to override it to be false, and to either do their work promptly
139      * in the event thread and return, or to somehow do work asynchronously (for example
140      * using {@link RequestProcessor#getDefault}).
141      * <p class="nonnormative">You may currently set the global default to false
142      * by setting the system property
143      * <code>org.openide.util.actions.CallableSystemAction.synchronousByDefault</code>
144      * to <code>true</code>.</p>
145      * <p class="nonnormative">When true, the current implementation also provides for a wait cursor during
146      * the execution of the action. Subclasses which override to return false should
147      * consider directly providing a wait or busy cursor if the nature of the action
148      * merits it.</p>
149      *
150      * @return true if this action should automatically be performed asynchronously
151      * @since 4.11
152      */

153     protected boolean asynchronous() {
154         return false;
155     }
156     
157     protected int mode() {
158         return CookieAction.MODE_EXACTLY_ONE;
159     }
160     
161     
162     protected Class JavaDoc[] cookieClasses() {
163         return COOKIE_ARRAY;
164     }
165     
166 }
167
Popular Tags