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

org.bklab.crud.menu.FluentCrudMenuButton Maven / Gradle / Ivy

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

import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.contextmenu.ContextMenu;
import com.vaadin.flow.component.grid.Grid;
import org.bklab.crud.FluentCrudView;

import java.util.Objects;
import java.util.function.BiPredicate;
import java.util.function.Predicate;

public class FluentCrudMenuButton> {

    private final Button button;
    private final ContextMenu contextMenu;
    private final IFluentMenuBuilder menuEntityBiConsumer;
    private final FluentCrudView fluentCrudView;

    private T entity;

    public FluentCrudMenuButton(FluentCrudView fluentCrudView,
                                T entity, Button button, ContextMenu contextMenu,
                                IFluentMenuBuilder menuEntityBiConsumer) {
        this.fluentCrudView = fluentCrudView;
        this.entity = entity;
        this.button = button;
        this.contextMenu = contextMenu;
        this.menuEntityBiConsumer = menuEntityBiConsumer;
    }

    public void reload() {
        contextMenu.removeAll();
        if (menuEntityBiConsumer != null) {
            menuEntityBiConsumer.safeBuild(fluentCrudView, contextMenu, entity);
        }
    }

    public void reload(T entity) {
        this.reload(entity, t -> Objects.equals(t, entity));
    }

    public void reload(T entity, Predicate sameFunction) {
        if (!sameFunction.test(entity)) return;
        this.entity = entity;
        contextMenu.removeAll();
        if (menuEntityBiConsumer != null) {
            menuEntityBiConsumer.safeBuild(fluentCrudView, contextMenu, entity);
        }
    }

    public boolean isThisEntity(T entity, BiPredicate sameFunction) {
        return sameFunction == null
                ? Objects.equals(entity, this.entity)
                : sameFunction.test(entity, this.entity);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy