public boolean editCellAt(int index, EventObject e) {
    if (editor != null && !editor.stopCellEditing()) return false;

    if (index < 0 || index >= getModel().getSize()) return false;

    if (!isCellEditable(index)) return false;

    if (editorRemover == null) {
      KeyboardFocusManager fm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
      editorRemover = new CellEditorRemover(fm);
      fm.addPropertyChangeListener("permanentFocusOwner", editorRemover); // NOI18N
    }

    if (editor != null && editor.isCellEditable(e)) {
      editorComp = prepareEditor(index);
      if (editorComp == null) {
        removeEditor();
        return false;
      }
      editorComp.setBounds(getCellBounds(index, index));
      add(editorComp);
      editorComp.validate();

      editingIndex = index;
      editor.addCellEditorListener(this);

      return true;
    }
    return false;
  }
  /*
   *  Create using the specified focus policy
   */
  public TabFocusHandler(JTabbedPane tabbedPane, int focusPolicy) {
    if (focusPolicy != RESET_FOCUS && focusPolicy != RETAIN_FOCUS)
      throw new IllegalArgumentException("Invalid focus policy");

    this.tabbedPane = tabbedPane;
    this.focusPolicy = focusPolicy;

    //  Add listeners to manage a tab change

    tabbedPane.addChangeListener(this);
    KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    focusManager.addPropertyChangeListener("permanentFocusOwner", this);
  }
  /*
   * The method maps the list of the active windows to the window's AppContext,
   * then the method registers ActiveWindowListener, GuiDisposedListener listeners;
   * it executes the initilialization only once per AppContext.
   */
  @SuppressWarnings("unchecked")
  private static void initActiveWindowsTracking(Window w) {
    AppContext appContext = AppContext.getAppContext();
    synchronized (appContext) {
      List<WWindowPeer> l = (List<WWindowPeer>) appContext.get(ACTIVE_WINDOWS_KEY);
      if (l == null) {
        l = new LinkedList<WWindowPeer>();
        appContext.put(ACTIVE_WINDOWS_KEY, l);
        appContext.addPropertyChangeListener(AppContext.GUI_DISPOSED, guiDisposedListener);

        KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        kfm.addPropertyChangeListener("activeWindow", activeWindowListener);
      }
    }
  }
 /** Register us as KeyEventDispatcher and property "managingFocus" listeners. */
 private void addTraversingOutListeners(KeyboardFocusManager kfm) {
   kfm.addKeyEventDispatcher(this);
   kfm.addPropertyChangeListener("managingFocus", this);
 }
  /**
   * invoked by reflection
   *
   * @param dataManager
   * @param applicationInfoEx
   * @param actionManager
   * @param uiSettings
   */
  public WindowManagerImpl(
      DataManager dataManager,
      ApplicationInfoEx applicationInfoEx,
      ActionManagerEx actionManager,
      UISettings uiSettings,
      MessageBus bus) {
    myApplicationInfoEx = applicationInfoEx;
    myDataManager = dataManager;
    myActionManager = actionManager;
    myUiSettings = uiSettings;
    if (myDataManager instanceof DataManagerImpl) {
      ((DataManagerImpl) myDataManager).setWindowManager(this);
    }

    final Application application = ApplicationManager.getApplication();
    if (!application.isUnitTestMode()) {
      Disposer.register(
          application,
          new Disposable() {
            @Override
            public void dispose() {
              disposeRootFrame();
            }
          });
    }

    myCommandProcessor = new CommandProcessor();
    myWindowWatcher = new WindowWatcher();
    final KeyboardFocusManager keyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addPropertyChangeListener(FOCUSED_WINDOW_PROPERTY_NAME, myWindowWatcher);
    if (Patches.SUN_BUG_ID_4218084) {
      keyboardFocusManager.addPropertyChangeListener(
          FOCUSED_WINDOW_PROPERTY_NAME, new SUN_BUG_ID_4218084_Patch());
    }
    myLayout = new DesktopLayout();
    myProject2Frame = new HashMap<Project, IdeFrameImpl>();
    myDialogsToDispose = new HashMap<Project, Set<JDialog>>();
    myFrameExtendedState = Frame.NORMAL;

    // Calculate screen bounds.

    Rectangle screenBounds = new Rectangle();
    if (!application.isHeadlessEnvironment()) {
      final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      final GraphicsDevice[] devices = env.getScreenDevices();
      for (final GraphicsDevice device : devices) {
        screenBounds = screenBounds.union(device.getDefaultConfiguration().getBounds());
      }
    }
    myScreenBounds = screenBounds;

    myActivationListener =
        new WindowAdapter() {
          public void windowActivated(WindowEvent e) {
            Window activeWindow = e.getWindow();
            if (activeWindow instanceof IdeFrameImpl) { // must be
              proceedDialogDisposalQueue(((IdeFrameImpl) activeWindow).getProject());
            }
          }
        };

    bus.connect()
        .subscribe(
            AppLifecycleListener.TOPIC,
            new AppLifecycleListener.Adapter() {
              @Override
              public void appClosing() {
                // save fullscreen window states
                if (isFullScreenSupportedInCurrentOS()
                    && GeneralSettings.getInstance().isReopenLastProject()) {
                  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();

                  if (openProjects.length > 0) {
                    WindowManagerEx wm = WindowManagerEx.getInstanceEx();
                    for (Project project : openProjects) {
                      IdeFrameImpl frame = wm.getFrame(project);
                      if (frame != null) {
                        frame.storeFullScreenStateIfNeeded();
                      }
                    }
                  }
                }
              }
            });

    if (UIUtil.hasLeakingAppleListeners()) {
      UIUtil.addAwtListener(
          new AWTEventListener() {
            @Override
            public void eventDispatched(AWTEvent event) {
              if (event.getID() == ContainerEvent.COMPONENT_ADDED) {
                if (((ContainerEvent) event).getChild() instanceof JViewport) {
                  UIUtil.removeLeakingAppleListeners();
                }
              }
            }
          },
          AWTEvent.CONTAINER_EVENT_MASK,
          application);
    }
  }