All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bklab.flow.factory.SelectFactory Maven / Gradle / Ivy

There is a newer version: 22.0.1
Show newest version
package org.bklab.flow.factory;

import com.vaadin.flow.component.AbstractField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasValue;
import com.vaadin.flow.component.ItemLabelGenerator;
import com.vaadin.flow.component.select.Select;
import com.vaadin.flow.component.select.data.SelectDataView;
import com.vaadin.flow.component.select.data.SelectListDataView;
import com.vaadin.flow.data.provider.DataProvider;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.function.SerializablePredicate;
import org.bklab.flow.FlowFactory;
import org.bklab.flow.base.*;

public class SelectFactory extends FlowFactory, SelectFactory> implements
        GeneratedVaadinSelectFactory, SelectFactory>,
        HasSizeFactory, SelectFactory>,
        HasListDataViewFactory, Select, SelectFactory>,
        HasDataViewFactory, Select, SelectFactory>,
        HasValidationFactory, SelectFactory>,
        HasHelperFactory, SelectFactory>,
        SingleSelectFactory, SelectFactory> {

    public SelectFactory() {
        this(new Select<>());
    }

    @SafeVarargs
    public SelectFactory(T... items) {
        this(new Select<>(items));
    }

    public SelectFactory(Select component) {
        super(component);
    }

    @Override
    public SelectFactory value(T value) {
        get().setValue(value);
        return this;
    }

    @Override
    public SelectFactory valueChangeListener(HasValue.ValueChangeListener, T>> valueChangeListener) {
        get().addValueChangeListener(valueChangeListener);
        return this;
    }

    public SelectFactory add(Component... add) {
        get().add(add);
        return this;
    }

    public SelectFactory remove(Component... remove) {
        get().remove(remove);
        return this;
    }

    public SelectFactory removeAll() {
        get().removeAll();
        return this;
    }

    public SelectFactory emptySelectionCaption(String emptySelectionCaption) {
        get().setEmptySelectionCaption(emptySelectionCaption);
        return this;
    }

    public SelectFactory itemEnabledProvider(SerializablePredicate itemEnabledProvider) {
        get().setItemEnabledProvider(itemEnabledProvider);
        return this;
    }

    public SelectFactory emptySelectionAllowed(boolean emptySelectionAllowed) {
        get().setEmptySelectionAllowed(emptySelectionAllowed);
        return this;
    }

    public SelectFactory itemLabelGenerator(ItemLabelGenerator itemLabelGenerator) {
        get().setItemLabelGenerator(i -> i == null ? get().getEmptySelectionCaption() : itemLabelGenerator.apply(i));
        return this;
    }

    public SelectFactory itemLabelGenerator(ItemLabelGenerator itemLabelGenerator, String DefaultValue) {
        get().setItemLabelGenerator(i -> i == null ? DefaultValue : itemLabelGenerator.apply(i));
        return this;
    }

    public SelectFactory componentAtIndex(int index, Component component) {
        get().addComponentAtIndex(index, component);
        return this;
    }

    public SelectFactory componentAsFirst(Component componentAsFirst) {
        get().addComponentAsFirst(componentAsFirst);
        return this;
    }

    public SelectFactory prependComponents(T beforeItem, Component... components) {
        get().prependComponents(beforeItem, components);
        return this;
    }

    @Deprecated
    public SelectFactory dataProvider(DataProvider dataProvider) {
        get().setDataProvider(dataProvider);
        return this;
    }

    public SelectFactory components(T afterItem, Component... components) {
        get().addComponents(afterItem, components);
        return this;
    }

    public SelectFactory errorMessage(String errorMessage) {
        get().setErrorMessage(errorMessage);
        return this;
    }

    public SelectFactory invalid(boolean invalid) {
        get().setInvalid(invalid);
        return this;
    }

    public SelectFactory requiredIndicatorVisible(boolean requiredIndicatorVisible) {
        get().setRequiredIndicatorVisible(requiredIndicatorVisible);
        return this;
    }

    public SelectFactory placeholder(String placeholder) {
        get().setPlaceholder(placeholder);
        return this;
    }

    public SelectFactory renderer(ComponentRenderer renderer) {
        get().setRenderer(renderer);
        return this;
    }

    public SelectFactory autofocus(boolean autofocus) {
        get().setAutofocus(autofocus);
        return this;
    }

    public SelectFactory label(String label) {
        get().setLabel(label);
        return this;
    }

    public SelectFactory textRenderer(ItemLabelGenerator textRenderer) {
        get().setTextRenderer(textRenderer);
        return this;
    }

    public SelectFactory toPrefix(Component... toPrefix) {
        get().addToPrefix(toPrefix);
        return this;
    }

    public SelectFactory lumoSmall() {
        get().getElement().setAttribute("theme", "small");
        get().getStyle().set("margin-top", "auto 0").set("margin-bottom", "auto 0");
        return this;
    }

    public SelectFactory lumoSmall30pxHeight() {
        get().getElement().setAttribute("theme", "small");
        get().getStyle().set("height", "30px")
                .set("margin-top", "auto 0").set("margin-bottom", "auto 0");
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy