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.IProject;
07: import org.eclipse.core.resources.IWorkspace;
08: import org.eclipse.core.resources.ResourcesPlugin;
09: import org.eclipse.core.runtime.IProgressMonitor;
10: import org.eclipse.core.runtime.OperationCanceledException;
11: import org.eclipse.jdt.core.IField;
12: import org.eclipse.jdt.core.IJavaElement;
13: import org.eclipse.jdt.core.IType;
14: import org.eclipse.ltk.core.refactoring.Change;
15: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
16:
17: import org.terracotta.dso.PatternHelper;
18: import org.terracotta.dso.TcPlugin;
19:
20: public class RenameFieldChange extends Change {
21: private String fNewFieldName;
22: private String fOldFieldName;
23: private String fProjectName;
24:
25: public RenameFieldChange(IField field, String newTypeName) {
26: IType type = field.getDeclaringType();
27: String parentType = PatternHelper.getFullyQualifiedName(type);
28: String fieldName = field.getElementName();
29:
30: fOldFieldName = parentType + "." + fieldName;
31: fNewFieldName = parentType + "." + newTypeName;
32: fProjectName = field.getAncestor(IJavaElement.JAVA_PROJECT)
33: .getElementName();
34: }
35:
36: public RenameFieldChange(String oldFieldName, String newFieldName,
37: String projectName) {
38: fNewFieldName = newFieldName;
39: fOldFieldName = oldFieldName;
40: fProjectName = projectName;
41: }
42:
43: public Object getModifiedElement() {
44: return null;
45: }
46:
47: public String getName() {
48: return "TCRenameFieldConfigUpdate";
49: }
50:
51: public void initializeValidationData(IProgressMonitor pm) {/**/
52: }
53:
54: public RefactoringStatus isValid(IProgressMonitor pm)
55: throws OperationCanceledException {
56: return new RefactoringStatus();
57: }
58:
59: public Change perform(IProgressMonitor pm) {
60: TcPlugin plugin = TcPlugin.getDefault();
61: IWorkspace workspace = ResourcesPlugin.getWorkspace();
62: IProject project = workspace.getRoot().getProject(fProjectName);
63:
64: plugin.getConfigurationHelper(project).renameRoot(
65: fOldFieldName, fNewFieldName);
66:
67: // create the undo change
68: return new RenameFieldChange(fNewFieldName, fOldFieldName,
69: fProjectName);
70: }
71: }
|