/**
   * @param callback a callback that'll receive null as a parameter and should return true if the
   *     condition seeked was reached and false otherwise.
   * @param deltaToElapse the number of seconds that can be elapsed until the function returns if
   *     the condition has not been satisfied.
   * @throws AssertionError if the condition was not satisfied in the available amount of time
   */
  protected void goToIdleLoopUntilCondition(
      final ICallback<Boolean, Object> callback,
      long deltaToElapse,
      final ICallback<String, Object> errorMessageCallback,
      boolean failIfNotSatisfied) {
    // make the delta the absolute time
    deltaToElapse = System.currentTimeMillis() + deltaToElapse;
    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    while (!shell.isDisposed()) {
      display.readAndDispatch();
      synchronized (this) {
        try {
          this.wait(50);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }

      if (callback.call(null)) {
        return;
      }
      if (deltaToElapse < System.currentTimeMillis()) {
        break;
      }
    }
    if (!failIfNotSatisfied) {
      return;
    }
    if (errorMessageCallback != null) {
      fail(
          "The condition requested was not satisfied in the available amount of time:\n"
              + errorMessageCallback.call(null));
    }
    fail("The condition requested was not satisfied in the available amount of time");
  }
 private void waitUntilCondition(ICallback<String, Object> call) {
   long currentTimeMillis = System.currentTimeMillis();
   String msg = null;
   while (System.currentTimeMillis() < currentTimeMillis + 5000) { // at most 5 seconds
     msg = call.call(null);
     if (msg == null) {
       return;
     }
     synchronized (this) {
       try {
         wait(25);
       } catch (Exception e) {
         e.printStackTrace();
       }
     }
   }
   fail("Condition not satisfied in 5 seconds." + msg);
 }
  /** Goes to 'manual' mode to allow the interaction with the opened eclipse instance. */
  protected void goToManual(long millis, ICallback<Boolean, Object> condition) {
    long finishAt = System.currentTimeMillis() + millis;

    System.out.println("going to manual...");
    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
      if (millis > 0 && finishAt < System.currentTimeMillis()) {
        break;
      }
      if (condition != null && condition.call(null)) {
        break;
      }
    }
    System.out.println("finishing...");
  }