Package ch.unibe.softwaremap

Source Code of ch.unibe.softwaremap.BaseTest

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);
  }

}
TOP

Related Classes of ch.unibe.softwaremap.BaseTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.