1 19 package org.netbeans.modules.languages.javascript.refactoring; 20 21 import java.text.MessageFormat ; 22 import javax.swing.event.ChangeListener ; 23 import javax.swing.text.Document ; 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 41 public class RenameRefactoringUI implements RefactoringUI { 42 43 private String newName = null; 44 private String oldName = null; 45 private RenameRefactoring refactoring = null; 46 private RenamePanel panel; 47 private ASTPath path; 48 49 public RenameRefactoringUI(ASTPath path, FileObject fileObject, Document 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 parent) { 61 if (panel == null) { 62 ASTToken item = (ASTToken) path.getLeaf(); 63 String itemName = item.getIdentifier(); 64 String 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 getDescription() { 85 return new MessageFormat (NbBundle.getMessage(RenameRefactoringUI.class, "DSC_Rename")).format ( 86 new Object [] {oldName, newName} 87 ); 88 } 89 90 public String 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 |