KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > reorg > RenameCuWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Matt Chapman, mpchapman@gmail.com - 89977 Make JDT .java agnostic
11  *******************************************************************************/

12 package org.eclipse.jdt.internal.ui.refactoring.reorg;
13
14
15 import org.eclipse.ltk.core.refactoring.Refactoring;
16 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
17 import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
18
19 import org.eclipse.jdt.core.ICompilationUnit;
20 import org.eclipse.jdt.core.JavaCore;
21
22 import org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor;
23 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
24 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
25
26 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
27 import org.eclipse.jdt.internal.ui.JavaPluginImages;
28 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
29
30 public class RenameCuWizard extends RenameTypeWizard {
31     
32     public RenameCuWizard(Refactoring refactoring) {
33         super(refactoring,
34             RefactoringMessages.RenameCuWizard_defaultPageTitle,
35             RefactoringMessages.RenameCuWizard_inputPage_description,
36             JavaPluginImages.DESC_WIZBAN_REFACTOR_CU,
37             IJavaHelpContextIds.RENAME_CU_WIZARD_PAGE);
38     }
39     
40     protected RefactoringStatus validateNewName(String JavaDoc newName) {
41         String JavaDoc fullName= JavaModelUtil.getRenamedCUName(getCompilationUnit(), newName);
42         return super.validateNewName(fullName);
43     }
44
45     private ICompilationUnit getCompilationUnit() {
46         return (ICompilationUnit) getCompilationUnitProcessor().getElements()[0];
47     }
48
49     protected RenameInputWizardPage createInputPage(String JavaDoc message, String JavaDoc initialSetting) {
50         return new RenameTypeWizardInputPage(message, IJavaHelpContextIds.RENAME_CU_WIZARD_PAGE, true, initialSetting) {
51             protected RefactoringStatus validateTextField(String JavaDoc text) {
52                 return validateNewName(text);
53             }
54             protected String JavaDoc getNewName(INameUpdating nameUpdating) {
55                 String JavaDoc result= nameUpdating.getNewElementName();
56                 // If renaming a CU we have to remove the java file extension
57
return JavaCore.removeJavaLikeExtension(result);
58             }
59         };
60     }
61
62     protected boolean isRenameType() {
63         // the flag 'willRenameType' may change in checkInitialConditions(), but
64
// only from true to false.
65
return getCompilationUnitProcessor().isWillRenameType();
66     }
67
68     private RenameCompilationUnitProcessor getCompilationUnitProcessor() {
69         return ((RenameCompilationUnitProcessor) ((RenameRefactoring) getRefactoring()).getProcessor());
70     }
71 }
72
Popular Tags