1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.lang.reflect.InvocationTargetException ; 14 15 import org.eclipse.jface.dialogs.ProgressMonitorDialog; 16 import org.eclipse.jface.operation.IRunnableWithProgress; 17 import org.eclipse.jface.operation.ModalContext; 18 import org.eclipse.swt.custom.BusyIndicator; 19 import org.eclipse.swt.widgets.Display; 20 import org.eclipse.swt.widgets.Shell; 21 22 public class TimeoutProgressMonitorDialog extends ProgressMonitorDialog { 23 private int timeout; 25 private int runningRunnables = 0; 27 28 36 public TimeoutProgressMonitorDialog(Shell parent, int timeout) { 37 super(parent); 38 this.timeout = timeout; 39 } 40 41 46 public void run(final boolean fork, boolean cancelable, final IRunnableWithProgress runnable) throws InvocationTargetException , InterruptedException { 47 setCancelable(cancelable); 48 create(); try { 50 runningRunnables++; 51 final Display display = getShell().getDisplay(); 52 display.timerExec(timeout, new Runnable () { 53 public void run() { 54 Shell shell = getShell(); 55 if (shell != null && ! shell.isDisposed()) open(); 56 } 57 }); 58 59 final Exception [] holder = new Exception [1]; 60 BusyIndicator.showWhile(display, new Runnable () { 61 public void run() { 62 try { 63 ModalContext.run(runnable, fork, getProgressMonitor(), display); 64 } catch (InvocationTargetException ite) { 65 holder[0] = ite; 66 } catch (InterruptedException ie) { 67 holder[0] = ie; 68 } 69 } 70 }); 71 if (holder[0] != null) { 72 if (holder[0] instanceof InvocationTargetException ) { 73 throw (InvocationTargetException ) holder[0]; 74 } else if (holder[0] instanceof InterruptedException ) { 75 throw (InterruptedException ) holder[0]; 76 } 77 } 78 } finally { 79 runningRunnables--; 80 close(); 81 } 82 } 83 84 public boolean close() { 85 if (runningRunnables <= 0) return super.close(); 86 return false; 87 } 88 } 89 | Popular Tags |