1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.core.runtime.OperationCanceledException; 19 import org.eclipse.core.runtime.jobs.ISchedulingRule; 20 import org.eclipse.core.runtime.jobs.Job; 21 22 import org.eclipse.core.resources.IWorkspace; 23 import org.eclipse.core.resources.IWorkspaceRunnable; 24 import org.eclipse.core.resources.ResourcesPlugin; 25 26 import org.eclipse.jface.operation.IRunnableWithProgress; 27 import org.eclipse.jface.operation.IThreadListener; 28 29 34 public class WorkbenchRunnableAdapter implements IRunnableWithProgress, IThreadListener { 35 36 private IWorkspaceRunnable fWorkspaceRunnable; 37 private ISchedulingRule fRule; 38 private boolean fTransfer; 39 40 47 public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable, ISchedulingRule rule) { 48 this(runnable, rule, true); 49 } 50 51 62 public WorkbenchRunnableAdapter(IWorkspaceRunnable runnable, ISchedulingRule rule, boolean transfer) { 63 Assert.isNotNull(runnable); 64 Assert.isNotNull(rule); 65 fWorkspaceRunnable= runnable; 66 fRule= rule; 67 fTransfer= transfer; 68 } 69 70 public ISchedulingRule getSchedulingRule() { 71 return fRule; 72 } 73 74 77 public void threadChange(Thread thread) { 78 if (fTransfer) 79 Job.getJobManager().transferRule(fRule, thread); 80 } 81 82 85 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 86 try { 87 ResourcesPlugin.getWorkspace().run(fWorkspaceRunnable, fRule, IWorkspace.AVOID_UPDATE, monitor); 88 } catch (OperationCanceledException e) { 89 throw new InterruptedException (e.getMessage()); 90 } catch (CoreException e) { 91 throw new InvocationTargetException (e); 92 } 93 } 94 } 95 96 | Popular Tags |