Search in sources :

Example 11 with SubProgressMonitor

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

the class RenameFieldProcessor method doCheckFinalConditions.

@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 18);
        pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_checking);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(Checks.checkIfCuBroken(fField));
        if (result.hasFatalError())
            return result;
        result.merge(checkNewElementName(getNewElementName()));
        pm.worked(1);
        result.merge(checkEnclosingHierarchy());
        pm.worked(1);
        result.merge(checkNestedHierarchy(fField.getDeclaringType()));
        pm.worked(1);
        if (fUpdateReferences) {
            pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_searching);
            fReferences = getReferences(new SubProgressMonitor(pm, 3), result);
            pm.setTaskName(RefactoringCoreMessages.RenameFieldRefactoring_checking);
        } else {
            fReferences = new SearchResultGroup[0];
            pm.worked(3);
        }
        if (fUpdateReferences)
            result.merge(analyzeAffectedCompilationUnits());
        else
            Checks.checkCompileErrorsInAffectedFile(result, fField.getResource());
        if (getGetter() != null && fRenameGetter) {
            result.merge(checkAccessor(new SubProgressMonitor(pm, 1), getGetter(), getNewGetterName()));
            result.merge(Checks.checkIfConstructorName(getGetter(), getNewGetterName(), fField.getDeclaringType().getElementName()));
        } else {
            pm.worked(1);
        }
        if (getSetter() != null && fRenameSetter) {
            result.merge(checkAccessor(new SubProgressMonitor(pm, 1), getSetter(), getNewSetterName()));
            result.merge(Checks.checkIfConstructorName(getSetter(), getNewSetterName(), fField.getDeclaringType().getElementName()));
        } else {
            pm.worked(1);
        }
        result.merge(createChanges(new SubProgressMonitor(pm, 10)));
        if (result.hasFatalError())
            return result;
        return result;
    } finally {
        pm.done();
    }
}
Also used : RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 12 with SubProgressMonitor

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

the class RenameNonVirtualMethodProcessor method doCheckFinalConditions.

//----------- preconditions --------------
@Override
protected RefactoringStatus doCheckFinalConditions(IProgressMonitor pm, CheckConditionsContext checkContext) throws CoreException {
    try {
        //$NON-NLS-1$
        pm.beginTask("", 3);
        RefactoringStatus result = new RefactoringStatus();
        result.merge(super.doCheckFinalConditions(new SubProgressMonitor(pm, 1), checkContext));
        if (result.hasFatalError())
            return result;
        final IMethod method = getMethod();
        final IType declaring = method.getDeclaringType();
        final String name = getNewElementName();
        IMethod[] hierarchyMethods = hierarchyDeclaresMethodName(new SubProgressMonitor(pm, 1), declaring.newTypeHierarchy(new SubProgressMonitor(pm, 1)), method, name);
        for (int i = 0; i < hierarchyMethods.length; i++) {
            IMethod hierarchyMethod = hierarchyMethods[i];
            RefactoringStatusContext context = JavaStatusContext.create(hierarchyMethod);
            if (Checks.compareParamTypes(method.getParameterTypes(), hierarchyMethod.getParameterTypes())) {
                String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
                result.addError(message, context);
            } else {
                String message = Messages.format(RefactoringCoreMessages.RenamePrivateMethodRefactoring_hierarchy_defines2, new String[] { BasicElementLabels.getJavaElementName(declaring.getFullyQualifiedName('.')), BasicElementLabels.getJavaElementName(name) });
                result.addWarning(message, context);
            }
        }
        return result;
    } finally {
        pm.done();
    }
}
Also used : RefactoringStatusContext(org.eclipse.ltk.core.refactoring.RefactoringStatusContext) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IMethod(org.eclipse.jdt.core.IMethod) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IType(org.eclipse.jdt.core.IType)

Example 13 with SubProgressMonitor

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

the class ImportOperation method execute.

/* (non-Javadoc)
     * Method declared on WorkbenchModifyOperation.
     * Imports the specified file system objects from the file system.
     */
protected void execute(IProgressMonitor progressMonitor) {
    monitor = progressMonitor;
    try {
        if (selectedFiles == null) {
            //Set the amount to 1000 as we have no idea of how long this will take
            monitor.beginTask("Importing:", 1000);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(Arrays.asList(new Object[] { source }));
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importRecursivelyFrom(source, POLICY_DEFAULT);
            //Be sure it finishes
            monitor.worked(90);
        } else {
            // Choose twice the selected files size to take folders into account
            int creationCount = selectedFiles.size();
            monitor.beginTask("Importing:", creationCount + 100);
            ContainerGenerator generator = new ContainerGenerator(destinationPath);
            monitor.worked(30);
            validateFiles(selectedFiles);
            monitor.worked(50);
            destinationContainer = generator.generateContainer(new SubProgressMonitor(monitor, 50));
            importFileSystemObjects(selectedFiles);
            monitor.done();
        }
    } catch (CoreException e) {
        errorTable.add(e.getStatus());
    } finally {
        monitor.done();
    }
}
Also used : ContainerGenerator(org.eclipse.ui.dialogs.ContainerGenerator) CoreException(org.eclipse.core.runtime.CoreException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 14 with SubProgressMonitor

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

the class ContainerGenerator method createProject.

/**
     * Creates a project resource for the given project handle.
     *
     * @param projectHandle the handle to create a project resource
     * @param monitor the progress monitor to show visual progress
     * @return the project handle (<code>projectHandle</code>)
     * @exception CoreException if the operation fails
     * @exception OperationCanceledException if the operation is canceled
     */
private IProject createProject(IProject projectHandle, IProgressMonitor monitor) throws CoreException {
    try {
        //$NON-NLS-1$
        monitor.beginTask("", 2000);
        projectHandle.create(new SubProgressMonitor(monitor, 1000));
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
        projectHandle.open(new SubProgressMonitor(monitor, 1000));
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    } finally {
        monitor.done();
    }
    return projectHandle;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 15 with SubProgressMonitor

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

the class ContainerDescription method recordStateFromHistory.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.internal.ide.undo.ResourceDescription#recordStateFromHistory(org.eclipse.core.resources.IResource,
	 *      org.eclipse.core.runtime.IProgressMonitor)
	 */
public void recordStateFromHistory(IResource resource, IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(UndoMessages.FolderDescription_SavingUndoInfoProgress, 100);
    if (members != null) {
        for (int i = 0; i < members.length; i++) {
            if (members[i] instanceof FileDescription) {
                IPath path = resource.getFullPath().append(((FileDescription) members[i]).name);
                IFile fileHandle = resource.getWorkspace().getRoot().getFile(path);
                members[i].recordStateFromHistory(fileHandle, new SubProgressMonitor(monitor, 100 / members.length));
            } else if (members[i] instanceof FolderDescription) {
                IPath path = resource.getFullPath().append(((FolderDescription) members[i]).name);
                IFolder folderHandle = resource.getWorkspace().getRoot().getFolder(path);
                members[i].recordStateFromHistory(folderHandle, new SubProgressMonitor(monitor, 100 / members.length));
            }
        }
    }
    monitor.done();
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)213 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)53 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)53 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)39 CoreException (org.eclipse.core.runtime.CoreException)38 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)29 IOException (java.io.IOException)23 IType (org.eclipse.jdt.core.IType)19 HashSet (java.util.HashSet)17 IProject (org.eclipse.core.resources.IProject)14 IResource (org.eclipse.core.resources.IResource)14 File (java.io.File)13 List (java.util.List)13 IPath (org.eclipse.core.runtime.IPath)13 IMethod (org.eclipse.jdt.core.IMethod)13 HashMap (java.util.HashMap)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)11