public static void watchContentManager(@NotNull ToolWindow toolWindow, @NotNull ContentManager contentManager) {
    toolWindow.setAvailable(!contentManager.isEmpty());

    contentManager.addContentManagerListener(new ContentManagerListener() {
      @Override
      public void contentAdded(@NotNull ContentManagerEvent e) {
        toolWindow.setAvailable(true);
      }

      @Override
      public void contentRemoved(@NotNull ContentManagerEvent e) {
        if ((!(toolWindow instanceof ToolWindowEx)
             || ApplicationManager.getApplication().isHeadlessEnvironment()
             || !((ToolWindowEx)toolWindow).getDecorator().isSplitUnsplitInProgress())
            && contentManager.isEmpty()) {
          toolWindow.setAvailable(false);
        }
      }
    });
  }
public static void watchContentManager(@NotNull ToolWindow toolWindow, @NotNull ContentManager contentManager)