diff options
author | Artur Signell <artur@vaadin.com> | 2015-08-03 23:42:27 +0300 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-10-09 09:53:52 +0000 |
commit | 98f9c438d8d03c4dbc5d896ef245d252a166b9ed (patch) | |
tree | d0e5fbe545f6fc3fe5547888fcbf73294041fc61 /server/src/com | |
parent | a0637c8feb47dc4d83ce976a7c1db769238a6c95 (diff) | |
download | vaadin-framework-98f9c438d8d03c4dbc5d896ef245d252a166b9ed.tar.gz vaadin-framework-98f9c438d8d03c4dbc5d896ef245d252a166b9ed.zip |
Add Grid.deselectAll() (#18339)
Change-Id: I5d5237fcc06ae184a884cb17fa9b6eee5c37179a
Diffstat (limited to 'server/src/com')
-rw-r--r-- | server/src/com/vaadin/ui/Grid.java | 41 |
1 files changed, 41 insertions, 0 deletions
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 @@ -5280,6 +5280,47 @@ public class Grid extends AbstractFocusable implements SelectionNotifier, } /** + * Marks all items as unselected. + * <p> + * This method is a shorthand that delegates to the + * {@link #getSelectionModel() selection model}. Only + * {@link SelectionModel.Single} and {@link SelectionModel.Multi} are + * supported. + * + * @return <code>true</code> if the selection state changed, + * <code>false</code> 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. * <p> * <strong>Note:</strong> This is not a method that should be called by |