class EntitiesList implements IsWidget {

    protected PaginationConstraints createPaginationCallback(final AbstractEntityManager.SearchResponse searchResponse) {
        if (searchResponse != null) {
            final int page = searchResponse.getPage();
            final int total = searchResponse.getTotal();

            // If the SPI is able to get max row count, calculate total pages.
            final int totalPagesRounded = (int) Math.ceil(total / (double) searchResponse.getPageSize());
            EntitiesList.this.totalPages = total > -1 ? total / searchResponse.getPageSize() : -1;
            final boolean hasNextPage = totalPages > -1 ? page < totalPagesRounded : searchResponse.hasNextPage();
            final boolean notInFistPage = page > 1;
            final boolean isLastPageButtonEnabled = EntitiesList.this.totalPages > -1 && hasNextPage;

            return (new PaginationConstraints() {

                @Override
                public boolean isFirstPageEnabled() {
                    return notInFistPage;
                }

                @Override
                public boolean isFirstPageVisible() {
                    return notInFistPage;
                }

                @Override
                public boolean isPrevPageEnabled() {
                    return notInFistPage;
                }

                @Override
                public boolean isPrevPageVisible() {
                    return notInFistPage;
                }

                @Override
                public int getCurrentPage() {
                    return page;
                }

                @Override
                public boolean isNextPageEnabled() {
                    return hasNextPage;
                }

                @Override
                public boolean isNextPageVisible() {
                    return hasNextPage;
                }

                @Override
                public boolean isLastPageEnabled() {
                    return isLastPageButtonEnabled;
                }

                @Override
                public boolean isLastPageVisible() {
                    return isLastPageButtonEnabled;
                }

                @Override
                public Integer getTotal() {
                    return total > -1 ? total : null;
                }
            });
        }
        return null;
    }

    @Inject public  EntitiesList(LoadingBox loadingBox,
                        View view);

}