Search in sources :

Example 61 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class RenamePackageChange method doRename.

@Override
protected void doRename(IProgressMonitor pm) throws CoreException {
    IPackageFragment pack = getPackage();
    if (pack == null)
        return;
    if (!fRenameSubpackages) {
        renamePackage(pack, pm, createNewPath(), getNewName());
    } else {
        IPackageFragment[] allPackages = JavaElementUtil.getPackageAndSubpackages(pack);
        Arrays.sort(allPackages, new Comparator<IPackageFragment>() {

            public int compare(IPackageFragment o1, IPackageFragment o2) {
                String p1 = o1.getElementName();
                String p2 = o2.getElementName();
                return p1.compareTo(p2);
            }
        });
        int count = allPackages.length;
        //$NON-NLS-1$
        pm.beginTask("", count);
        // When renaming to subpackage (a -> a.b), do it inside-out:
        boolean insideOut = getNewName().startsWith(getOldName());
        try {
            for (int i = 0; i < count; i++) {
                IPackageFragment currentPackage = allPackages[insideOut ? count - i - 1 : i];
                renamePackage(currentPackage, new SubProgressMonitor(pm, 1), createNewPath(currentPackage), getNewName(currentPackage));
            }
        } finally {
            pm.done();
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 62 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class UndoDeleteResourceChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    IResource created = fResourceDescription.createResource(pm);
    created.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(pm, 1));
    return new DeleteResourceChange(created.getFullPath(), true);
}
Also used : DeleteResourceChange(org.eclipse.ltk.core.refactoring.resource.DeleteResourceChange) IResource(org.eclipse.core.resources.IResource) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 63 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class PackageFragmentRootReorgChange method perform.

@Override
public final Change perform(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    pm.beginTask(getName(), 2);
    try {
        String newName = getNewResourceName();
        IPackageFragmentRoot root = getRoot();
        ResourceMapping mapping = JavaElementResourceMapping.create(root);
        final Change result = doPerformReorg(getDestinationProjectPath().append(newName), new SubProgressMonitor(pm, 1));
        markAsExecuted(root, mapping);
        return result;
    } finally {
        pm.done();
    }
}
Also used : JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) ResourceChange(org.eclipse.ltk.core.refactoring.resource.ResourceChange) Change(org.eclipse.ltk.core.refactoring.Change) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 64 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class RenameJavaProjectChange method doRename.

@Override
protected void doRename(IProgressMonitor pm) throws CoreException {
    try {
        pm.beginTask(getName(), 2);
        if (fUpdateReferences)
            modifyClassPaths(new SubProgressMonitor(pm, 1));
        IProject project = getProject();
        if (project != null) {
            IProjectDescription description = project.getDescription();
            description.setName(getNewName());
            project.move(description, IResource.FORCE | IResource.SHALLOW, new SubProgressMonitor(pm, 1));
        }
    } finally {
        pm.done();
    }
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProject(org.eclipse.core.resources.IProject)

Example 65 with SubProgressMonitor

use of org.eclipse.core.runtime.SubProgressMonitor in project che by eclipse.

the class AbstractDeleteChange method saveFileIfNeeded.

protected static void saveFileIfNeeded(IFile file, IProgressMonitor pm) throws CoreException {
    ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
    if (buffer != null && buffer.isDirty() && buffer.isStateValidated() && buffer.isSynchronized()) {
        //$NON-NLS-1$
        pm.beginTask("", 2);
        buffer.commit(new SubProgressMonitor(pm, 1), false);
        file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
    }
    pm.done();
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) 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