public static void showTestResultsToolWindow(
      @NotNull final Project project, @NotNull final String message, boolean solved) {
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
    if (window == null) {
      toolWindowManager.registerToolWindow(
          StudyTestResultsToolWindowFactoryKt.ID, true, ToolWindowAnchor.BOTTOM);
      window = toolWindowManager.getToolWindow(StudyTestResultsToolWindowFactoryKt.ID);
      new StudyTestResultsToolWindowFactory().createToolWindowContent(project, window);
    }

    final Content[] contents = window.getContentManager().getContents();
    for (Content content : contents) {
      final JComponent component = content.getComponent();
      if (component instanceof ConsoleViewImpl) {
        ((ConsoleViewImpl) component).clear();
        if (!solved) {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.ERROR_OUTPUT);
        } else {
          ((ConsoleViewImpl) component).print(message, ConsoleViewContentType.NORMAL_OUTPUT);
        }
        window.setAvailable(true, () -> {});
        window.show(() -> {});
        return;
      }
    }
  }
 @Override
 public Insets getBorderInsets(final Component c) {
   if (myProject == null) return new Insets(0, 0, 0, 0);
   ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
   if (!(toolWindowManager instanceof ToolWindowManagerImpl)
       || !((ToolWindowManagerImpl) toolWindowManager).isToolWindowRegistered(myInfo.getId())
       || myWindow.getType() == ToolWindowType.FLOATING) {
     return new Insets(0, 0, 0, 0);
   }
   ToolWindowAnchor anchor = myWindow.getAnchor();
   Component component = myWindow.getComponent();
   Container parent = component.getParent();
   while (parent != null) {
     if (parent instanceof Splitter) {
       Splitter splitter = (Splitter) parent;
       boolean isFirst = splitter.getFirstComponent() == component;
       boolean isVertical = splitter.isVertical();
       return new Insets(
           0,
           anchor == ToolWindowAnchor.RIGHT || (!isVertical && !isFirst) ? 1 : 0,
           (isVertical && isFirst) ? 1 : 0,
           anchor == ToolWindowAnchor.LEFT || (!isVertical && isFirst) ? 1 : 0);
     }
     component = parent;
     parent = component.getParent();
   }
   return new Insets(
       0,
       anchor == ToolWindowAnchor.RIGHT ? 1 : 0,
       anchor == ToolWindowAnchor.TOP ? 1 : 0,
       anchor == ToolWindowAnchor.LEFT ? 1 : 0);
 }
  private boolean isProjectViewVisible() {
    final Window frame = SwingUtilities.getWindowAncestor(this);
    if (frame instanceof IdeFrameImpl) {
      final Project project = ((IdeFrameImpl) frame).getProject();
      if (project != null) {
        if (!project.isInitialized()) return true;
        ToolWindow toolWindow =
            ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.PROJECT_VIEW);
        return toolWindow != null && toolWindow.isVisible();
      }
    }

    return false;
  }
  private void updateTabBorder() {
    if (!myProject.isOpen()) return;

    ToolWindowManagerEx mgr = (ToolWindowManagerEx) ToolWindowManager.getInstance(myProject);

    String[] ids = mgr.getToolWindowIds();

    Insets border = new Insets(0, 0, 0, 0);

    UISettings uiSettings = UISettings.getInstance();

    List<String> topIds = mgr.getIdsOn(ToolWindowAnchor.TOP);
    List<String> bottom = mgr.getIdsOn(ToolWindowAnchor.BOTTOM);
    List<String> rightIds = mgr.getIdsOn(ToolWindowAnchor.RIGHT);
    List<String> leftIds = mgr.getIdsOn(ToolWindowAnchor.LEFT);

    if (!uiSettings.HIDE_TOOL_STRIPES) {
      border.top = topIds.size() > 0 ? 1 : 0;
      border.bottom = bottom.size() > 0 ? 1 : 0;
      border.left = leftIds.size() > 0 ? 1 : 0;
      border.right = rightIds.size() > 0 ? 1 : 0;
    }

    for (String each : ids) {
      ToolWindow eachWnd = mgr.getToolWindow(each);
      if (!eachWnd.isAvailable()) continue;

      if (eachWnd.isVisible() && eachWnd.getType() == ToolWindowType.DOCKED) {
        ToolWindowAnchor eachAnchor = eachWnd.getAnchor();
        if (eachAnchor == ToolWindowAnchor.TOP) {
          border.top = 0;
        } else if (eachAnchor == ToolWindowAnchor.BOTTOM) {
          border.bottom = 0;
        } else if (eachAnchor == ToolWindowAnchor.LEFT) {
          border.left = 0;
        } else if (eachAnchor == ToolWindowAnchor.RIGHT) {
          border.right = 0;
        }
      }
    }

    myTabs
        .getPresentation()
        .setPaintBorder(border.top, border.left, border.right, border.bottom)
        .setTabSidePaintBorder(5);
  }
  /** @return can be null if user cancelled operation */
  @Nullable
  public static AntBuildMessageView openBuildMessageView(
      Project project, AntBuildFileBase buildFile, String[] targets) {
    final VirtualFile antFile = buildFile.getVirtualFile();
    if (!LOG.assertTrue(antFile != null)) {
      return null;
    }

    // check if there are running instances of the same build file

    MessageView ijMessageView = MessageView.SERVICE.getInstance(project);
    Content[] contents = ijMessageView.getContentManager().getContents();
    for (Content content : contents) {
      if (content.isPinned()) {
        continue;
      }
      AntBuildMessageView buildMessageView = content.getUserData(KEY);
      if (buildMessageView == null) {
        continue;
      }

      if (!antFile.equals(buildMessageView.getBuildFile().getVirtualFile())) {
        continue;
      }

      if (buildMessageView.isStopped()) {
        ijMessageView.getContentManager().removeContent(content, true);
        continue;
      }

      int result =
          Messages.showYesNoCancelDialog(
              AntBundle.message("ant.is.active.terminate.confirmation.text"),
              AntBundle.message("starting.ant.build.dialog.title"),
              Messages.getQuestionIcon());

      switch (result) {
        case 0: // yes
          buildMessageView.stopProcess();
          ijMessageView.getContentManager().removeContent(content, true);
          continue;
        case 1: // no
          continue;
        default: // cancel
          return null;
      }
    }

    final AntBuildMessageView messageView = new AntBuildMessageView(project, buildFile, targets);
    String contentName = buildFile.getPresentableName();
    contentName = BUILD_CONTENT_NAME + " (" + contentName + ")";

    final Content content =
        ContentFactory.SERVICE
            .getInstance()
            .createContent(messageView.getComponent(), contentName, true);
    content.putUserData(KEY, messageView);
    ijMessageView.getContentManager().addContent(content);
    ijMessageView.getContentManager().setSelectedContent(content);
    content.setDisposer(
        new Disposable() {
          @Override
          public void dispose() {
            Disposer.dispose(messageView.myAlarm);
          }
        });
    new CloseListener(content, ijMessageView.getContentManager(), project);
    // Do not inline next two variabled. Seeking for NPE.
    ToolWindow messageToolWindow =
        ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
    messageToolWindow.activate(null, false);
    return messageView;
  }