KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.refactoring.reorg;
13
14 import org.eclipse.core.runtime.CoreException;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17
18 import org.eclipse.jdt.internal.corext.refactoring.rename.RenamingNameSuggestor;
19 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
20 import org.eclipse.jdt.internal.ui.JavaPlugin;
21 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
22
23 import org.eclipse.ltk.core.refactoring.Refactoring;
24 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
25 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
26
27 public class RenameRefactoringWizard extends RefactoringWizard {
28     
29     private final String JavaDoc fInputPageDescription;
30     private final String JavaDoc fPageContextHelpId;
31     private final ImageDescriptor fInputPageImageDescriptor;
32     
33     // dialog settings constants:
34

35     /**
36      * Dialog settings key (value is of type boolean).
37      */

38     public static final String JavaDoc UPDATE_TEXTUAL_MATCHES= "updateTextualMatches"; //$NON-NLS-1$
39
/**
40      * Dialog settings key (value is of type boolean).
41      */

42     public static final String JavaDoc UPDATE_QUALIFIED_NAMES= "updateQualifiedNames"; //$NON-NLS-1$
43
/**
44      * Dialog settings key (value is of type String).
45      */

46     public static final String JavaDoc QUALIFIED_NAMES_PATTERNS= "patterns"; //$NON-NLS-1$
47

48     /**
49      * Dialog settings key (value is of type boolean).
50      */

51     public static final String JavaDoc TYPE_UPDATE_SIMILAR_ELEMENTS= "updateSimilarElements"; //$NON-NLS-1$
52
/**
53      * Dialog settings key (value is of type int).
54      * @see RenamingNameSuggestor
55      */

56     public static final String JavaDoc TYPE_SIMILAR_MATCH_STRATEGY= "updateSimilarElementsMatchStrategy"; //$NON-NLS-1$
57

58     /**
59      * Dialog settings key (value is of type boolean).
60      */

61     public static final String JavaDoc PACKAGE_RENAME_SUBPACKAGES= "renameSubpackages"; //$NON-NLS-1$
62

63     /**
64      * Dialog settings key (value is of type boolean).
65      */

66     public static final String JavaDoc FIELD_RENAME_GETTER= "renameGetter"; //$NON-NLS-1$
67
/**
68      * Dialog settings key (value is of type boolean).
69      */

70     public static final String JavaDoc FIELD_RENAME_SETTER= "renameSetter"; //$NON-NLS-1$
71

72     
73     public RenameRefactoringWizard(Refactoring refactoring, String JavaDoc defaultPageTitle, String JavaDoc inputPageDescription,
74             ImageDescriptor inputPageImageDescriptor, String JavaDoc pageContextHelpId) {
75         super(refactoring, DIALOG_BASED_USER_INTERFACE);
76         setDefaultPageTitle(defaultPageTitle);
77         fInputPageDescription= inputPageDescription;
78         fInputPageImageDescriptor= inputPageImageDescriptor;
79         fPageContextHelpId= pageContextHelpId;
80         setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
81     }
82
83     /* non java-doc
84      * @see RefactoringWizard#addUserInputPages
85      */

86     protected void addUserInputPages() {
87         String JavaDoc initialSetting= getNameUpdating().getCurrentElementName();
88         RenameInputWizardPage inputPage= createInputPage(fInputPageDescription, initialSetting);
89         inputPage.setImageDescriptor(fInputPageImageDescriptor);
90         addPage(inputPage);
91     }
92
93     private INameUpdating getNameUpdating() {
94         return (INameUpdating)getRefactoring().getAdapter(INameUpdating.class);
95     }
96     
97     protected RenameInputWizardPage createInputPage(String JavaDoc message, String JavaDoc initialSetting) {
98         return new RenameInputWizardPage(message, fPageContextHelpId, true, initialSetting) {
99             protected RefactoringStatus validateTextField(String JavaDoc text) {
100                 return validateNewName(text);
101             }
102         };
103     }
104     
105     protected RefactoringStatus validateNewName(String JavaDoc newName) {
106         INameUpdating ref= getNameUpdating();
107         ref.setNewElementName(newName);
108         try{
109             return ref.checkNewElementName(newName);
110         } catch (CoreException e){
111             JavaPlugin.log(e);
112             return RefactoringStatus.createFatalErrorStatus(RefactoringMessages.RenameRefactoringWizard_internal_error);
113         }
114     }
115 }
116
Popular Tags