@Override
  public void run(boolean fork, boolean cancelable, final IRunnableWithProgress request)
      throws InvocationTargetException, InterruptedException {
    if (headless && Display.getCurrent() == null) {
      PlatformGIS.run(request);
      return;
    }

    if (getProgressMonitor() instanceof ProgressMonitorPart) {
      ProgressMonitorPart part = (ProgressMonitorPart) getProgressMonitor();
      if (Display.getCurrent() != null) part.setVisible(true);

      try {
        setEnablement(buttonBar, false);
        if (fork) {
          PlatformGIS.run(request, part);
        } else {
          PlatformGIS.runBlockingOperation(request, part);
        }
      } finally {
        setEnablement(buttonBar, true);
        if (Display.getCurrent() != null && !part.isDisposed()) part.setVisible(false);
      }
    } else {
      if (fork) {
        PlatformGIS.run(request);
      } else {
        PlatformGIS.runBlockingOperation(request, ProgressManager.instance().get());
      }
    }
  }
  private Object aboutToStart(boolean cancelable) {
    Map savedState = null;
    Shell shell = getShell();
    if (shell != null) {
      // Save focus control
      Control focusControl = getShell().getDisplay().getFocusControl();
      if (focusControl != null && focusControl.getShell() != getShell()) focusControl = null;

      Button cancelButton = getButton(IDialogConstants.CANCEL_ID);
      // Set the busy cursor to all shells.
      Display d = getShell().getDisplay();
      setDisplayCursor(d, d.getSystemCursor(SWT.CURSOR_WAIT));

      // Set the arrow cursor to the cancel component.
      cancelButton.setCursor(d.getSystemCursor(SWT.CURSOR_ARROW));

      boolean hasProgressMonitor = fProgressMonitorPart != null;

      // Deactivate shell
      savedState = saveUIState(false);
      if (focusControl != null) savedState.put("focus", focusControl); // $NON-NLS-1$

      if (hasProgressMonitor) {
        if (cancelable) fProgressMonitorPart.attachToCancelComponent(cancelButton);
        fStatusContainer.showPage(fProgressMonitorPart);
      }
      // Update the status container since we are blocking the event loop right now.
      fStatusContainer.update();
    }
    return savedState;
  }
  private void stopped(Object savedState) {
    Shell shell = getShell();
    if (shell != null) {
      Button cancelButton = getButton(IDialogConstants.CANCEL_ID);

      if (fProgressMonitorPart != null)
        fProgressMonitorPart.removeFromCancelComponent(cancelButton);

      fStatusContainer.showPage(fMessageBox);
      Map state = (Map) savedState;
      restoreUIState(state);

      setDisplayCursor(shell.getDisplay(), null);
      cancelButton.setCursor(null);
      Control focusControl = (Control) state.get("focus"); // $NON-NLS-1$
      if (focusControl != null) focusControl.setFocus();
    }
  }