001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring.reorg;
011:
012: import org.eclipse.core.runtime.CoreException;
013:
014: import org.eclipse.jface.resource.ImageDescriptor;
015:
016: import org.eclipse.jdt.internal.corext.refactoring.rename.RenamingNameSuggestor;
017: import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating;
018: import org.eclipse.jdt.internal.ui.JavaPlugin;
019: import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
020:
021: import org.eclipse.ltk.core.refactoring.Refactoring;
022: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
023: import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
024:
025: public class RenameRefactoringWizard extends RefactoringWizard {
026:
027: private final String fInputPageDescription;
028: private final String fPageContextHelpId;
029: private final ImageDescriptor fInputPageImageDescriptor;
030:
031: // dialog settings constants:
032:
033: /**
034: * Dialog settings key (value is of type boolean).
035: */
036: public static final String UPDATE_TEXTUAL_MATCHES = "updateTextualMatches"; //$NON-NLS-1$
037: /**
038: * Dialog settings key (value is of type boolean).
039: */
040: public static final String UPDATE_QUALIFIED_NAMES = "updateQualifiedNames"; //$NON-NLS-1$
041: /**
042: * Dialog settings key (value is of type String).
043: */
044: public static final String QUALIFIED_NAMES_PATTERNS = "patterns"; //$NON-NLS-1$
045:
046: /**
047: * Dialog settings key (value is of type boolean).
048: */
049: public static final String TYPE_UPDATE_SIMILAR_ELEMENTS = "updateSimilarElements"; //$NON-NLS-1$
050: /**
051: * Dialog settings key (value is of type int).
052: * @see RenamingNameSuggestor
053: */
054: public static final String TYPE_SIMILAR_MATCH_STRATEGY = "updateSimilarElementsMatchStrategy"; //$NON-NLS-1$
055:
056: /**
057: * Dialog settings key (value is of type boolean).
058: */
059: public static final String PACKAGE_RENAME_SUBPACKAGES = "renameSubpackages"; //$NON-NLS-1$
060:
061: /**
062: * Dialog settings key (value is of type boolean).
063: */
064: public static final String FIELD_RENAME_GETTER = "renameGetter"; //$NON-NLS-1$
065: /**
066: * Dialog settings key (value is of type boolean).
067: */
068: public static final String FIELD_RENAME_SETTER = "renameSetter"; //$NON-NLS-1$
069:
070: public RenameRefactoringWizard(Refactoring refactoring,
071: String defaultPageTitle, String inputPageDescription,
072: ImageDescriptor inputPageImageDescriptor,
073: String pageContextHelpId) {
074: super (refactoring, DIALOG_BASED_USER_INTERFACE);
075: setDefaultPageTitle(defaultPageTitle);
076: fInputPageDescription = inputPageDescription;
077: fInputPageImageDescriptor = inputPageImageDescriptor;
078: fPageContextHelpId = pageContextHelpId;
079: setDialogSettings(JavaPlugin.getDefault().getDialogSettings());
080: }
081:
082: /* non java-doc
083: * @see RefactoringWizard#addUserInputPages
084: */
085: protected void addUserInputPages() {
086: String initialSetting = getNameUpdating()
087: .getCurrentElementName();
088: RenameInputWizardPage inputPage = createInputPage(
089: fInputPageDescription, initialSetting);
090: inputPage.setImageDescriptor(fInputPageImageDescriptor);
091: addPage(inputPage);
092: }
093:
094: private INameUpdating getNameUpdating() {
095: return (INameUpdating) getRefactoring().getAdapter(
096: INameUpdating.class);
097: }
098:
099: protected RenameInputWizardPage createInputPage(String message,
100: String initialSetting) {
101: return new RenameInputWizardPage(message, fPageContextHelpId,
102: true, initialSetting) {
103: protected RefactoringStatus validateTextField(String text) {
104: return validateNewName(text);
105: }
106: };
107: }
108:
109: /**
110: * Sets a new name, validates the input, and returns the status.
111: *
112: * @param newName the new name
113: * @return validation status
114: */
115: protected RefactoringStatus validateNewName(String newName) {
116: INameUpdating ref = getNameUpdating();
117: ref.setNewElementName(newName);
118: try {
119: return ref.checkNewElementName(newName);
120: } catch (CoreException e) {
121: JavaPlugin.log(e);
122: return RefactoringStatus
123: .createFatalErrorStatus(RefactoringMessages.RenameRefactoringWizard_internal_error);
124: }
125: }
126: }
|