% pagination.getResultsPerPage() != 0) {
totalPages++;
}
// Previous Page
Hyperlink previousPageLink = new Hyperlink(previousPageText,
"previousPage");
pagingControls[i].setWidget(0, 0, previousPageLink);
if (pagination.getPage() == 1
|| pagination.getResults().getSize() == 0) {
pagingControls[i].getCellFormatter().addStyleName(0, 0,
"noPreviousPageCell");
} else {
previousPageLink.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
pagination.showPage(pagination.getPage() - 1);
}
});
pagingControls[i].getCellFormatter().addStyleName(0, 0,
"previousPageCell");
}
// Pages
int currentPageForCell = 1;
int totalCells = totalPages;
if (totalPages > maxPageLinks) {
totalCells = maxPageLinks;
if (pagination.getPage() > maxPageLinks / 2) {
currentPageForCell = pagination.getPage()
- (maxPageLinks / 2);
if (pagination.getPage() >= totalPages
- (maxPageLinks / 2)) {
currentPageForCell = totalPages
- (maxPageLinks - 1);
}
}
}
int cellNumber = 1;
for (; cellNumber <= totalCells; cellNumber++) {
Hyperlink pageLink = new Hyperlink(currentPageForCell + "",
"page");
pagingControls[i].setWidget(0, cellNumber, pageLink);
final int tmp = currentPageForCell;
if (pagination.getPage() != currentPageForCell) {
pageLink.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
pagination.showPage(tmp);
}
});
pagingControls[i].getCellFormatter().addStyleName(0,
cellNumber, "pageCell");
} else {
pagingControls[i].getCellFormatter().addStyleName(0,
cellNumber, "currentPageCell");
}
currentPageForCell++;
}
// Next Page
Hyperlink nextPageLink = new Hyperlink(nextPageText, "nextPage");
pagingControls[i].setWidget(0, cellNumber, nextPageLink);
if (pagination.getPage() == totalPages
|| pagination.getResults().getSize() == 0) {
pagingControls[i].getCellFormatter().addStyleName(0,
cellNumber, "noNextPageCell");
} else {
nextPageLink.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
pagination.showPage(pagination.getPage() + 1);
}
});