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

br.com.jarch.faces.controller.AcessMenu Maven / Gradle / Ivy

package br.com.jarch.faces.controller;

import br.com.jarch.core.model.IAcessMenu;
import br.com.jarch.core.model.ItemMenuArch;
import br.com.jarch.core.model.type.ActionCrudType;

import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;

public class AcessMenu implements IAcessMenu {

    private final List menuActions;

    public AcessMenu() {
        menuActions = ItemMenuFactory.createMenuFromListAction(null);
    }

    public AcessMenu(IBaseListController controller) {
        menuActions = ItemMenuFactory.createMenuFromListAction(controller);
    }

    public AcessMenu(Field field) {
        menuActions = ItemMenuFactory.createMenuFromField(field);
    }

    @Override
    public List getMenuActions() {
        return Collections.unmodifiableList(menuActions);
    }

    @Override
    public void enableItemMenuActionDynamic(String id) {
        enableItemMenuAction(id);
    }

    @Override
    public void enableItemMenuAction(String id) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equalsIgnoreCase(id))
                .forEach(menu -> menu.setDisabled(false));
    }

    @Override
    public void showItemMenuActionDynamic(String id) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equalsIgnoreCase(id))
                .forEach(menu -> menu.setRendered(true));
    }

    @Override
    public void disableAllItemMenuActionDynamic() {
        menuActions
                .stream()
                .filter(ItemMenuArch::isDynamic)
                .forEach(menu -> menu.setDisabled(true));
    }

    @Override
    public void disableAllItemMenuActionPattern() {
        menuActions
                .stream()
                .filter(ItemMenuArch::isCrud)
                .forEach(menu -> menu.setDisabled(true));
    }

    @Override
    public void disableAllItemMenuAction() {
        menuActions
                .forEach(menu -> menu.setDisabled(true));
    }

    @Override
    public void enableAllItemMenuAction() {
        menuActions
                .forEach(menu -> menu.setDisabled(false));
    }

    @Override
    public void hideAllItemMenuActionDynamic() {
        menuActions
                .stream()
                .filter(ItemMenuArch::isDynamic)
                .forEach(menu -> menu.setRendered(false));

    }

    @Override
    public void hideAllItemMenuActionPattern() {
        menuActions
                .stream()
                .filter(menu -> menu.isChange() || menu.isClone() || menu.isConsult() || menu.isDelete())
                .forEach(menu -> menu.setRendered(false));
    }

    @Override
    public void hideAllItemMenuAction() {
        menuActions
                .forEach(menu -> menu.setRendered(false));
    }

    @Override
    public void showAllItemMenuAction() {
        menuActions
                .forEach(menu -> menu.setRendered(true));
    }

    @Override
    public boolean isDisabledInsert() {
        return menuActions
                .stream()
                .filter(ItemMenuArch::isInsert)
                .anyMatch(ItemMenuArch::isDisabled);
    }

    @Override
    public boolean isDisabledPrint() {
        return menuActions
                .stream()
                .filter(ItemMenuArch::isPrint)
                .anyMatch(ItemMenuArch::isDisabled);
    }

    @Override
    public boolean isVisibleInsert() {
        return menuActions
                .stream()
                .filter(ItemMenuArch::isInsert)
                .anyMatch(ItemMenuArch::isRendered);
    }

    @Override
    public boolean isVisiblePrint() {
        return menuActions
                .stream()
                .filter(ItemMenuArch::isPrint)
                .anyMatch(ItemMenuArch::isRendered);
    }

    @Override
    public void enableItemMenuAction(ActionCrudType actionCrudType) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equals(actionCrudType.getId()))
                .forEach(menu -> menu.setDisabled(false));
    }

    @Override
    public void disableItemMenuAction(ActionCrudType actionCrudType) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equals(actionCrudType.getId()))
                .forEach(menu -> menu.setDisabled(true));
    }

    @Override
    public void showItemMenuAction(String id) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equals(id))
                .forEach(menu -> menu.setRendered(true));
    }

    @Override
    public void showItemMenuAction(ActionCrudType actionCrudType) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equals(actionCrudType.getId()))
                .forEach(menu -> menu.setRendered(true));
    }

    @Override
    public void hideItemMenuAction(ActionCrudType actionCrudType) {
        menuActions
                .stream()
                .filter(menu -> menu.getId() != null && menu.getId().equals(actionCrudType.getId()))
                .forEach(menu -> menu.setRendered(false));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy