package ch.unibe.softwaremap; import org.eclipse.core.runtime.jobs.Job; import org.eclipse.swt.widgets.Display; public abstract class BaseTest { /** * Process UI input but do not return for the specified time interval. * * @param waitTimeMillis the number of milliseconds */ protected static void delay(long waitTimeMillis) { Display display = Display.getCurrent(); // If this is the UI thread, // then process input. if (display != null) { long endTimeMillis = System.currentTimeMillis() + waitTimeMillis; while (System.currentTimeMillis() < endTimeMillis) { display.readAndDispatch(); // just busy wait as sleep() seems to block until some input is recieved (e.g. mouse moved) // if (!display.readAndDispatch()) // display.sleep(); } display.update(); } // Otherwise, perform a simple sleep. else { try { Thread.sleep(waitTimeMillis); } catch (InterruptedException e) { // Ignored. } } } /** * Wait until all background tasks are complete. */ public static void waitForJobs() { while (!Job.getJobManager().isIdle()) delay(65); } }