From 0fce1d47dc103d31033d138132fa61d6a0684a87 Mon Sep 17 00:00:00 2001 From: Riccardo Righi Date: Wed, 28 Aug 2019 14:29:05 +0200 Subject: [PATCH] Fix item caption/label configuration --- .../DefaultSingleSelectInputBuilder.java | 66 ++++++++++--------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/com/holonplatform/vaadin/flow/internal/components/builders/DefaultSingleSelectInputBuilder.java b/core/src/main/java/com/holonplatform/vaadin/flow/internal/components/builders/DefaultSingleSelectInputBuilder.java index 7f3bbc96..2541a052 100644 --- a/core/src/main/java/com/holonplatform/vaadin/flow/internal/components/builders/DefaultSingleSelectInputBuilder.java +++ b/core/src/main/java/com/holonplatform/vaadin/flow/internal/components/builders/DefaultSingleSelectInputBuilder.java @@ -74,6 +74,7 @@ import com.vaadin.flow.data.provider.ListDataProvider; import com.vaadin.flow.data.provider.QuerySortOrder; import com.vaadin.flow.data.renderer.ComponentRenderer; +import com.vaadin.flow.data.renderer.TextRenderer; import com.vaadin.flow.dom.DomEventListener; import com.vaadin.flow.dom.Element; @@ -105,6 +106,7 @@ public class DefaultSingleSelectInputBuilder protected final Map itemCaptions = new HashMap<>(); protected boolean customItemCaptionGenerator = false; + protected boolean customItemLabelGenerator = false; /** * Constructor. @@ -229,6 +231,39 @@ public SingleSelectInputBuilder renderer(ComponentRenderer itemCaptionGenerator(ItemCaptionGenerator itemCaptionGenerator) { + ObjectUtils.argumentNotNull(itemCaptionGenerator, "ItemCaptionGenerator must be not null"); + getComponent().setRenderer(new TextRenderer<>(item -> itemCaptionGenerator.getItemCaption(item))); + this.customItemCaptionGenerator = true; + if (!customItemLabelGenerator) { + getComponent().setItemLabelGenerator(item -> itemCaptionGenerator.getItemCaption(item)); + } + return getConfigurator(); + } + + /* + * (non-Javadoc) + * @see com.holonplatform.vaadin.flow.components.builders.SelectModeSingleSelectInputBuilder#itemCaption(java.lang. + * Object, com.holonplatform.core.i18n.Localizable) + */ + @Override + public SingleSelectInputBuilder itemCaption(ITEM item, Localizable caption) { + ObjectUtils.argumentNotNull(item, "Item must be not null"); + if (caption == null) { + itemCaptions.remove(item); + } else { + itemCaptions.put(item, caption); + } + return getConfigurator(); + } + /* * (non-Javadoc) * @see @@ -239,6 +274,7 @@ public SingleSelectInputBuilder renderer(ComponentRenderer itemLabelGenerator(Function itemLabelGenerator) { ObjectUtils.argumentNotNull(itemLabelGenerator, "Item label generator must be not null"); getComponent().setItemLabelGenerator(item -> itemLabelGenerator.apply(item)); + this.customItemLabelGenerator = true; return getConfigurator(); } @@ -318,36 +354,6 @@ public SingleSelectInputBuilder itemEnabledProvider(Predicate ite return getConfigurator(); } - /* - * (non-Javadoc) - * @see - * com.holonplatform.vaadin.flow.components.builders.SelectModeSingleSelectInputBuilder#itemCaptionGenerator(com. - * holonplatform.vaadin.flow.components.ItemSet.ItemCaptionGenerator) - */ - @Override - public SingleSelectInputBuilder itemCaptionGenerator(ItemCaptionGenerator itemCaptionGenerator) { - ObjectUtils.argumentNotNull(itemCaptionGenerator, "ItemCaptionGenerator must be not null"); - getComponent().setTextRenderer(item -> itemCaptionGenerator.getItemCaption(item)); - this.customItemCaptionGenerator = true; - return getConfigurator(); - } - - /* - * (non-Javadoc) - * @see com.holonplatform.vaadin.flow.components.builders.SelectModeSingleSelectInputBuilder#itemCaption(java.lang. - * Object, com.holonplatform.core.i18n.Localizable) - */ - @Override - public SingleSelectInputBuilder itemCaption(ITEM item, Localizable caption) { - ObjectUtils.argumentNotNull(item, "Item must be not null"); - if (caption == null) { - itemCaptions.remove(item); - } else { - itemCaptions.put(item, caption); - } - return getConfigurator(); - } - /* * (non-Javadoc) * @see com.holonplatform.vaadin.flow.components.builders.HasDataProviderConfigurator#items(java.lang.Object[])