Search in sources :

Example 71 with OperationCanceledException

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

the class Refactoring method checkAllConditions.

/**
	 * Checks all conditions. This implementation calls <code>checkInitialConditions</code>
	 * and <code>checkFinalConditions</code>.
	 * <p>
	 * Subclasses may extend this method to provide additional condition checks.
	 * </p>
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @return a refactoring status. If the status is <code>RefactoringStatus#FATAL</code>
	 *  the refactoring has to be considered as not being executable.
	 *
	 * @throws CoreException if an exception occurred during condition checking.
	 *  If this happens then the condition checking has to be interpreted as failed
	 *
	 * @throws OperationCanceledException if the condition checking got canceled
	 *
	 * @see #checkInitialConditions(IProgressMonitor)
	 * @see #checkFinalConditions(IProgressMonitor)
	 */
public RefactoringStatus checkAllConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    RefactoringTickProvider refactoringTickProvider = getRefactoringTickProvider();
    //$NON-NLS-1$
    pm.beginTask("", refactoringTickProvider.getCheckAllConditionsTicks());
    RefactoringStatus result = new RefactoringStatus();
    result.merge(checkInitialConditions(new SubProgressMonitor(pm, refactoringTickProvider.getCheckInitialConditionsTicks())));
    if (!result.hasFatalError()) {
        if (pm.isCanceled())
            throw new OperationCanceledException();
        result.merge(checkFinalConditions(new SubProgressMonitor(pm, refactoringTickProvider.getCheckFinalConditionsTicks())));
    }
    pm.done();
    return result;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 72 with OperationCanceledException

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

the class CompositeChange method isValid.

/**
	 * {@inheritDoc}
	 * <p>
	 * The composite change sends <code>isValid</code> to all its children
	 * until the first one returns a status with a severity of <code>FATAL
	 * </code>. If one of the children throws an exception the remaining children
	 * will not receive the <code>isValid</code> call.
	 * </p>
	 * <p>
	 * Client are allowed to extend this method.
	 * </p>
	 */
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
    RefactoringStatus result = new RefactoringStatus();
    //$NON-NLS-1$
    pm.beginTask("", fChanges.size());
    for (Iterator iter = fChanges.iterator(); iter.hasNext() && !result.hasFatalError(); ) {
        Change change = (Change) iter.next();
        if (change.isEnabled())
            result.merge(change.isValid(new SubProgressMonitor(pm, 1)));
        else
            pm.worked(1);
        if (pm.isCanceled())
            throw new OperationCanceledException();
    }
    pm.done();
    return result;
}
Also used : OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) Iterator(java.util.Iterator) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 73 with OperationCanceledException

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

the class CompositeChange method perform.

/**
	 * {@inheritDoc}
	 * <p>
	 * The composite change sends <code>perform</code> to all its <em>enabled</em>
	 * children. If one of the children throws an exception the remaining children
	 * will not receive the <code>perform</code> call. In this case the method <code>
	 * getUndoUntilException</code> can be used to get an undo object containing the
	 * undo objects of all executed children.
	 * </p>
	 * <p>
	 * Client are allowed to extend this method.
	 * </p>
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    fUndoUntilException = null;
    List undos = new ArrayList(fChanges.size());
    //$NON-NLS-1$
    pm.beginTask("", fChanges.size());
    pm.setTaskName(RefactoringCoreMessages.CompositeChange_performingChangesTask_name);
    Change change = null;
    boolean canceled = false;
    try {
        for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) {
            change = (Change) iter.next();
            if (canceled && !internalProcessOnCancel(change))
                continue;
            if (change.isEnabled()) {
                Change undoChange = null;
                try {
                    undoChange = change.perform(new SubProgressMonitor(pm, 1));
                } catch (OperationCanceledException e) {
                    canceled = true;
                    if (!internalContinueOnCancel())
                        throw e;
                    undos = null;
                }
                if (undos != null) {
                    if (undoChange == null) {
                        undos = null;
                    } else {
                        undos.add(undoChange);
                    }
                }
            }
            // remove the change from the list of children to give
            // the garbage collector the change to collect the change. This
            // ensures that the memory consumption doesn't go up when
            // producing the undo change tree.
            iter.remove();
            // Make sure we dispose the change since it will now longer be
            // in the list of children when call CompositeChange#dispose()
            final Change changeToDispose = change;
            SafeRunner.run(new ISafeRunnable() {

                public void run() throws Exception {
                    changeToDispose.dispose();
                }

                public void handleException(Throwable exception) {
                    RefactoringCorePlugin.log(exception);
                }
            });
        }
        if (canceled)
            throw new OperationCanceledException();
        if (undos != null) {
            Collections.reverse(undos);
            return createUndoChange((Change[]) undos.toArray(new Change[undos.size()]));
        } else {
            return null;
        }
    } catch (CoreException e) {
        handleUndos(change, undos);
        internalHandleException(change, e);
        throw e;
    } catch (RuntimeException e) {
        handleUndos(change, undos);
        internalHandleException(change, e);
        throw e;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ArrayList(java.util.ArrayList) List(java.util.List) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException)

Example 74 with OperationCanceledException

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

the class TextMatchUpdater method addTextMatches.

private void addTextMatches(IResource resource, IProgressMonitor pm) throws JavaModelException {
    try {
        String task = RefactoringCoreMessages.TextMatchUpdater_searching + resource.getFullPath();
        if (resource instanceof IFile) {
            IJavaElement element = JavaCore.create(resource);
            // don't start pm task (flickering label updates; finally {pm.done()} is enough)
            if (!(element instanceof ICompilationUnit))
                return;
            if (!element.exists())
                return;
            if (!fScope.encloses(element))
                return;
            addCuTextMatches((ICompilationUnit) element);
        } else if (resource instanceof IContainer) {
            IResource[] members = ((IContainer) resource).members();
            pm.beginTask(task, members.length);
            pm.subTask(task);
            for (int i = 0; i < members.length; i++) {
                if (pm.isCanceled())
                    throw new OperationCanceledException();
                addTextMatches(members[i], new SubProgressMonitor(pm, 1));
            }
        }
    } catch (JavaModelException e) {
        throw e;
    } catch (CoreException e) {
        throw new JavaModelException(e);
    } finally {
        pm.done();
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IContainer(org.eclipse.core.resources.IContainer) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 75 with OperationCanceledException

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

the class RefactoringExecutionHelper method perform.

/**
	 * Must be called in the UI thread.<br>
	 * <strong>Use {@link #perform(boolean, boolean)} unless you know exactly what you are doing!</strong>
	 *
	 * @param fork if set, the operation will be forked
	 * @param forkChangeExecution if the change should not be executed in the UI thread: This may not work in any case
	 * @param cancelable  if set, the operation will be cancelable
	 * @throws InterruptedException thrown when the operation is cancelled
	 * @throws InvocationTargetException thrown when the operation failed to execute
	 */
public RefactoringStatus perform(boolean fork, boolean forkChangeExecution, boolean cancelable) throws InterruptedException, InvocationTargetException, CoreException {
    //		Assert.isTrue(Display.getCurrent() != null);
    final IJobManager manager = Job.getJobManager();
    final ISchedulingRule rule;
    if (fRefactoring instanceof IScheduledRefactoring) {
        rule = ((IScheduledRefactoring) fRefactoring).getSchedulingRule();
    } else {
        rule = ResourcesPlugin.getWorkspace().getRoot();
    }
    Operation op = null;
    try {
        try {
            op = new Operation(fork, forkChangeExecution);
            op.run(new NullProgressMonitor());
            fPerformChangeOperation = op.fPerformChangeOperation;
            //			fRefactoring.setValidationContext(fParent);
            if (op.fPerformChangeOperation != null) {
                ResourcesPlugin.getWorkspace().run(op.fPerformChangeOperation, new NullProgressMonitor());
            }
            if (op.fPerformChangeOperation != null) {
                RefactoringStatus validationStatus = op.fPerformChangeOperation.getValidationStatus();
                if (validationStatus != null) /*&& validationStatus.hasFatalError()*/
                {
                    //						throw new InterruptedException();
                    return validationStatus;
                }
            }
        } catch (OperationCanceledException e) {
            if (op != null) {
                if (op.allConditions != null) {
                    return op.allConditions;
                }
            }
            throw new InterruptedException(e.getMessage());
        } finally {
        //				saveHelper.triggerIncrementalBuild();
        }
    } finally {
        //			manager.endRule(rule);
        fRefactoring.setValidationContext(null);
    }
    return new RefactoringStatus();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IJobManager(org.eclipse.core.runtime.jobs.IJobManager) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Aggregations

OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)134 CoreException (org.eclipse.core.runtime.CoreException)38 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)34 ArrayList (java.util.ArrayList)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 IOException (java.io.IOException)21 IFile (org.eclipse.core.resources.IFile)21 IStatus (org.eclipse.core.runtime.IStatus)21 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 Status (org.eclipse.core.runtime.Status)16 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)16 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)16 File (java.io.File)15 SubMonitor (org.eclipse.core.runtime.SubMonitor)10 Job (org.eclipse.core.runtime.jobs.Job)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)9 IProject (org.eclipse.core.resources.IProject)8 HashSet (java.util.HashSet)7 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)7