Skip to content

Commit

Permalink
Refine pagination logic and visibility bindings.
Browse files Browse the repository at this point in the history
Updated the logic for determining the visibility of the page size selector to account for available page sizes and total item count. Adjusted bindings to ensure more consistent and dynamic component visibility management in `PagingControlsSkin`. Fixed the condition for styling the last cell in `InnerListViewSkin`.
  • Loading branch information
dlemmermann committed Dec 12, 2024
1 parent e97248b commit f0bbf36
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void buildItems() {
cell.updateSelected(getSkinnable().getSelectionModel().isSelected(index));
content.getChildren().add(cell);

if (index == pagingListView.getPageSize() - 1) {
if (index == endIndex - 1) {
cell.getStyleClass().add("last");
}
}
Expand Down
29 changes: 27 additions & 2 deletions gemsfx/src/main/java/com/dlsc/gemsfx/skins/PagingControlsSkin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dlsc.gemsfx.Spacer;
import javafx.beans.InvalidationListener;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.BooleanBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.HPos;
Expand Down Expand Up @@ -99,10 +100,22 @@ private void createStaticElements() {
pageSizeSelectorLabel.visibleProperty().bind(pageSizeSelectorLabel.textProperty().isNotEmpty());
pageSizeSelectorLabel.managedProperty().bind(pageSizeSelectorLabel.textProperty().isNotEmpty());

/*
* We do not want to see the page size selector if the page sizes shown inside the selector are all bigger
* than the total amount of items.
*/
BooleanBinding moreItemsThanMinimumPageSize = Bindings.createBooleanBinding(() -> {
int smallestAvailablePageSize = view.getAvailablePageSizes().stream()
.min(Integer::compareTo)
.orElse(1);
int totalItemCount = view.getTotalItemCount();
return totalItemCount > smallestAvailablePageSize;
}, view.totalItemCountProperty(), view.availablePageSizesProperty());

pageSizeSelectorContainer = new HBox(pageSizeSelectorLabel, pageSizeSelector);
pageSizeSelectorContainer.getStyleClass().add("page-size-container");
pageSizeSelectorContainer.visibleProperty().bind(view.showPageSizeSelectorProperty().and(view.totalItemCountProperty().greaterThan(0)));
pageSizeSelectorContainer.managedProperty().bind(view.showPageSizeSelectorProperty().and(view.totalItemCountProperty().greaterThan(0)));
pageSizeSelectorContainer.visibleProperty().bind(view.showPageSizeSelectorProperty().and(view.totalItemCountProperty().greaterThan(0)).and(moreItemsThanMinimumPageSize));
pageSizeSelectorContainer.managedProperty().bind(pageSizeSelectorContainer.visibleProperty());

messageLabel = new Label();
messageLabel.getStyleClass().add("message-label");
Expand Down Expand Up @@ -172,6 +185,18 @@ private void createStaticElements() {
lastPageButton.disableProperty().bind(view.pageProperty().add(view.getMaxPageIndicatorsCount()).lessThan(view.getPageCount()).not());
lastPageButton.visibleProperty().bind(view.firstLastPageDisplayModeProperty().isEqualTo(PagingControls.FirstLastPageDisplayMode.SHOW_ARROW_BUTTONS).and(view.pageCountProperty().greaterThan(1)));
lastPageButton.setOnMouseClicked(evt -> view.setPage(view.getPageCount() - 1));

view.visibleProperty()
.bind(pageSizeSelectorContainer.visibleProperty()
.or(pageButtonsBox.visibleProperty())
.or(firstPageButton.visibleProperty())
.or(previousButton.visibleProperty())
.or(nextButton.visibleProperty())
.or(lastPageButton.visibleProperty())
.or(messageLabel.visibleProperty())
);

view.managedProperty().bind(view.visibleProperty());
}

private Node wrapIcon(Region region) {
Expand Down

0 comments on commit f0bbf36

Please sign in to comment.