diff options
author | Denis <denis@vaadin.com> | 2017-01-27 15:44:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-27 15:44:03 +0200 |
commit | 9ef479303bb514622ef90d95b94d912780c1812d (patch) | |
tree | fd6929a4b396cb6b1ff290ded4e129cd60415d60 /server/src/main/java | |
parent | 5616216306a138b3437d188e4b2df8253590abf5 (diff) | |
download | vaadin-framework-9ef479303bb514622ef90d95b94d912780c1812d.tar.gz vaadin-framework-9ef479303bb514622ef90d95b94d912780c1812d.zip |
Introduce empty selection functionality for NativeSelect. (#8336)
* Introduce empty selection functionality for NativeSelect.
Fixes vaadin/framework8-issues#545
Diffstat (limited to 'server/src/main/java')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/NativeSelect.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/NativeSelect.java b/server/src/main/java/com/vaadin/ui/NativeSelect.java index 9ae3409b66..f7427568ff 100644 --- a/server/src/main/java/com/vaadin/ui/NativeSelect.java +++ b/server/src/main/java/com/vaadin/ui/NativeSelect.java @@ -17,6 +17,7 @@ package com.vaadin.ui; import java.util.Collection; +import java.util.Objects; import com.vaadin.data.HasDataProvider; import com.vaadin.data.provider.DataProvider; @@ -139,4 +140,59 @@ public class NativeSelect<T> extends AbstractSingleSelect<T> public ItemCaptionGenerator<T> getItemCaptionGenerator() { return super.getItemCaptionGenerator(); } + + /** + * Returns whether the user is allowed to select nothing in the combo box. + * + * @return true if empty selection is allowed, false otherwise + */ + public boolean isEmptySelectionAllowed() { + return getState(false).emptySelectionAllowed; + } + + /** + * Sets whether the user is allowed to select nothing in the combo box. When + * true, a special empty item is shown to the user. + * + * @param emptySelectionAllowed + * true to allow not selecting anything, false to require + * selection + */ + public void setEmptySelectionAllowed(boolean emptySelectionAllowed) { + getState().emptySelectionAllowed = emptySelectionAllowed; + } + + /** + * Returns the empty selection caption. + * <p> + * The empty string {@code ""} is the default empty selection caption. + * + * @see #setEmptySelectionAllowed(boolean) + * @see #isEmptySelectionAllowed() + * @see #setEmptySelectionCaption(String) + * @see #isSelected(Object) + * + * @return the empty selection caption, not {@code null} + */ + public String getEmptySelectionCaption() { + return getState(false).emptySelectionCaption; + } + + /** + * Sets the empty selection caption. + * <p> + * The empty string {@code ""} is the default empty selection caption. + * <p> + * If empty selection is allowed via the + * {@link #setEmptySelectionAllowed(boolean)} method (it is by default) then + * the empty item will be shown with the given caption. + * + * @param caption + * the caption to set, not {@code null} + * @see #isSelected(Object) + */ + public void setEmptySelectionCaption(String caption) { + Objects.nonNull(caption); + getState().emptySelectionCaption = caption; + } } |