// Create the tool window content.
 public void createToolWindowContent(Project project, ToolWindow toolWindow) {
   this.toolWindow = toolWindow;
   this.quack();
   ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
   Content content = contentFactory.createContent(toolWindowContent, "", false);
   toolWindow.getContentManager().addContent(content);
 }
  /*
  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();
  }
 private void createToolWindowContent(ToolWindow toolWindow) {
   ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
   Content content = contentFactory.createContent(toolWindowContent, "", false);
   toolWindow.getContentManager().addContent(content);
 }
  @NotNull
  private Content createContent(String contentName) {
    if (project == null) {
      throw new IllegalStateException("Project not opened");
    }

    ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    ToolWindow wm = ToolWindowManager.getInstance(project).getToolWindow(QUERY_RESULT_PANE);

    if (wm == null) {
      wm = toolWindowManager.registerToolWindow(QUERY_RESULT_PANE, true, ToolWindowAnchor.BOTTOM);
      wm.setIcon(Icons.QUERY_RESULT_PANE);
      wm.setToHideOnEmptyContent(true);
    }

    Content content = wm.getContentManager().findContent(contentName);
    if (content == null) {
      JTabbedPane tabbedPane = new JTabbedPane();
      tabbedPane.addContainerListener(new JTabbedPaneListener());

      tabbedPane.addKeyListener(
          new KeyAdapter() {
            public void keyPressed(KeyEvent e) {
              ((JComponent) e.getComponent()).putClientProperty(JTABBED_CONTROL, e.isControlDown());
            }

            public void keyReleased(KeyEvent e) {
              ((JComponent) e.getComponent()).putClientProperty(JTABBED_CONTROL, e.isControlDown());
            }
          });
      tabbedPane.addFocusListener(
          new FocusAdapter() {
            public void focusGained(FocusEvent e) {
              Object source = e.getSource();
              Component c = e.getOppositeComponent();
            }

            public void focusLost(FocusEvent e) {
              ((JComponent) e.getSource()).putClientProperty(JTABBED_CONTROL, false);
            }
          });

      JPanel jpanel = new JPanel(new BorderLayout());

      DefaultActionGroup actionGroup = new DefaultActionGroup("PsiActionGroup22", false);
      actionGroup.add(
          new LocalToggleAction(
              "Refresh Query Result",
              "Refresh Query Result",
              Icons.REFRESH_RESULTSET,
              REFRESH_RESULTSET));
      actionGroup.add(new LocalToggleAction("Copy", "Copy", Icons.EXPORT_DATA, EXPORT_DATA));

      // todo -- problem with keeping sql markers and tabs in sync
      //            actionGroup.add(new LocalToggleAction("Close", "Close", Icons.CLOSE_PANEL,
      // CLOSE_PANEL));

      ActionManager actionManager = ActionManager.getInstance();
      ActionToolbar toolBar =
          actionManager.createActionToolbar("DataGridActionToolbar", actionGroup, false);
      jpanel.add(toolBar.getComponent(), "West");
      jpanel.add(tabbedPane, "Center");

      //            ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
      //            ContentFactory contentFactory = PeerFactory.getInstance().getContentFactory();
      ContentFactory contentFactory = ContentFactoryEx.getContentFactory();
      content = contentFactory.createContent(jpanel, contentName, false);
      // content.setActions(actionGroup, "UKNOWN", null);
      content.setIcon(Icons.DISCONNECT);
      wm.getContentManager().addContent(content);
    }

    return content;
  }