Esempio n. 1
0
  /**
   * @param divPagination
   * @param pagi
   * @param ul1
   * @param a
   * @return Div
   */
  @SuppressWarnings("unchecked")
  private Div makePages(
      final Div divPagination, final Paginator pagi, final HtmlTag ul1, final Application a) {
    Div divTemp = divPagination;
    if (!pagi.getFirstPagesNumber().isEmpty()) {
      for (Object o : pagi.getFirstPagesNumber()) {
        Integer page = (Integer) o;
        if (page != pagi.getCurrentPage()) {
          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      null));
        } else {

          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      PaginatorUtils.CURRENT_PAGE));
        }
      }
      ul1.getChildren().add(makeLiText(a));
      String nameValueButton =
          getPaginatorELExpression() + "." + PaginatorUtils.LAST_PAGE_NUMBER + "+1";
      ul1.getChildren()
          .add(
              makeLiGroup(
                  a,
                  nameValueButton,
                  PaginatorUtils.LAST_PAGE_NUMBER,
                  true,
                  PaginatorUtils.RELOAD_DATA,
                  PaginatorUtils.CURRENT_PAGE,
                  null));
    } else if (!pagi.getLastPagesNumber().isEmpty()) {
      String nameValueButton =
          getPaginatorELExpression() + "." + PaginatorUtils.FIRST_PAGE_NUMBER + "+1";
      ul1.getChildren()
          .add(
              makeLiGroup(
                  a,
                  nameValueButton,
                  PaginatorUtils.FIRST_PAGE_NUMBER,
                  true,
                  PaginatorUtils.RELOAD_DATA,
                  PaginatorUtils.CURRENT_PAGE,
                  null));
      ul1.getChildren().add(makeLiText(a));
      for (Object o : pagi.getLastPagesNumber()) {
        Integer page = (Integer) o;
        if (page != pagi.getCurrentPage()) {
          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      null));
        } else {
          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      PaginatorUtils.CURRENT_PAGE));
        }
      }
    } else if (!pagi.getMiddlePagesNumber().isEmpty()) {
      String nameValueButton =
          getPaginatorELExpression() + "." + PaginatorUtils.FIRST_PAGE_NUMBER + "+1";
      ul1.getChildren()
          .add(
              makeLiGroup(
                  a,
                  nameValueButton,
                  PaginatorUtils.FIRST_PAGE_NUMBER,
                  true,
                  PaginatorUtils.RELOAD_DATA,
                  PaginatorUtils.CURRENT_PAGE,
                  null));
      ul1.getChildren().add(makeLiText(a));
      for (Object o : pagi.getMiddlePagesNumber()) {
        Integer page = (Integer) o;
        if (page != pagi.getCurrentPage()) {
          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      null));
        } else {

          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      PaginatorUtils.CURRENT_PAGE));
        }
      }
      ul1.getChildren().add(makeLiText(a));
      nameValueButton = getPaginatorELExpression() + "." + PaginatorUtils.LAST_PAGE_NUMBER + "+1";
      ul1.getChildren()
          .add(
              makeLiGroup(
                  a,
                  nameValueButton,
                  PaginatorUtils.LAST_PAGE_NUMBER,
                  true,
                  PaginatorUtils.RELOAD_DATA,
                  PaginatorUtils.CURRENT_PAGE,
                  null));
    } else {
      // in the case of a paginator with very little page
      for (Object o : pagi.getNearPages()) {
        Integer page = (Integer) o;
        if (page != pagi.getCurrentPage()) {
          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      null));
        } else {

          ul1.getChildren()
              .add(
                  makeLiGroup(
                      a,
                      "" + (page + 1),
                      "" + page,
                      false,
                      PaginatorUtils.RELOAD_DATA,
                      PaginatorUtils.CURRENT_PAGE,
                      PaginatorUtils.CURRENT_PAGE));
        }
      }
    }
    if (getPaginator().getCurrentPage() != getPaginator().getLastPageNumber()) {
      ul1.getChildren()
          .add(
              makeLiGroup(
                  a,
                  getStringsVar() + "['" + NEXT_BUTTON_I18N_KEY + "']",
                  null,
                  true,
                  PaginatorUtils.GOTO_NEXT,
                  null,
                  null));
    }
    divTemp.getChildren().add(ul1);
    return divTemp;
  }