From 175154e1acac7e50828167c14c199c3a66772172 Mon Sep 17 00:00:00 2001 From: Sergey Vinogradov Date: Thu, 19 Dec 2024 15:51:18 +0400 Subject: [PATCH] polish --- .../vaadin/demo/component/grid/GridRangeSelection.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/vaadin/demo/component/grid/GridRangeSelection.java b/src/main/java/com/vaadin/demo/component/grid/GridRangeSelection.java index cfb316a525..48b2938610 100644 --- a/src/main/java/com/vaadin/demo/component/grid/GridRangeSelection.java +++ b/src/main/java/com/vaadin/demo/component/grid/GridRangeSelection.java @@ -19,6 +19,7 @@ public class GridRangeSelection extends Div { private Person startItem; public GridRangeSelection() { + // tag::snippet[] Grid grid = new Grid<>(Person.class, false); grid.addColumn(Person::getFirstName).setHeader("First name"); grid.addColumn(Person::getLastName).setHeader("Last name"); @@ -27,7 +28,6 @@ public GridRangeSelection() { List people = DataService.getPeople(); grid.setItems(people); - // tag::snippet[] grid.setSelectionMode(Grid.SelectionMode.MULTI); ((GridMultiSelectionModel) grid.getSelectionModel()) .addClientItemToggleListener(event -> { @@ -39,9 +39,10 @@ public GridRangeSelection() { 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 rangeItems = grid.getListDataView().getItems().skip(Math.min(startIndex, endIndex)).limit(Math.abs(startIndex - endIndex) + 1).collect(Collectors.toSet()); + GridListDataView dataView = grid.getListDataView(); + int startIndex = dataView.getItemIndex(startItem).get(); + int endIndex = dataView.getItemIndex(endItem).get(); + Set rangeItems = dataView.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 @@ -56,6 +57,7 @@ public GridRangeSelection() { startItem = item; }); // end::snippet[] + add(grid); }