private void buildPager(final int page, final int pageCount, Css css) {
if (pageCount > 1) {
if (page > 1) {
DivElement previous = Elements.createDivElement(css.previous());
getView().pager.appendChild(previous);
previous.setOnClick(new EventListener() {
@Override
public void handleEvent(Event evt) {
currentPlace.fireChildPlaceNavigation(
SearchPlace.PLACE.createNavigationEvent(query, page - 1));
}
});
}
if (page > 7) {
SpanElement elipsis = Elements.createSpanElement(css.thispage());
elipsis.setTextContent("...");
getView().pager.appendChild(elipsis);
}
// page numbers are one-based (i.e. human-oriented)
for (int i = page > 6 ? page - 6 : 1; i < pageCount + 1 && i < page + 6; i++) {
SpanElement counter =
Elements.createSpanElement(i == page ? css.thispage() : css.otherpage());
counter.setTextContent(Integer.toString(i));
getView().pager.appendChild(counter);
final int pageNumber = i;
counter.setOnClick(new EventListener() {
@Override
public void handleEvent(Event evt) {
currentPlace.fireChildPlaceNavigation(
SearchPlace.PLACE.createNavigationEvent(query, pageNumber));
}
});
if (page + 7 < pageCount + 1) {
SpanElement elipsis = Elements.createSpanElement(css.thispage());
elipsis.setTextContent("...");
getView().pager.appendChild(elipsis);
}
}
if (page < pageCount) {
DivElement next = Elements.createDivElement(css.next());
getView().pager.appendChild(next);
next.setOnClick(new EventListener() {
@Override
public void handleEvent(Event evt) {
currentPlace.fireChildPlaceNavigation(
SearchPlace.PLACE.createNavigationEvent(query, page + 1));
}