diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/WorkbenchRunnableAdapter.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/WorkbenchRunnableAdapter.java
index 2b9b4e7b3d9..8345d6a4059 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/WorkbenchRunnableAdapter.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/WorkbenchRunnableAdapter.java
@@ -1,38 +1,58 @@
/*******************************************************************************
- * Copyright (c) 2001 Rational Software Corp. and others.
+ * 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 v0.5
+ * 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-v05.html
+ * http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
- * Rational Software - initial implementation
- ******************************************************************************/
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
import java.lang.reflect.InvocationTargetException;
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.internal.ui.CUIStatus;
import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.cdt.core.model.CoreModel;
-
/**
* An IRunnableWithProgress
that adapts and IWorkspaceRunnable
* so that is can be executed inside IRunnableContext
. OperationCanceledException
- * thrown by the apapted runnabled are cought and rethrown as a InterruptedException
.
+ * thrown by the adapted runnable are caught and re-thrown as a InterruptedException
.
*/
-
public class WorkbenchRunnableAdapter implements IRunnableWithProgress {
private IWorkspaceRunnable fWorkspaceRunnable;
+ private ISchedulingRule fRule;
+ /**
+ * Runs a workspace runnable with the workspace lock.
+ */
public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable) {
+ this(runnable, ResourcesPlugin.getWorkspace().getRoot());
+ }
+
+ /**
+ * Runs a workspace runnable with the given lock or null
to run with no lock at all.
+ */
+ public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable, ISchedulingRule rule) {
fWorkspaceRunnable= runnable;
+ fRule= rule;
+ }
+
+ public ISchedulingRule getSchedulingRule() {
+ return fRule;
}
/*
@@ -40,13 +60,45 @@ public class WorkbenchRunnableAdapter implements IRunnableWithProgress {
*/
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
- CoreModel.run(fWorkspaceRunnable, monitor);
+ CoreModel.run(fWorkspaceRunnable, fRule, monitor);
} catch (OperationCanceledException e) {
throw new InterruptedException(e.getMessage());
} catch (CoreException e) {
throw new InvocationTargetException(e);
}
}
-
+
+ public void runAsUserJob(String name, final Object jobFamiliy) {
+ Job buildJob = new Job(name){
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ WorkbenchRunnableAdapter.this.run(monitor);
+ } catch (InvocationTargetException e) {
+ Throwable cause= e.getCause();
+ if (cause instanceof CoreException) {
+ return ((CoreException) cause).getStatus();
+ } else {
+ return CUIStatus.createError(IStatus.ERROR, cause);
+ }
+ } catch (InterruptedException e) {
+ return Status.CANCEL_STATUS;
+ } finally {
+ monitor.done();
+ }
+ return Status.OK_STATUS;
+ }
+ public boolean belongsTo(Object family) {
+ return jobFamiliy == family;
+ }
+ };
+ buildJob.setRule(fRule);
+ buildJob.setUser(true);
+ buildJob.schedule();
+
+ // TODO: should block until user pressed 'to background'
+ }
}