KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > languages > javascript > refactoring > RenameRefactoringUI


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.languages.javascript.refactoring;
20
21 import java.text.MessageFormat JavaDoc;
22 import javax.swing.event.ChangeListener JavaDoc;
23 import javax.swing.text.Document JavaDoc;
24 import org.netbeans.api.languages.ASTItem;
25 import org.netbeans.api.languages.ASTNode;
26 import org.netbeans.api.languages.ASTPath;
27 import org.netbeans.api.languages.ASTToken;
28 import org.netbeans.api.languages.ASTToken;
29 import org.netbeans.modules.refactoring.api.RenameRefactoring;
30 import org.netbeans.modules.refactoring.spi.ui.CustomRefactoringPanel;
31 import org.netbeans.modules.refactoring.spi.ui.RefactoringUI;
32 import org.openide.filesystems.FileObject;
33 import org.openide.util.HelpCtx;
34 import org.openide.util.NbBundle;
35 import org.openide.util.lookup.Lookups;
36
37 /**
38  *
39  * @author Daniel Prusa
40  */

41 public class RenameRefactoringUI implements RefactoringUI {
42     
43     private String JavaDoc newName = null;
44     private String JavaDoc oldName = null;
45     private RenameRefactoring refactoring = null;
46     private RenamePanel panel;
47     private ASTPath path;
48
49     public RenameRefactoringUI(ASTPath path, FileObject fileObject, Document JavaDoc doc) {
50         this.refactoring = new RenameRefactoring(Lookups.fixed(path, fileObject, doc));
51         this.path = path;
52         ASTItem item = path.getLeaf();
53         this.oldName = item instanceof ASTToken ? ((ASTToken)item).getIdentifier() : ((ASTNode) item).getNT();
54     }
55     
56     public boolean isQuery() {
57         return false;
58     }
59
60     public CustomRefactoringPanel getPanel(ChangeListener JavaDoc parent) {
61         if (panel == null) {
62             ASTToken item = (ASTToken) path.getLeaf();
63             String JavaDoc itemName = item.getIdentifier();
64             String JavaDoc panelName = NbBundle.getMessage(RenameRefactoringUI.class, "LBL_Rename") + ' ' + itemName;
65             panel = new RenamePanel(itemName, parent, panelName);
66         }
67         return panel;
68     }
69
70     public org.netbeans.modules.refactoring.api.Problem setParameters() {
71         newName = panel.getNameValue();
72         refactoring.setNewName(newName);
73         return refactoring.checkParameters();
74     }
75
76     public org.netbeans.modules.refactoring.api.Problem checkParameters() {
77         return refactoring.fastCheckParameters();
78     }
79
80     public org.netbeans.modules.refactoring.api.AbstractRefactoring getRefactoring() {
81         return refactoring;
82     }
83
84     public String JavaDoc getDescription() {
85         return new MessageFormat JavaDoc(NbBundle.getMessage(RenameRefactoringUI.class, "DSC_Rename")).format (
86                     new Object JavaDoc[] {oldName, newName}
87                 );
88     }
89
90     public String JavaDoc getName() {
91         return NbBundle.getMessage(RenameRefactoringUI.class, "LBL_Rename");
92     }
93     
94     public boolean hasParameters() {
95         return true;
96     }
97
98     public HelpCtx getHelpCtx() {
99         return new HelpCtx(WhereUsedQueryUI.class);
100     }
101     
102 }
103
Popular Tags