/*
  This sets up the tool window. This can be called multiple times (such as when gradle
  home is changed). As such, this may unregister the tool window if gradle goes away.
   */
  private synchronized void initToolWindow() {
    if (gradlePanelWrapper != null) {
      if (myToolWindow == null) {
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);

        // register the tool Window. Ignore the 'Disposable' object. It's required (even though it
        // doesn't apply to us)
        // if we want to set the 'canWorkInDumbMode' argument to true. That argument means this
        // window will be enabled while
        // Idea is re-indexing the project settings.
        myToolWindow =
            toolWindowManager.registerToolWindow(
                TOOL_WINDOW_ID,
                false,
                ToolWindowAnchor.LEFT,
                new Disposable() {
                  public void dispose() {}
                },
                true);
      } else {
        gradlePanelWrapper.reset();
        myToolWindow
            .getContentManager()
            .removeAllContents(
                true); // remove any previous contents (this can be called to reset a new gradle
                       // home)
      }

      JPanel gradlePanel = gradlePanelWrapper.getMainComponent();

      // I'm going to pass in blank text here. The title will already say 'Gradle'. This is for
      // further refinement.
      ContentFactory contentFactory = PeerFactory.getInstance().getContentFactory();
      Content content = contentFactory.createContent(gradlePanel, "", false);
      myToolWindow.getContentManager().addContent(content);

      // set the icon. (should be 13 x 13?  but this one works...)
      Icon gradleIcon = GradleUtils.loadGradleIcon();
      myToolWindow.setIcon(gradleIcon);
    } else unregisterToolWindow();
  }