com.vaadin.flow.component.ItemLabelGenerator Java Examples

The following examples show how to use com.vaadin.flow.component.ItemLabelGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IconRenderer.java    From flow with Apache License 2.0 6 votes vote down vote up
@Override
public Component createComponent(ITEM item) {
    Component icon = iconGenerator.apply(item);
    if (icon == null) {
        throw new IllegalStateException(String.format(
                "Got 'null' as an icon for the item '%s'. "
                        + "Icon generator instance may not return 'null' values",
                item));
    }
    String text = itemLabelGenerator.apply(item);
    if (text == null) {
        throw new IllegalStateException(String.format(
                "Got 'null' as a label value for the item '%s'. "
                        + "'%s' instance may not return 'null' values",
                item, ItemLabelGenerator.class.getSimpleName()));
    }
    IconComponent component = new IconComponent();
    component.add(icon);
    component.add(new IconComponent(text));
    return component;
}
 
Example #2
Source File: MultiselectComboBox.java    From multiselect-combo-box-flow with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the item label generator that is used to produce the strings shown
 * in the multiselect-combo-box for each item. By default,
 * {@link String#valueOf(Object)} is used.
 *
 * @param itemLabelGenerator
 *            the item label provider to use, not null
 */
public void setItemLabelGenerator(
        ItemLabelGenerator<T> itemLabelGenerator) {
    Objects.requireNonNull(itemLabelGenerator,
            "The item label generator can not be null");
    this.itemLabelGenerator = itemLabelGenerator;
    reset();
    if (getValue() != null) {
        refreshValue();
    }
}
 
Example #3
Source File: MultiselectComboBox.java    From multiselect-combo-box-flow with Apache License 2.0 5 votes vote down vote up
private String generateLabel(T item) {
    if (item == null) {
        return "";
    }
    String label = getItemLabelGenerator().apply(item);
    if (label == null) {
        throw new IllegalStateException(String.format(
                "Got 'null' as a label value for the item '%s'. "
                        + "'%s' instance may not return 'null' values",
                item, ItemLabelGenerator.class.getSimpleName()));
    }
    return label;
}
 
Example #4
Source File: TextRenderer.java    From flow with Apache License 2.0 5 votes vote down vote up
@Override
public Component createComponent(ITEM item) {
    String text = itemLabelGenerator.apply(item);
    if (text == null) {
        throw new IllegalStateException(String.format(
                "Got 'null' as a label value for the item '%s'. "
                        + "'%s' instance may not return 'null' values",
                item, ItemLabelGenerator.class.getSimpleName()));
    }
    return new TextRendererComponent(createElement(text));
}
 
Example #5
Source File: CheckBoxGroupProvider.java    From crudui with Apache License 2.0 4 votes vote down vote up
public CheckBoxGroupProvider(String caption, Collection<T> items, ItemLabelGenerator<T> itemLabelGenerator) {
    super(caption, items);
    this.itemLabelGenerator = itemLabelGenerator;
}
 
Example #6
Source File: ComboBoxProvider.java    From crudui with Apache License 2.0 4 votes vote down vote up
public ComboBoxProvider(String caption, Collection<T> items, ComponentRenderer<? extends Component, T> renderer, ItemLabelGenerator<T> itemLabelGenerator) {
    super(caption, items, renderer);
    this.itemLabelGenerator = itemLabelGenerator;
}
 
Example #7
Source File: IconRenderer.java    From flow with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new renderer instance using the provided {@code iconGenerator}
 * and {@code itemLabelGenerator}.
 *
 * @param iconGenerator
 *            the icon component generator
 * @param itemLabelGenerator
 *            the item label generator
 */
public IconRenderer(
        SerializableFunction<ITEM, ? extends Component> iconGenerator,
        ItemLabelGenerator<ITEM> itemLabelGenerator) {
    this.iconGenerator = iconGenerator;
    this.itemLabelGenerator = itemLabelGenerator;
}
 
Example #8
Source File: MultiselectComboBox.java    From multiselect-combo-box-flow with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the item label generator.
 *
 * By default, {@link String#valueOf(Object)} is used.
 *
 * @return the item label generator.
 */
public ItemLabelGenerator<T> getItemLabelGenerator() {
    return itemLabelGenerator;
}
 
Example #9
Source File: TextRenderer.java    From flow with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new renderer instance using the provided
 * {@code itemLabelGenerator}.
 *
 * @param itemLabelGenerator
 *            the item label generator
 */
public TextRenderer(ItemLabelGenerator<ITEM> itemLabelGenerator) {
    this.itemLabelGenerator = itemLabelGenerator;
}