Skip to content

Commit

Permalink
Fix item caption/label configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rrighi committed Aug 28, 2019
1 parent e93d938 commit 0fce1d4
Showing 1 changed file with 36 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -105,6 +106,7 @@ public class DefaultSingleSelectInputBuilder<T, ITEM>
protected final Map<ITEM, Localizable> itemCaptions = new HashMap<>();

protected boolean customItemCaptionGenerator = false;
protected boolean customItemLabelGenerator = false;

/**
* Constructor.
Expand Down Expand Up @@ -229,6 +231,39 @@ public SingleSelectInputBuilder<T, ITEM> renderer(ComponentRenderer<? extends Co
return getConfigurator();
}

/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.flow.components.builders.SelectModeSingleSelectInputBuilder#itemCaptionGenerator(com.
* holonplatform.vaadin.flow.components.ItemSet.ItemCaptionGenerator)
*/
@Override
public SingleSelectInputBuilder<T, ITEM> itemCaptionGenerator(ItemCaptionGenerator<ITEM> 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<T, ITEM> 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
Expand All @@ -239,6 +274,7 @@ public SingleSelectInputBuilder<T, ITEM> renderer(ComponentRenderer<? extends Co
public SingleSelectInputBuilder<T, ITEM> itemLabelGenerator(Function<ITEM, String> itemLabelGenerator) {
ObjectUtils.argumentNotNull(itemLabelGenerator, "Item label generator must be not null");
getComponent().setItemLabelGenerator(item -> itemLabelGenerator.apply(item));
this.customItemLabelGenerator = true;
return getConfigurator();
}

Expand Down Expand Up @@ -318,36 +354,6 @@ public SingleSelectInputBuilder<T, ITEM> itemEnabledProvider(Predicate<ITEM> ite
return getConfigurator();
}

/*
* (non-Javadoc)
* @see
* com.holonplatform.vaadin.flow.components.builders.SelectModeSingleSelectInputBuilder#itemCaptionGenerator(com.
* holonplatform.vaadin.flow.components.ItemSet.ItemCaptionGenerator)
*/
@Override
public SingleSelectInputBuilder<T, ITEM> itemCaptionGenerator(ItemCaptionGenerator<ITEM> 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<T, ITEM> 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[])
Expand Down

0 comments on commit 0fce1d4

Please sign in to comment.