public SectionRepeater(
        String id,
        Iterable<XmlSection> sections,
        XmlSection currentSection,
        SectionIconFactory iconFactory) {
      super(id);

      for (XmlSection s : sections) {
        ISIXmlSection section = (ISIXmlSection) s;
        boolean current = section.equals(currentSection);

        WebMarkupContainer sectionContainer = new WebMarkupContainer(newChildId());
        add(sectionContainer);

        BookmarkablePageLink<ISIStandardPage> link =
            new SectionLinkFactory().linkToPage("sectionLink", section);
        sectionContainer.add(link);
        if (current) {
          link.setEnabled(false);
          link.add(new ClassAttributeModifier("current"));
          link.add(new IconContainer("iconContainer", section, iconFactory));
          sectionContainer.add(new WebMarkupContainer("current"));
        } else {
          WebMarkupContainer iconContainer = new WebMarkupContainer("iconContainer");
          link.add(iconContainer);
          iconContainer.add(iconFactory.getIconFor(section));
          sectionContainer.add(new WebMarkupContainer("current").setVisible(false));
        }
      }
    }
  private void addSuperSections(
      ISIXmlSection currentSection,
      ISIXmlSection rootSection,
      RepeatingView superSectionRepeater,
      SectionIconFactory iconFactory) {
    // We do have supersections
    for (XmlSection ss : rootSection.getChildren()) {
      ISIXmlSection superSection = (ISIXmlSection) ss;
      WebMarkupContainer superSectionContainer =
          new WebMarkupContainer(superSectionRepeater.newChildId());
      superSectionRepeater.add(superSectionContainer);

      superSectionContainer.add(new Label("superSectionTitle", superSection.getTitle()));

      List<XmlSection> sections;
      // Use Supersection children, or supersection itself if there are no children.
      if (!superSection.hasChildren()) {
        sections = new ArrayList<XmlSection>();
        sections.add(superSection);
      } else {
        sections = superSection.getChildren();
      }

      superSectionContainer.add(
          new SectionRepeater("sectionRepeater", sections, currentSection, iconFactory));
    }
  }
  @Override
  public void onBeforeRender() {
    ISIXmlSection currentSection = getCurrentSection();
    ISIXmlSection rootSection = ISIXmlSection.getRootSection(currentSection);

    /** ************************ Super Section Repeater * ************************ */
    RepeatingView superSectionRepeater = new RepeatingView("superSectionRepeater");
    addOrReplace(superSectionRepeater);

    // Determine if there is a super-section level, or if we just have a list of regular sections
    if (rootSection.hasSuperSections()) {
      addSuperSections(currentSection, rootSection, superSectionRepeater, iconFactory);
    } else {
      addSimpleSections(currentSection, rootSection, superSectionRepeater, iconFactory);
    }
    super.onBeforeRender();
  }
  /**
   * Construct nav bar based on a certain page that is currently being displayed.
   *
   * @param id
   * @param mCurrentPage - model of the XmlSection that is the current page.
   * @param teacher if true, a version of the nav bar appropriate for the teacher is produced.
   */
  public DefaultNavBar(String id, IModel<XmlSection> mCurrentPage, boolean teacher) {
    super(id, mCurrentPage);
    setOutputMarkupId(true);
    iconFactory = SectionIconFactory.getIconFactory(teacher);

    if (mCurrentPage == null) {
      setModel(new XmlSectionModel(ISIApplication.get().getPageNum(1)));
    }

    ISIXmlSection rootSection = ISIXmlSection.getRootSection(getCurrentSection());

    // Current Section's Page Repeater with prev/next
    PageNavPanel pageNavPanelTop = new PageNavPanel("pageNavPanelTop", getModel());
    add(pageNavPanelTop);

    /** ******* Other * ******* */
    // Jump to a certain page
    add(new QuickFlipForm("quickFlipForm", true));

    // Chapter Title (xml level 1)
    add(new Label("title", rootSection.getTitle()));
  }
 private void addSimpleSections(
     ISIXmlSection currentSection,
     ISIXmlSection rootSection,
     RepeatingView superSectionRepeater,
     SectionIconFactory iconFactory) {
   // Simple case - no supersection.  Create a single container and put sections into it.
   WebMarkupContainer container = new WebMarkupContainer(superSectionRepeater.newChildId());
   superSectionRepeater.add(container);
   container.add(new EmptyPanel("superSectionTitle"));
   container.add(
       new SectionRepeater(
           "sectionRepeater", rootSection.getChildren(), currentSection, iconFactory));
 }
 private ISIXmlSection getCurrentSection() {
   ISIXmlSection currentPage = (ISIXmlSection) getModelObject();
   // May be the current page or an ancestor
   return currentPage.getSectionAncestor();
 }