public static void invokeLaterAfterDialogShown(@NotNull DialogWrapper dialog, @NotNull Runnable action) {
    Application application = ApplicationManager.getApplication();
    if (application.isHeadlessEnvironment()) {
      // there's nothing to tie the action to, so we just schedule it as a next task
      application.invokeLater(action, ModalityState.any());
    }
    else {
      dialog.getWindow().addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
          Window window = e.getWindow();
          application.invokeLater(action, ModalityState.stateForComponent(window));
          window.removeWindowListener(this);
        }
      });
    }
  }
public static void invokeLaterAfterDialogShown(@NotNull DialogWrapper dialog, @NotNull Runnable action)