KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.eclipse.jdt.internal.ui.refactoring.reorg;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.NullProgressMonitor;
15
16 import org.eclipse.jdt.core.IMethod;
17
18 import org.eclipse.swt.widgets.Shell;
19
20 import org.eclipse.jface.dialogs.MessageDialog;
21
22 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
23 import org.eclipse.jdt.internal.corext.refactoring.rename.RenameVirtualMethodProcessor;
24 import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
25 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
26 import org.eclipse.jdt.internal.corext.util.Messages;
27
28 import org.eclipse.ltk.core.refactoring.Refactoring;
29 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
30
31 public class RenameMethodUserInterfaceStarter extends RenameUserInterfaceStarter {
32     
33     /* (non-Javadoc)
34      * @see org.eclipse.jdt.internal.ui.refactoring.reorg.RenameUserInterfaceStarter#activate(org.eclipse.jdt.internal.corext.refactoring.base.Refactoring, org.eclipse.swt.widgets.Shell)
35      */

36     public boolean activate(Refactoring refactoring, Shell parent, int saveMode) throws CoreException {
37         RenameVirtualMethodProcessor processor= (RenameVirtualMethodProcessor)refactoring.getAdapter(RenameVirtualMethodProcessor.class);
38         if (processor != null) {
39             RefactoringStatus status= processor.checkInitialConditions(new NullProgressMonitor());
40             if (!status.hasFatalError()) {
41                 IMethod method= processor.getMethod();
42                 if (!method.equals(processor.getOriginalMethod())) {
43                     String JavaDoc message= null;
44                     if (method.getDeclaringType().isInterface()) {
45                         message= Messages.format(
46                             RefactoringCoreMessages.MethodChecks_implements,
47                             new String JavaDoc[]{
48                                 JavaElementUtil.createMethodSignature(method),
49                                 JavaModelUtil.getFullyQualifiedName(method.getDeclaringType())});
50                     } else {
51                         message= Messages.format(
52                             RefactoringCoreMessages.MethodChecks_overrides,
53                             new String JavaDoc[]{
54                                 JavaElementUtil.createMethodSignature(method),
55                                 JavaModelUtil.getFullyQualifiedName(method.getDeclaringType())});
56                     }
57                     message= Messages.format(
58                         ReorgMessages.RenameMethodUserInterfaceStarter_message,
59                         message);
60                     if (!MessageDialog.openQuestion(parent,
61                             ReorgMessages.RenameMethodUserInterfaceStarter_name,
62                             message)) {
63                         return false;
64                     }
65                 }
66             }
67         }
68         return super.activate(refactoring, parent, saveMode);
69     }
70 }
71
Popular Tags