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

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

package org.bklab.crud.grid;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.data.binder.Binder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class FluentGridItem {
    private static final Logger logger = LoggerFactory.getLogger(FluentGridItem.class);
    private final T entity;
    private final C component;
    private final FluentColumnRender render;

    public FluentGridItem(T entity, C component, FluentColumnRender render) {
        this.entity = entity;
        this.component = component;
        this.render = render;
    }

    public static  C registered(
            T entity,
            FluentColumnRender render,
            List> container,
            Map, FluentGridItem>> map,
            Map> binderMap
    ) {
        C c = render.createComponent(entity);
        FluentGridItem fluentGridItem = new FluentGridItem<>(entity, c, render);
        container.add(fluentGridItem);
        map.computeIfAbsent(entity, k -> new LinkedHashMap<>()).put(render, fluentGridItem);
        Optional.ofNullable(render.getBinderConsumer())
                .flatMap(binderConsumer -> Optional.ofNullable(render.getBinderConsumer()))
                .ifPresent(b -> b.accept(binderMap.computeIfAbsent(entity, k -> new Binder<>()), c));
        return c;
    }

    public void writeComponent() {
        render.writeComponent(entity, component);
    }

    public void writeEntity() {
        render.writeEntity(entity, component);
    }

    public boolean match(T entity) {
        return this.entity == entity;
    }

    public boolean match(T entity, FluentColumnRender render) {
        return this.entity == entity && this.render == render;
    }

    public C getComponent() {
        return component;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy