KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > reorg > MonitoringNewNameQueries


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.corext.refactoring.reorg;
12
13 import org.eclipse.core.runtime.OperationCanceledException;
14
15 import org.eclipse.core.resources.mapping.ResourceMapping;
16
17 import org.eclipse.core.resources.IResource;
18
19 import org.eclipse.ltk.core.refactoring.participants.ReorgExecutionLog;
20
21 import org.eclipse.jdt.core.ICompilationUnit;
22 import org.eclipse.jdt.core.IPackageFragment;
23 import org.eclipse.jdt.core.IPackageFragmentRoot;
24
25 import org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping;
26 import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
27
28
29 public class MonitoringNewNameQueries implements INewNameQueries {
30     private INewNameQueries fDelegate;
31     private ReorgExecutionLog fExecutionLog;
32     public MonitoringNewNameQueries(INewNameQueries delegate, ReorgExecutionLog log) {
33         fDelegate= delegate;
34         fExecutionLog= log;
35     }
36     public INewNameQuery createNewCompilationUnitNameQuery(final ICompilationUnit cu, final String JavaDoc initialSuggestedName) {
37         return new INewNameQuery() {
38             public String JavaDoc getNewName() throws OperationCanceledException {
39                 String JavaDoc result= fDelegate.createNewCompilationUnitNameQuery(cu, initialSuggestedName).getNewName();
40                 String JavaDoc newName= JavaModelUtil.getRenamedCUName(cu, result);
41                 fExecutionLog.setNewName(cu, newName);
42                 ResourceMapping mapping= JavaElementResourceMapping.create(cu);
43                 if (mapping != null) {
44                     fExecutionLog.setNewName(mapping, newName);
45                 }
46                 return result;
47             }
48         };
49     }
50     public INewNameQuery createNewPackageFragmentRootNameQuery(final IPackageFragmentRoot root, final String JavaDoc initialSuggestedName) {
51         return new INewNameQuery() {
52             public String JavaDoc getNewName() throws OperationCanceledException {
53                 String JavaDoc result= fDelegate.createNewPackageFragmentRootNameQuery(root, initialSuggestedName).getNewName();
54                 fExecutionLog.setNewName(root, result);
55                 ResourceMapping mapping= JavaElementResourceMapping.create(root);
56                 if (mapping != null) {
57                     fExecutionLog.setNewName(mapping, result);
58                 }
59                 return result;
60             }
61         };
62     }
63     public INewNameQuery createNewPackageNameQuery(final IPackageFragment pack, final String JavaDoc initialSuggestedName) {
64         return new INewNameQuery() {
65             public String JavaDoc getNewName() throws OperationCanceledException {
66                 String JavaDoc result= fDelegate.createNewPackageNameQuery(pack, initialSuggestedName).getNewName();
67                 fExecutionLog.setNewName(pack, result);
68                 ResourceMapping mapping= JavaElementResourceMapping.create(pack);
69                 if (mapping != null) {
70                     int index= result.lastIndexOf('.');
71                     String JavaDoc newFolderName= index == -1 ? result : result.substring(index + 1);
72                     fExecutionLog.setNewName(mapping, newFolderName);
73                 }
74                 return result;
75             }
76         };
77     }
78     public INewNameQuery createNewResourceNameQuery(final IResource res, final String JavaDoc initialSuggestedName) {
79         return new INewNameQuery() {
80             public String JavaDoc getNewName() throws OperationCanceledException {
81                 String JavaDoc result= fDelegate.createNewResourceNameQuery(res, initialSuggestedName).getNewName();
82                 fExecutionLog.setNewName(res, result);
83                 return result;
84             }
85         };
86     }
87     public INewNameQuery createNullQuery() {
88         return fDelegate.createNullQuery();
89     }
90     public INewNameQuery createStaticQuery(String JavaDoc newName) {
91         return fDelegate.createStaticQuery(newName);
92     }
93 }
94
Popular Tags