| /******************************************************************************* |
| * Copyright (c) 2000, 2017 IBM Corporation and others. |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| *******************************************************************************/ |
| |
| package org.eclipse.dltk.internal.ui.refactoring.reorg; |
| |
| import org.eclipse.core.runtime.CoreException; |
| import org.eclipse.dltk.internal.corext.refactoring.tagging.INameUpdating; |
| import org.eclipse.dltk.internal.ui.refactoring.RefactoringMessages; |
| import org.eclipse.dltk.ui.DLTKUIPlugin; |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.ltk.core.refactoring.Refactoring; |
| import org.eclipse.ltk.core.refactoring.RefactoringStatus; |
| import org.eclipse.ltk.ui.refactoring.RefactoringWizard; |
| |
| public class RenameRefactoringWizard extends RefactoringWizard { |
| |
| private final String fInputPageDescription; |
| protected final String fPageContextHelpId; |
| private final ImageDescriptor fInputPageImageDescriptor; |
| |
| public RenameRefactoringWizard(Refactoring refactoring, |
| String defaultPageTitle, String inputPageDescription, |
| ImageDescriptor inputPageImageDescriptor, |
| String pageContextHelpId) { |
| super(refactoring, DIALOG_BASED_USER_INTERFACE); |
| setDefaultPageTitle(defaultPageTitle); |
| fInputPageDescription = inputPageDescription; |
| fInputPageImageDescriptor = inputPageImageDescriptor; |
| fPageContextHelpId = pageContextHelpId; |
| } |
| |
| @Override |
| protected void addUserInputPages() { |
| String initialSetting = getNameUpdating().getCurrentElementName(); |
| RenameInputWizardPage inputPage = createInputPage(fInputPageDescription, |
| initialSetting); |
| inputPage.setImageDescriptor(fInputPageImageDescriptor); |
| addPage(inputPage); |
| } |
| |
| private INameUpdating getNameUpdating() { |
| return getRefactoring().getAdapter(INameUpdating.class); |
| } |
| |
| protected RenameInputWizardPage createInputPage(String message, |
| String initialSetting) { |
| return new RenameInputWizardPage(message, fPageContextHelpId, true, |
| initialSetting) { |
| @Override |
| protected RefactoringStatus validateTextField(String text) { |
| return validateNewName(text); |
| } |
| }; |
| } |
| |
| protected RefactoringStatus validateNewName(String newName) { |
| INameUpdating ref = getNameUpdating(); |
| ref.setNewElementName(newName); |
| try { |
| return ref.checkNewElementName(newName); |
| } catch (CoreException e) { |
| DLTKUIPlugin.log(e); |
| return RefactoringStatus.createFatalErrorStatus( |
| RefactoringMessages.RenameRefactoringWizard_internal_error); |
| } |
| } |
| } |