private void closeResultTab(ResultTab tab) {
   if (tab == null) {
     throw new IllegalArgumentException("Null ResultTab passed");
   }
   s_log.debug("SQLPanel.closeResultTab(" + tab.getIdentifier().toString() + ")");
   tab.closeTab();
   _tabbedExecutionsPanel.remove(tab);
 }
  private void addResultsTab(ResultTab tab, IResultTab resultTabToReplace) {
    if (null == resultTabToReplace && null == _stickyTab) {
      _tabbedExecutionsPanel.addTab(tab.getTitle(), null, tab, tab.getViewableSqlString());
      checkResultTabLimit();
    } else {
      if (null != resultTabToReplace && _session.getProperties().getKeepTableLayoutOnRerun()) {
        TableState sortableTableState = resultTabToReplace.getResultSortableTableState();
        if (null != sortableTableState) {
          tab.applyResultSortableTableState(sortableTableState);
        }
      }

      int indexToReplace = -1;
      ImageIcon tabIcon = null;

      // Either resultTabToReplace or _stickyTab must be not null here
      if (null != resultTabToReplace && _stickyTab != resultTabToReplace) {
        indexToReplace = getIndexOfTab(resultTabToReplace);
      } else {
        indexToReplace = getIndexOfTab(_stickyTab);
        if (-1 == indexToReplace) {
          // sticky tab was closed
          _stickyTab = null;
        } else {
          tabIcon = getStickyIcon();
          _stickyTab = tab;
        }
      }

      if (-1 == indexToReplace) {
        // Just add the tab
        addResultsTab(tab, null);
        return;
      }

      closeTabAt(indexToReplace);
      _tabbedExecutionsPanel.insertTab(
          tab.getTitle(), tabIcon, tab, tab.getViewableSqlString(), indexToReplace);
    }
  }
  /**
   * Return the passed tab back into the tabbed pane.
   *
   * @param tab <TT>Resulttab</TT> to be returned
   * @throws IllegalArgumentException Thrown if a <TT>null</TT> <TT>ResultTab</TT> passed.
   */
  private void returnToTabbedPane(ResultTab tab) {
    if (tab == null) {
      throw new IllegalArgumentException("Null ResultTab passed");
    }

    s_log.debug("SQLPanel.returnToTabbedPane(" + tab.getIdentifier().toString() + ")");

    for (ResultFrame sqlResultFrame : _sqlResultFrames) {
      if (tab == sqlResultFrame.getTab()) {
        _sqlResultFrames.remove(sqlResultFrame);
        break;
      }
    }

    addResultsTab(tab, null);
  }
  /**
   * Create an internal frame for the specified tab and display the tab in the internal frame after
   * removing it from the tabbed pane.
   *
   * @param tab <TT>ResultTab</TT> to be displayed in an internal frame.
   * @throws IllegalArgumentException Thrown if a <TT>null</TT> <TT>ResultTab</TT> passed.
   */
  private void createSQLResultFrame(ResultTab tab) {
    if (tab == null) {
      throw new IllegalArgumentException("Null ResultTab passed");
    }
    s_log.debug("SQLPanel.createSQLResultFrame(" + tab.getIdentifier().toString() + ")");
    _tabbedExecutionsPanel.remove(tab);

    ResultFrameListener resultFrameListener =
        new ResultFrameListener() {
          @Override
          public void frameReplaced(ResultFrame oldFrame, ResultFrame newFrame) {
            onFrameReplaced(oldFrame, newFrame);
          }
        };

    ResultFrame frame =
        new ResultFrame(_session, tab, _resultTabFactory, resultFrameListener, true, false);
    _sqlResultFrames.add(frame);
  }