01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.refactoring;
05:
06: import org.eclipse.core.resources.IFile;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.resources.IWorkspace;
09: import org.eclipse.core.resources.ResourcesPlugin;
10: import org.eclipse.core.runtime.IProgressMonitor;
11: import org.eclipse.core.runtime.OperationCanceledException;
12: import org.eclipse.jdt.core.IJavaElement;
13: import org.eclipse.jdt.core.IPackageFragment;
14: import org.eclipse.ltk.core.refactoring.Change;
15: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
16:
17: import org.terracotta.dso.TcPlugin;
18:
19: public class RenamePackageFragmentChange extends Change {
20: private String fOldFragmentName;
21: private String fNewFragmentName;
22: private String fProjectName;
23:
24: public RenamePackageFragmentChange(IPackageFragment fragment,
25: String newName) {
26: fOldFragmentName = fragment.getElementName();
27: fNewFragmentName = newName;
28: fProjectName = fragment.getAncestor(IJavaElement.JAVA_PROJECT)
29: .getElementName();
30: }
31:
32: public RenamePackageFragmentChange(String oldTypeName,
33: String newTypeName, String projectName) {
34: fNewFragmentName = newTypeName;
35: fOldFragmentName = oldTypeName;
36: fProjectName = projectName;
37: }
38:
39: public Object getModifiedElement() {
40: return null;
41: }
42:
43: public String getName() {
44: IWorkspace workspace = ResourcesPlugin.getWorkspace();
45: IProject project = workspace.getRoot().getProject(fProjectName);
46: IFile configFile = TcPlugin.getDefault().getConfigurationFile(
47: project);
48: return "Replace '" + fOldFragmentName + "' with '"
49: + fNewFragmentName + "' in " + configFile.getName();
50: }
51:
52: public void initializeValidationData(IProgressMonitor pm) {/**/
53: }
54:
55: public RefactoringStatus isValid(IProgressMonitor pm)
56: throws OperationCanceledException {
57: return new RefactoringStatus();
58: }
59:
60: public Change perform(IProgressMonitor pm) {
61: IWorkspace workspace = ResourcesPlugin.getWorkspace();
62: IProject project = workspace.getRoot().getProject(fProjectName);
63:
64: TcPlugin.getDefault().replaceConfigText(project,
65: fOldFragmentName, fNewFragmentName);
66:
67: // create the undo change
68: return new RenamePackageFragmentChange(fNewFragmentName,
69: fOldFragmentName, fProjectName);
70: }
71: }
|