blob: 6df2cbae7dd2ccfd7f8f8da07051f6e192e48744 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ltk.internal.ui.refactoring;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.operation.IRunnableWithProgress;
/**
* An <code>IRunnableWithProgress</code> that adapts and <code>IWorkspaceRunnable</code>
* so that is can be executed inside <code>IRunnableContext</code>. <code>OperationCanceledException</code>
* thrown by the adapted runnable are caught and re-thrown as a <code>InterruptedException</code>.
*/
public class WorkbenchRunnableAdapter implements IRunnableWithProgress {
private IWorkspaceRunnable fWorkspaceRunnable;
private ISchedulingRule fRule;
/**
* Runs a workspace runnable with the given lock or <code>null</code> to run with no lock at all.
*
* @param runnable the workspace runnable
* @param rule the scheduling rule
*/
public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable, ISchedulingRule rule) {
Assert.isNotNull(runnable);
Assert.isNotNull(rule);
fWorkspaceRunnable= runnable;
fRule= rule;
}
public ISchedulingRule getSchedulingRule() {
return fRule;
}
/*
* @see IRunnableWithProgress#run(IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
ResourcesPlugin.getWorkspace().run(fWorkspaceRunnable, fRule, IWorkspace.AVOID_UPDATE, monitor);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
}