Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Dec 19, 2024
1 parent cbc6d5f commit b224e44
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,32 @@ public GridRangeSelection() {
.addClientItemToggleListener(event -> {
Person item = event.getItem();

// If the anchor point isn't set, set it to the current item
startItem = startItem != null ? startItem : item;

if (event.isShiftKey()) {
// Calculcate the range of items between the anchor point and
// the current item
int startIndex = grid.getListDataView().getItemIndex(startItem).get();
int endIndex = grid.getListDataView().getItemIndex(endItem).get();
Set<Person> rangeItems = grid.getListDataView().getItems().skip(Math.min(startIndex, endIndex)).limit(Math.abs(startIndex - endIndex) + 1).collect(Collectors.toSet());

// Update the selection state of the items within the range
// based on the state of the current item
if (event.isSelected()) {
grid.asMultiSelect().select(rangeItems);
} else {
grid.asMultiSelect().deselect(rangeItems);
}
}

// Update the anchor point to the current item
startItem = item;
});
// end::snippet[]

add(grid);
}

// tag::snippet2[]
private <T> Set<T> fetchItemsRange(Grid<T> grid, T startItem, T endItem) {

}
// end::snippet2[]

public static class Exporter // hidden-source-line
extends DemoExporter<GridRangeSelection> { // hidden-source-line
} // hidden-source-line
Expand Down

0 comments on commit b224e44

Please sign in to comment.