Search in sources :

Example 66 with SubProgressMonitor

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();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) NullChange(org.eclipse.ltk.core.refactoring.NullChange) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 67 with SubProgressMonitor

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IFolder(org.eclipse.core.resources.IFolder)

Example 68 with SubProgressMonitor

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();
    }
}
Also used : IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 69 with SubProgressMonitor

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) Entry(java.util.Map.Entry) IJavaProject(org.eclipse.jdt.core.IJavaProject) NullChange(org.eclipse.ltk.core.refactoring.NullChange) ResourceDescription(org.eclipse.ui.ide.undo.ResourceDescription) ReplaceEdit(org.eclipse.text.edits.ReplaceEdit) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource)

Example 70 with SubProgressMonitor

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();
    }
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)217 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)54 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 CoreException (org.eclipse.core.runtime.CoreException)40 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 ArrayList (java.util.ArrayList)36 IFile (org.eclipse.core.resources.IFile)33 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)31 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)30 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IPath (org.eclipse.core.runtime.IPath)17 IResource (org.eclipse.core.resources.IResource)16 IProject (org.eclipse.core.resources.IProject)15 File (java.io.File)14 List (java.util.List)13 IMethod (org.eclipse.jdt.core.IMethod)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 HashMap (java.util.HashMap)12