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 --- server/src/com/vaadin/ui/Grid.java | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/ui/Grid.java b/server/src/com/vaadin/ui/Grid.java index 8d8b0fe8e3..d44cb31cb0 100644 --- a/server/src/com/vaadin/ui/Grid.java +++ b/server/src/com/vaadin/ui/Grid.java @@ -5279,6 +5279,47 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } } + /** + * Marks all items as unselected. + *

+ * This method is a shorthand that delegates to the + * {@link #getSelectionModel() selection model}. Only + * {@link SelectionModel.Single} and {@link SelectionModel.Multi} are + * supported. + * + * @return true if the selection state changed, + * false if the itemId was already selected + * @throws IllegalStateException + * if the deselection was illegal. One such reason might be that + * the implementation requires one or more items to be selected + * at all times. + * @throws IllegalStateException + * if the selection model does not implement + * {@code SelectionModel.Single} or {code SelectionModel.Multi} + */ + public boolean deselectAll() throws IllegalStateException { + if (selectionModel instanceof SelectionModel.Single) { + if (getSelectedRow() != null) { + return deselect(getSelectedRow()); + } + return false; + } else if (selectionModel instanceof SelectionModel.Multi) { + return ((SelectionModel.Multi) selectionModel).deselectAll(); + } else if (selectionModel instanceof SelectionModel.None) { + throw new IllegalStateException("Cannot deselect all rows" + + ": Grid selection is disabled " + + "(the current selection model is " + + selectionModel.getClass().getName() + ")."); + } else { + throw new IllegalStateException("Cannot deselect all rows:" + + " Grid selection model does not implement " + + SelectionModel.Single.class.getName() + " or " + + SelectionModel.Multi.class.getName() + + "(the current model is " + + selectionModel.getClass().getName() + ")."); + } + } + /** * Fires a selection change event. *

-- cgit v1.2.3