return true;
}
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
CompositeChange result = new CompositeChange(getName());
try {
pm
.beginTask(
"beging create change for context-root and artifactId",
100);
String oldName = project.getName();
String underProjectFilePath = getDeploymentPlanFileUnderProjectPath(project);
String projectRelativeFilePath = deploymentPlanFile.getFullPath()
.toString();
String absoluteWorkspacePath = project.getParent().getLocation()
.toString();
String absoluteFilePath = absoluteWorkspacePath
+ projectRelativeFilePath;
DeploymentPlanEditHelper editHelper = new DeploymentPlanEditHelper(
new DeploymentPlanHandler(absoluteFilePath));
// Before this change being applied, the project has been
// renamed. So, use a MovedTextFileChange instead of TextFileChange
String newName = this.getArguments().getNewName();
IProject newProject = ((IWorkspaceRoot) deploymentPlanFile
.getProject().getParent()).getProject(newName);
IFile newFile = newProject.getFile(underProjectFilePath);
// if a web project, should create a context-root change if any
if (JavaEEProjectUtilities.isDynamicWebProject(project)) {
// create change for context-root
String oldName1 = editHelper
.getNodeValue(DeploymentPlanTextNode.CONTEXT_ROOT);
int offset1 = editHelper
.getNodeOffset(DeploymentPlanTextNode.CONTEXT_ROOT);
if (offset1 != -1 && oldName1 != null
&& oldName1.substring(1).equals(oldName)) {
MovedTextFileChange change1 = new MovedTextFileChange(
"Rename artifactId's value", newFile,
deploymentPlanFile);
MultiTextEdit rootEdit1 = new MultiTextEdit();
ReplaceEdit edit1 = new ReplaceEdit(offset1, oldName1
.length(), "/" + newName);
rootEdit1.addChild(edit1);
change1.setEdit(rootEdit1);
result.add(change1);
}
}
// create change for artifactId
String oldName2 = editHelper
.getNodeValue(DeploymentPlanTextNode.ARTIFACT_ID);
int offset2 = editHelper
.getNodeOffset(DeploymentPlanTextNode.ARTIFACT_ID);
if (offset2 != -1 && oldName2 != null && oldName2.equals(oldName)) {
MovedTextFileChange change2 = new MovedTextFileChange(
"Rename context-root's value", newFile,
deploymentPlanFile);
MultiTextEdit rootEdit2 = new MultiTextEdit();
ReplaceEdit edit2 = new ReplaceEdit(offset2, oldName2.length(),
newName);
rootEdit2.addChild(edit2);
change2.setEdit(rootEdit2);
result.add(change2);
}
} finally {
pm.done();
}
if (result.getChildren().length == 0)
return null;
return result;
}