@Override
      public void windowGainedFocus(final WindowEvent e) {
        removeWindowFocusListener(this); // run this code only the first time our dialog is focused

        myOpened = true;

        DialogWrapper wrapper = getDialogWrapper();
        JComponent toFocus = wrapper == null ? null : wrapper.getPreferredFocusedComponent();
        JRootPane pane = getRootPane();
        if (pane != null && toFocus == null) {
          toFocus = pane.getDefaultButton();
        }

        if (pane != null) {
          IJSwingUtilities.moveMousePointerOn(pane.getDefaultButton());
        }

        setupSelectionOnPreferredComponent(toFocus);

        if (toFocus != null && toFocus.isEnabled()) {
          if (isShowing() && (!LoadingState.COMPONENTS_REGISTERED.isOccurred() ||
                              ApplicationManager.getApplication() == null ||
                              ApplicationManager.getApplication().isActive())) {
            toFocus.requestFocus();
          }
          else {
            toFocus.requestFocusInWindow();
          }
        }
      }
@Override
      public void windowGainedFocus(final WindowEvent e)