summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorAleksi Hietanen <aleksi@vaadin.com>2017-02-03 13:27:51 +0200
committerPekka Hyvönen <pekka@vaadin.com>2017-02-03 13:27:51 +0200
commit0a325d95a588010a6d5c511afddb8db8048d50ee (patch)
tree8c70dcd594140dd1734bdcefdff4e83413eb1f7d /server
parent8163c0c77d5c099ef89a255ca87129a1422cda70 (diff)
downloadvaadin-framework-0a325d95a588010a6d5c511afddb8db8048d50ee.tar.gz
vaadin-framework-0a325d95a588010a6d5c511afddb8db8048d50ee.zip
Add selection methods to grid that delegate to its selection model (#8315)
* Add selection methods to grid that delegate to the selection model * Merge remote-tracking branch 'github/master' into 577-alt * Remove getFirstSelected, isSelected
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/Grid.java46
-rw-r--r--server/src/test/java/com/vaadin/tests/components/grid/GridDelegatesToSelectionModelTest.java55
2 files changed, 99 insertions, 2 deletions
diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java
index 8e12b4a20b..f3dc3d9389 100644
--- a/server/src/main/java/com/vaadin/ui/Grid.java
+++ b/server/src/main/java/com/vaadin/ui/Grid.java
@@ -3045,6 +3045,50 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
}
/**
+ * This method is a shorthand that delegates to the currently set selection
+ * model.
+ *
+ * @see #getSelectionModel()
+ * @see GridSelectionModel
+ */
+ public Set<T> getSelectedItems() {
+ return getSelectionModel().getSelectedItems();
+ }
+
+ /**
+ * This method is a shorthand that delegates to the currently set selection
+ * model.
+ *
+ * @see #getSelectionModel()
+ * @see GridSelectionModel
+ */
+ public void select(T item) {
+ getSelectionModel().select(item);
+ }
+
+ /**
+ * This method is a shorthand that delegates to the currently set selection
+ * model.
+ *
+ * @see #getSelectionModel()
+ * @see GridSelectionModel
+ */
+ public void deselect(T item) {
+ getSelectionModel().deselect(item);
+ }
+
+ /**
+ * This method is a shorthand that delegates to the currently set selection
+ * model.
+ *
+ * @see #getSelectionModel()
+ * @see GridSelectionModel
+ */
+ public void deselectAll() {
+ getSelectionModel().deselectAll();
+ }
+
+ /**
* Adds a selection listener to the current selection model.
* <p>
* <em>NOTE:</em> If selection mode is switched with
@@ -3621,7 +3665,6 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
*
* @return the comparator based on column sorting information.
*/
-
protected SerializableComparator<T> createSortingComparator() {
BinaryOperator<SerializableComparator<T>> operator = (comparator1,
comparator2) -> SerializableComparator
@@ -3631,5 +3674,4 @@ public class Grid<T> extends AbstractListing<T> implements HasComponents,
order -> order.getSorted().getComparator(order.getDirection()))
.reduce((x, y) -> 0, operator);
}
-
}
diff --git a/server/src/test/java/com/vaadin/tests/components/grid/GridDelegatesToSelectionModelTest.java b/server/src/test/java/com/vaadin/tests/components/grid/GridDelegatesToSelectionModelTest.java
new file mode 100644
index 0000000000..ae121d2e03
--- /dev/null
+++ b/server/src/test/java/com/vaadin/tests/components/grid/GridDelegatesToSelectionModelTest.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.grid;
+
+import static org.mockito.Mockito.verify;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import com.vaadin.ui.Grid;
+import com.vaadin.ui.components.grid.GridSelectionModel;
+
+public class GridDelegatesToSelectionModelTest {
+
+ private GridSelectionModel<String> selectionModelMock;
+
+ private CustomGrid grid;
+
+ private class CustomGrid extends Grid<String> {
+ CustomGrid() {
+ super();
+ setSelectionModel(selectionModelMock);
+ }
+ }
+
+ @Before
+ @SuppressWarnings("unchecked")
+ public void init() {
+ selectionModelMock = Mockito.mock(GridSelectionModel.class);
+ grid = new CustomGrid();
+ }
+
+ @Test
+ public void grid_getSelectedItems_delegated_to_SelectionModel() {
+ grid.getSelectedItems();
+ verify(selectionModelMock).getSelectedItems();
+ }
+
+ @Test
+ public void grid_select_delegated_to_SelectionModel() {
+ grid.select("");
+ verify(selectionModelMock).select("");
+ }
+
+ @Test
+ public void grid_deselect_delegated_to_SelectionModel() {
+ grid.deselect("");
+ verify(selectionModelMock).deselect("");
+ }
+
+ @Test
+ public void grid_deselectAll_delegated_to_SelectionModel() {
+ grid.deselectAll();
+ verify(selectionModelMock).deselectAll();
+ }
+}