From 98f9c438d8d03c4dbc5d896ef245d252a166b9ed Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 3 Aug 2015 23:42:27 +0300 Subject: Add Grid.deselectAll() (#18339) Change-Id: I5d5237fcc06ae184a884cb17fa9b6eee5c37179a --- client/src/com/vaadin/client/widgets/Grid.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'client') diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index e01edcddd7..db7b25720e 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -151,6 +151,7 @@ import com.vaadin.client.widget.grid.selection.SelectionEvent; import com.vaadin.client.widget.grid.selection.SelectionHandler; import com.vaadin.client.widget.grid.selection.SelectionModel; import com.vaadin.client.widget.grid.selection.SelectionModel.Multi; +import com.vaadin.client.widget.grid.selection.SelectionModel.Single; import com.vaadin.client.widget.grid.selection.SelectionModelMulti; import com.vaadin.client.widget.grid.selection.SelectionModelNone; import com.vaadin.client.widget.grid.selection.SelectionModelSingle; @@ -7513,6 +7514,31 @@ public class Grid extends ResizeComposite implements } } + /** + * Deselect all rows using the current selection model. + * + * @param row + * a row object + * @return true iff the current selection changed + * @throws IllegalStateException + * if the current selection model is not an instance of + * {@link SelectionModel.Single} or {@link SelectionModel.Multi} + */ + public boolean deselectAll() { + if (selectionModel instanceof SelectionModel.Single) { + Single single = ((SelectionModel.Single) selectionModel); + if (single.getSelectedRow() != null) { + return single.deselect(single.getSelectedRow()); + } else { + return false; + } + } else if (selectionModel instanceof SelectionModel.Multi) { + return ((SelectionModel.Multi) selectionModel).deselectAll(); + } else { + throw new IllegalStateException("Unsupported selection model"); + } + } + /** * Gets last selected row from the current SelectionModel. *

-- cgit v1.2.3