KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.refactoring.actions;
20
21 import org.netbeans.modules.refactoring.spi.ui.UI;
22 import org.netbeans.modules.xml.refactoring.FileRenameRequest;
23 import org.netbeans.modules.xml.refactoring.RefactoringManager;
24 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil;
25 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.FileRenameRefactoringUI;
26 import org.netbeans.modules.xml.refactoring.ui.j.ui.RefactoringPanel;
27 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
28 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
29 import org.netbeans.modules.xml.xam.Model;
30 import org.netbeans.modules.xml.xam.Referenceable;
31 import org.openide.nodes.Node;
32 import org.openide.text.CloneableEditorSupport;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.actions.CookieAction;
36 import org.openide.windows.TopComponent;
37
38 /**
39  *
40  * @author Nam Nguyen
41  */

42 public class FileRenameAction extends CookieAction {
43     public static Class JavaDoc[] EMPTY_CLASS_ARRAY = new Class JavaDoc[0];
44     
45     /** Creates a new instance of FileRenameAction */
46     public FileRenameAction() {
47         super();
48     }
49
50     protected boolean enable(Node[] activatedNodes) {
51         if (activatedNodes.length != 1) {
52             return false;
53         }
54         Referenceable ref = AnalysisUtilities.getReferenceable(activatedNodes);
55         return ref instanceof Model && RefactoringUtil.isWritable((Model)ref) &&
56                RefactoringManager.getInstance().canChange(FileRenameRequest.class, ref);
57     }
58     
59     protected void performAction(Node[] activatedNodes) {
60         System.out.println("FileRename called");
61         if (activatedNodes.length != 1) return;
62
63         Referenceable ref = AnalysisUtilities.getReferenceable(activatedNodes);
64         if (ref instanceof Model) {
65             Model model = (Model) ref;
66             WhereUsedView wuv = new WhereUsedView(model);
67             FileRenameRefactoringUI ui = new FileRenameRefactoringUI(wuv, model);
68             TopComponent activetc = TopComponent.getRegistry().getActivated();
69             //UI.openRefactoringUI(ui);
70

71             if (activetc instanceof CloneableEditorSupport.Pane) {
72            // new RefactoringPanel(ui, activetc);
73
} else {
74             // new RefactoringPanel(ui);
75
}
76         }
77     }
78
79     protected int mode() {
80         return CookieAction.MODE_EXACTLY_ONE;
81     }
82
83     public String JavaDoc getName() {
84         return NbBundle.getMessage(FileRenameAction.class, "LBL_FileRename");
85     }
86
87     public HelpCtx getHelpCtx() {
88         return HelpCtx.DEFAULT_HELP;
89     }
90
91     protected Class JavaDoc[] cookieClasses() {
92         return EMPTY_CLASS_ARRAY;
93     }
94
95     protected boolean asynchronous() {
96         return false;
97     }
98 }
99
Popular Tags