public void initComponent() {
    gradlePanelWrapper = new GradlePanelWrapper();

    SettingsNodeVersion1 settingsNodeVersion1 = getSettings();

    gradlePanelWrapper.initialize(myProject, settingsNodeVersion1);

    GradleUIApplicationComponent gradleUIApplicationComponent =
        ApplicationManager.getApplication().getComponent(GradleUIApplicationComponent.class);
    gradleUIApplicationComponent.addUIAvailabilityObserver(this, true, false);
  }
  /*
  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();
  }
  /**
   * This is called to see if we can close a project. If gradle is running, we'll ask the user for
   * confirmation. Unfortunately, there's this odd behavior I'm seeing where this is called twice if
   * you return true the first time. I don't think this mechanism was meant for prompting the user
   * for confirmation. As an ugly hack, I'll track when we asked and if its less than so many
   * seconds, we'll just return the last answer. This is so we don't get duplicate questions to the
   * user.
   *
   * @param project the project being closed
   * @return true if the project can be closed, false if not.
   * @author mhunsicker
   */
  public boolean canCloseProject(Project project) {
    if (project != myProject) return true;

    long now = System.currentTimeMillis();
    long timeSinceLastPrompt = now - lastTimeAskedCanClose;
    if (timeSinceLastPrompt <= 2000) return lastAnswerWhenAskedCanClose;

    lastAnswerWhenAskedCanClose = gradlePanelWrapper.canClose();

    lastTimeAskedCanClose =
        System
            .currentTimeMillis(); // set this AFTER asking because it displays a UI and the user may
                                  // let it sit there before answering.

    return lastAnswerWhenAskedCanClose;
  }
 /**
  * This updates the main gradle panel if the path to the gradle home has changed. This triggers
  * the wrapper to reload which will fire a gradleUILoaded/Unloaded message -- which is when this
  * component will reflect this change
  */
 public void reset() {
   if (gradlePanelWrapper != null) gradlePanelWrapper.reset();
 }
 public JPanel getOutputComponent() {
   return gradlePanelWrapper.getOutputComponent();
 }
 /**
  * @return the single pane UI version1. Note: this is very likely to return null if this hasn't
  *     been setup yet or hasn't loaded yet.
  * @author mhunsicker
  */
 public DualPaneUIVersion1 getGradleUI() {
   return gradlePanelWrapper.getGradleUI();
 }
 public void removeTab(GradleTabVersion1 tab) {
   gradlePanelWrapper.removeTab(tab);
 }
 /**
  * This adds a tab. You'll want to add tabs using this rather than calling
  * SinglePaneUIVersion1.addTab directly. Why? Because this removes the timing issues. That is,
  * whether or not we've loaded the gradle UI, you can call this and we'll show the tabs whenever
  * we do display the UI.
  *
  * @param tab the tab to add
  * @author mhunsicker
  */
 public void addTab(GradleTabVersion1 tab) {
   gradlePanelWrapper.addTab(tab);
 }