/**
   * Forces mouse out on self and contained buttons.
   *
   * <p>
   */
  public void forceMouseOut() {

    for (Widget w : m_buttonPanel) {
      CmsDomUtil.ensureMouseOut(w);
    }
    CmsDomUtil.ensureMouseOut(this);
    removeStyleName(I_CmsLayoutBundle.INSTANCE.stateCss().cmsHovering());
  }
  /**
   * Sets the overflow of the tab layout content's parent to visible.
   *
   * <p>
   */
  protected void setOverflowVisibleToContent() {

    Element tabRoot = m_tabPanel.getElement();
    // set an additional css class for the parent element of the .gwt-TabLayoutPanelTabs element
    List<Element> tabContentDivs =
        CmsDomUtil.getElementsByClass(
            I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelContent(),
            CmsDomUtil.Tag.div,
            tabRoot);
    tabContentDivs.addAll(
        CmsDomUtil.getElementsByClass(
            "gwt-TabLayoutPanelContentContainer", CmsDomUtil.Tag.div, tabRoot));
    for (Element e : tabContentDivs) {
      e.getParentElement().getStyle().setOverflow(Overflow.VISIBLE);
    }
  }
  /**
   * Add a new tab with the provided name and content.
   *
   * <p>Wrapper function for {@link com.google.gwt.user.client.ui.TabLayoutPanel#add(Widget,
   * String)}
   *
   * @param tabContent the widget to add as a tab
   * @param tabName the name of the tab to display in the tabbar
   */
  public void add(E tabContent, String tabName) {

    tabContent.addStyleName(I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
    m_tabPanel.add(tabContent, tabName);

    Element tabRootEl = m_tabPanel.getElement();
    // set an additional css class for the parent element of the .gwt-TabLayoutPanelTabs element
    List<Element> tabDivs =
        CmsDomUtil.getElementsByClass(
            I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelTab(),
            CmsDomUtil.Tag.div,
            tabRootEl);

    Iterator<Element> it = tabDivs.iterator();
    boolean first = true;
    while (it.hasNext()) {

      Element e = it.next();
      e.removeClassName(I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cornerLeft());
      e.removeClassName(I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cornerRight());
      if (first) {
        e.addClassName(I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cornerLeft());
        first = false;
      }
      if (!it.hasNext()) {
        e.addClassName(I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cornerRight());
      }
    }
  }
  /**
   * Returns the tab element for the given index.
   *
   * <p>
   *
   * @param tabIndex the tab index to get the tab element for
   * @return the tab element for the given index
   */
  private Element getTabElement(int tabIndex) {

    Element tabRootEl = m_tabPanel.getElement();
    // set an additional css class for the parent element of the .gwt-TabLayoutPanelTabs element
    List<Element> tabDivs =
        CmsDomUtil.getElementsByClass(
            I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelTab(),
            CmsDomUtil.Tag.div,
            tabRootEl);
    if ((tabDivs != null) && (tabDivs.size() > tabIndex)) {
      return tabDivs.get(tabIndex);
    }
    return null;
  }
  /**
   * The constructor for an empty tabbed panel.
   *
   * <p>
   *
   * @param tabbedPanelStyle the pre-defined height of the tabbar, can be "small" or "standard"
   */
  public CmsTabbedPanel(CmsTabbedPanelStyle tabbedPanelStyle) {

    m_tabPanel = new TabLayoutPanel(tabbedPanelStyle.getBarHeight(), Unit.PX);
    m_panelStyle = tabbedPanelStyle;

    // All composites must call initWidget() in their constructors.
    initWidget(m_tabPanel);

    Element tabRootEl = m_tabPanel.getElement();
    // set an additional css class for the parent element of the .gwt-TabLayoutPanelTabs element
    List<Element> tabBarDivs =
        CmsDomUtil.getElementsByClass(
            I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelTabs(),
            CmsDomUtil.Tag.div,
            tabRootEl);
    if (tabBarDivs.size() == 1) {
      tabBarDivs
          .get(0)
          .getParentElement()
          .setClassName(
              I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanelTabBar()
                  + " "
                  + I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll());
      if (m_panelStyle.getTabColorClass() != null) {
        tabBarDivs.get(0).getParentElement().addClassName(m_panelStyle.getTabColorClass());
      }
    }

    m_tabPanel.setStyleName(m_panelStyle.getStyleClass());
    m_tabPanel.addStyleName(I_CmsLayoutBundle.INSTANCE.tabbedPanelCss().cmsTabLayoutPanel());
    m_tabPanel.addStyleName(
        I_CmsLayoutBundle.INSTANCE.generalCss().cornerAll()
            + " "
            + I_CmsLayoutBundle.INSTANCE.generalCss().textMedium());

    m_tabPanel.addAttachHandler(
        new AttachEvent.Handler() {

          /**
           * @see
           *     com.google.gwt.event.logical.shared.AttachEvent.Handler#onAttachOrDetach(com.google.gwt.event.logical.shared.AttachEvent)
           */
          public void onAttachOrDetach(AttachEvent event) {

            setOverflowVisibleToContent();
          }
        });
  }