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

org.bklab.crud.grid.FluentColumnRender Maven / Gradle / Ivy

There is a newer version: 22.0.1
Show newest version
package org.bklab.crud.grid;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.function.ValueProvider;

import java.util.function.BiConsumer;

public class FluentColumnRender {

    private final String id;
    private final String name;
    private final ValueProvider componentProvider;
    private BiConsumer writeComponentConsumer;
    private BiConsumer writeEntityConsumer;
    private BiConsumer, C> binderConsumer;

    public FluentColumnRender(String id, String name, ValueProvider supplier) {
        this.id = id;
        this.name = name;
        this.componentProvider = supplier;
    }

    public FluentColumnRender binderConsumer(BiConsumer, C> binderConsumer) {
        this.binderConsumer = binderConsumer;
        return this;
    }

    public C createComponent(T entity) {
        return componentProvider.apply(entity);
    }

    public void writeEntity(T entity, Component c) {
        if (writeEntityConsumer != null)
            //noinspection unchecked
            writeEntityConsumer.accept(entity, (C) c);
    }

    public void writeComponent(T entity, Component c) {
        if (writeComponentConsumer != null)
            //noinspection unchecked
            writeComponentConsumer.accept(entity, (C) c);
    }

    public BiConsumer, C> getBinderConsumer() {
        return binderConsumer;
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public ValueProvider getComponentProvider() {
        return componentProvider;
    }

    public BiConsumer getWriteComponentConsumer() {
        return writeComponentConsumer;
    }

    public FluentColumnRender setWriteComponentConsumer(BiConsumer writeComponentConsumer) {
        this.writeComponentConsumer = writeComponentConsumer;
        return this;
    }

    public BiConsumer getWriteEntityConsumer() {
        return writeEntityConsumer;
    }

    public FluentColumnRender setWriteEntityConsumer(BiConsumer writeEntityConsumer) {
        this.writeEntityConsumer = writeEntityConsumer;
        return this;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy