Search in sources :

Example 1 with NotCancelableProgressMonitor

use of org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor in project che by eclipse.

the class PerformChangeOperation method executeChange.

/**
	 * Actually executes the change.
	 *
	 * @param pm a progress monitor to report progress
	 *
	 * @throws CoreException if an unexpected error occurs during
	 *  change execution
	 */
protected void executeChange(IProgressMonitor pm) throws CoreException {
    fChangeExecuted = false;
    if (!fChange.isEnabled())
        return;
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(IProgressMonitor monitor) throws CoreException {
            boolean undoInitialized = false;
            try {
                //$NON-NLS-1$
                monitor.beginTask("", 10);
                fValidationStatus = fChange.isValid(new SubProgressMonitor(monitor, 1));
                if (fValidationStatus.hasFatalError())
                    return;
                boolean aboutToPerformChangeCalled = false;
                try {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        fUndoManager.aboutToPerformChange(fChange);
                        aboutToPerformChangeCalled = true;
                    }
                    fChangeExecutionFailed = true;
                    fUndoChange = fChange.perform(new SubProgressMonitor(monitor, 9));
                    fChangeExecutionFailed = false;
                    fChangeExecuted = true;
                } finally {
                    if (fUndoManager != null) {
                        ResourcesPlugin.getWorkspace().checkpoint(false);
                        if (aboutToPerformChangeCalled)
                            fUndoManager.changePerformed(fChange, !fChangeExecutionFailed);
                    }
                }
                fChange.dispose();
                if (fUndoChange != null) {
                    fUndoChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(monitor, 1)));
                    undoInitialized = true;
                }
                if (fUndoManager != null) {
                    if (fUndoChange != null) {
                        fUndoManager.addUndo(fUndoName, fUndoChange);
                    } else {
                        fUndoManager.flush();
                    }
                }
            } catch (CoreException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } catch (RuntimeException e) {
                if (fUndoManager != null)
                    fUndoManager.flush();
                if (fUndoChange != null && undoInitialized) {
                    Change ch = fUndoChange;
                    fUndoChange = null;
                    ch.dispose();
                }
                fUndoChange = null;
                throw e;
            } finally {
                monitor.done();
            }
        }
    };
    ResourcesPlugin.getWorkspace().run(runnable, fSchedulingRule, IWorkspace.AVOID_UPDATE, pm);
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with NotCancelableProgressMonitor

use of org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor in project che by eclipse.

the class CreateChangeOperation method run.

/**
	 * {@inheritDoc}
	 */
public void run(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    fChange = null;
    try {
        fChange = null;
        RefactoringTickProvider rtp = fRefactoring.getRefactoringTickProvider();
        if (fCheckConditionOperation != null) {
            int conditionTicks = fCheckConditionOperation.getTicks(rtp);
            int allTicks = conditionTicks + rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks();
            //$NON-NLS-1$
            pm.beginTask("", allTicks);
            //$NON-NLS-1$
            pm.subTask("");
            fCheckConditionOperation.run(new SubProgressMonitor(pm, conditionTicks));
            RefactoringStatus status = fCheckConditionOperation.getStatus();
            if (status != null && status.getSeverity() < fConditionCheckingFailedSeverity) {
                fChange = fRefactoring.createChange(new SubProgressMonitor(pm, rtp.getCreateChangeTicks()));
                fChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(pm, rtp.getInitializeChangeTicks())));
            } else {
                pm.worked(rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks());
            }
        } else {
            //$NON-NLS-1$
            pm.beginTask("", rtp.getCreateChangeTicks() + rtp.getInitializeChangeTicks());
            fChange = fRefactoring.createChange(new SubProgressMonitor(pm, rtp.getCreateChangeTicks()));
            fChange.initializeValidationData(new NotCancelableProgressMonitor(new SubProgressMonitor(pm, rtp.getInitializeChangeTicks())));
        }
    } finally {
        pm.done();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) NotCancelableProgressMonitor(org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Aggregations

SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 NotCancelableProgressMonitor (org.eclipse.ltk.internal.core.refactoring.NotCancelableProgressMonitor)2 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1