1 11 12 package org.eclipse.ui.internal.editors.text; 13 14 import java.lang.reflect.InvocationTargetException ; 15 16 import org.eclipse.core.resources.ResourcesPlugin; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.NullProgressMonitor; 19 import org.eclipse.core.runtime.jobs.ISchedulingRule; 20 21 import org.eclipse.jface.operation.IRunnableContext; 22 import org.eclipse.jface.operation.IRunnableWithProgress; 23 24 import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; 25 import org.eclipse.ui.texteditor.ISchedulingRuleProvider; 26 27 30 public class WorkspaceOperationRunner implements IRunnableContext { 31 32 private IProgressMonitor fProgressMonitor; 33 34 public WorkspaceOperationRunner() { 35 } 36 37 42 public void setProgressMonitor(IProgressMonitor progressMonitor) { 43 fProgressMonitor= progressMonitor; 44 } 45 46 52 public IProgressMonitor getProgressMonitor() { 53 if (fProgressMonitor == null) 54 fProgressMonitor= new NullProgressMonitor(); 55 return fProgressMonitor; 56 } 57 58 61 public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException , InterruptedException { 62 if (runnable instanceof ISchedulingRuleProvider) 63 run(fork, cancelable, runnable, ((ISchedulingRuleProvider)runnable).getSchedulingRule()); 64 else 65 run(fork, cancelable, runnable, ResourcesPlugin.getWorkspace().getRoot()); 66 } 67 68 71 public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable, ISchedulingRule schedulingRule) throws InvocationTargetException , InterruptedException { 72 WorkspaceModifyDelegatingOperation operation= new WorkspaceModifyDelegatingOperation(runnable, schedulingRule); 73 operation.run(getProgressMonitor()); 74 } 75 } 76 | Popular Tags |