use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class ClasspathChange method perform.
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
pm.beginTask(RefactoringCoreMessages.ClasspathChange_progress_message, 1);
try {
if (!JavaConventions.validateClasspath(fProject, fNewClasspath, fOutputLocation).matches(IStatus.ERROR)) {
IClasspathEntry[] oldClasspath = fProject.getRawClasspath();
IPath oldOutputLocation = fProject.getOutputLocation();
fProject.setRawClasspath(fNewClasspath, fOutputLocation, new SubProgressMonitor(pm, 1));
return new ClasspathChange(fProject, oldClasspath, oldOutputLocation);
} else {
return new NullChange();
}
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class CopyResourceChange method deleteIfAlreadyExists.
/**
* returns false if source and destination are the same (in workspace or on disk)
* in such case, no action should be performed
* @param pm the progress monitor
* @param newName the new name
* @return returns <code>true</code> if the resource already exists
* @throws CoreException thrown when teh resource cannpt be accessed
*/
private boolean deleteIfAlreadyExists(IProgressMonitor pm, String newName) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
IResource current = getDestination().findMember(newName);
if (current == null)
return true;
if (!current.exists())
return true;
IResource resource = getResource();
Assert.isNotNull(resource);
if (ReorgUtils.areEqualInWorkspaceOrOnDisk(resource, current))
return false;
if (current instanceof IFile)
((IFile) current).delete(false, true, new SubProgressMonitor(pm, 1));
else if (current instanceof IFolder)
((IFolder) current).delete(false, true, new SubProgressMonitor(pm, 1));
else
Assert.isTrue(false);
return true;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class CopyResourceChange method perform.
/* non java-doc
* @see IChange#perform(ChangeContext, IProgressMonitor)
*/
@Override
public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
try {
pm.beginTask(getName(), 2);
String newName = getNewResourceName();
IResource resource = getResource();
boolean performReorg = deleteIfAlreadyExists(new SubProgressMonitor(pm, 1), newName);
if (!performReorg)
return null;
getResource().copy(getDestinationPath(newName), getReorgFlags(), new SubProgressMonitor(pm, 1));
markAsExecuted(resource);
return null;
} finally {
pm.done();
}
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class DeletePackageFragmentRootChange method doDelete.
@Override
protected Change doDelete(IProgressMonitor pm) throws CoreException {
if (!confirmDeleteIfReferenced())
return new NullChange();
int resourceUpdateFlags = IResource.KEEP_HISTORY;
int jCoreUpdateFlags = IPackageFragmentRoot.ORIGINATING_PROJECT_CLASSPATH | IPackageFragmentRoot.OTHER_REFERRING_PROJECTS_CLASSPATH;
//$NON-NLS-1$
pm.beginTask("", 2);
IPackageFragmentRoot root = getRoot();
IResource rootResource = root.getResource();
CompositeChange result = new CompositeChange(getName());
ResourceDescription rootDescription = ResourceDescription.fromResource(rootResource);
IJavaProject[] referencingProjects = JavaElementUtil.getReferencingProjects(root);
HashMap<IFile, String> classpathFilesContents = new HashMap<IFile, String>();
for (int i = 0; i < referencingProjects.length; i++) {
IJavaProject javaProject = referencingProjects[i];
//$NON-NLS-1$
IFile classpathFile = javaProject.getProject().getFile(".classpath");
if (classpathFile.exists()) {
classpathFilesContents.put(classpathFile, getFileContents(classpathFile));
}
}
root.delete(resourceUpdateFlags, jCoreUpdateFlags, new SubProgressMonitor(pm, 1));
rootDescription.recordStateFromHistory(rootResource, new SubProgressMonitor(pm, 1));
for (Iterator<Entry<IFile, String>> iterator = classpathFilesContents.entrySet().iterator(); iterator.hasNext(); ) {
Entry<IFile, String> entry = iterator.next();
IFile file = entry.getKey();
String contents = entry.getValue();
//Restore time stamps? This should probably be some sort of UndoTextFileChange.
TextFileChange classpathUndo = new TextFileChange(Messages.format(RefactoringCoreMessages.DeletePackageFragmentRootChange_restore_file, BasicElementLabels.getPathLabel(file.getFullPath(), true)), file);
classpathUndo.setEdit(new ReplaceEdit(0, getFileLength(file), contents));
result.add(classpathUndo);
}
result.add(new UndoDeleteResourceChange(rootDescription));
pm.done();
return result;
}
use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.
the class ExtractConstantRefactoring method checkFinalConditions.
@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException {
pm.beginTask(RefactoringCoreMessages.ExtractConstantRefactoring_checking_preconditions, 2);
try {
RefactoringStatus result = new RefactoringStatus();
createConstantDeclaration();
replaceExpressionsWithConstant();
fChange = fCuRewrite.createChange(RefactoringCoreMessages.ExtractConstantRefactoring_change_name, true, new SubProgressMonitor(pm, 1));
if (fCheckResultForCompileProblems) {
checkSource(new SubProgressMonitor(pm, 1), result);
}
return result;
} finally {
fConstantTypeCache = null;
fCuRewrite.clearASTAndImportRewrites();
pm.done();
}
}
Aggregations