// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.wm.impl;

import com.intellij.ide.ApplicationInitializedListener;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.ExtensionNotApplicableException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import org.jetbrains.annotations.NotNull;

public final class WindowDressing implements ApplicationInitializedListener {
  @Override
  public void componentsInitialized() {
    Application app = ApplicationManager.getApplication();
    if (app.isHeadlessEnvironment()) {
      throw ExtensionNotApplicableException.INSTANCE;
    }

    app.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
      @Override
      public void projectOpened(@NotNull Project project) {
        getWindowActionGroup().addProject(project);
      }

      @Override
      public void projectClosed(@NotNull Project project) {
        getWindowActionGroup().removeProject(project);
      }
    });
  }

  @NotNull
  public static ProjectWindowActionGroup getWindowActionGroup() {
    return (ProjectWindowActionGroup)ActionManager.getInstance().getAction("OpenProjectWindows");
  }
}

@@ -289,61 +289,8 @@
 er;%0A
-import com.intellij.openapi.application.Application;%0A
 impo
@@ -701,80 +701,42 @@
 %7B%0A  
-@Override%0A  public void componentsInitialized() %7B%0A    Application app = 
+public WindowDressing() %7B%0A    if (
 Appl
@@ -770,21 +770,8 @@
 on()
-;%0A    if (app
 .isH
@@ -858,16 +858,104 @@
   %7D%0A
-%0A    app
+  %7D%0A%0A  @Override%0A  public void componentsInitialized() %7B%0A    ApplicationManager.getApplication()
 .get

throw ExtensionNotApplicableException in ctor