KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > terracotta > dso > refactoring > RenamePackageFragmentChange


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package org.terracotta.dso.refactoring;
5
6 import org.eclipse.core.resources.IProject;
7 import org.eclipse.core.resources.IWorkspace;
8 import org.eclipse.core.resources.ResourcesPlugin;
9 import org.eclipse.core.runtime.IProgressMonitor;
10 import org.eclipse.core.runtime.OperationCanceledException;
11 import org.eclipse.jdt.core.IJavaElement;
12 import org.eclipse.jdt.core.IPackageFragment;
13 import org.eclipse.ltk.core.refactoring.Change;
14 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
15
16 import org.terracotta.dso.TcPlugin;
17
18 public class RenamePackageFragmentChange extends Change {
19   private String JavaDoc fOldFragmentName;
20   private String JavaDoc fNewFragmentName;
21   private String JavaDoc fProjectName;
22     
23   public RenamePackageFragmentChange(IPackageFragment fragment, String JavaDoc newName) {
24     fOldFragmentName = fragment.getElementName();
25     fNewFragmentName = newName;
26     fProjectName = fragment.getAncestor(IJavaElement.JAVA_PROJECT).getElementName();
27   }
28   
29   public RenamePackageFragmentChange(String JavaDoc oldTypeName,
30                                      String JavaDoc newTypeName,
31                                      String JavaDoc projectName)
32   {
33     fNewFragmentName = newTypeName;
34     fOldFragmentName = oldTypeName;
35     fProjectName = projectName;
36   }
37
38   public Object JavaDoc getModifiedElement() {
39     return null;
40   }
41   
42   public String JavaDoc getName() {
43     return "TCRenamePackageFragmentConfigUpdate";
44   }
45   
46   public void initializeValidationData(IProgressMonitor pm) {/**/}
47   
48   public RefactoringStatus isValid(IProgressMonitor pm)
49     throws OperationCanceledException
50   {
51     return new RefactoringStatus();
52   }
53   
54   public Change perform(IProgressMonitor pm) {
55     IWorkspace workspace = ResourcesPlugin.getWorkspace();
56     IProject project = workspace.getRoot().getProject(fProjectName);
57     
58     TcPlugin.getDefault().replaceConfigText(project, fOldFragmentName, fNewFragmentName);
59     
60     // create the undo change
61
return new RenamePackageFragmentChange(fNewFragmentName, fOldFragmentName, fProjectName);
62   }
63 }
64
Popular Tags