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

br.com.jarch.faces.menu.BaseMenuController Maven / Gradle / Ivy

package br.com.jarch.faces.menu;

import br.com.jarch.core.crud.menu.IMenu;
import br.com.jarch.faces.util.JsfUtils;
import br.com.jarch.util.CharacterUtils;

import java.io.Serializable;
import java.util.List;

public abstract class BaseMenuController implements IBaseMenuController, Serializable {

    public abstract List createMenu();

    public String getMenuXhtml() {
        StringBuilder sbMenu = new StringBuilder();
        List menus = createMenu();
        montaMenu(menus, sbMenu, 0, "menu_", "");
        return sbMenu.toString();
    }

    private void montaMenu(List listaMenu, StringBuilder sbMenu, int index, String nomeVariavel, String hierarchyName) {
        String archMenuParent = JsfUtils.getAttributeSession(String.class, "archMenuParent");
        archMenuParent = archMenuParent == null ? "" : archMenuParent;

        if (listaMenu == null)
            return;

        for (int i = 0; i < listaMenu.size(); i++) {
            IMenu menu = listaMenu.get(i);
            String hierarchyNameMenu = hierarchyName + (hierarchyName.isEmpty() ? "" : "->") + menu.getName();

            String nomeMenu = menu.getName();
            String[] split = hierarchyNameMenu.split("->");

            if (split.length > 2)
                nomeMenu = CharacterUtils.alignTextRigth("", (split.length - 2) * 3, " ") + nomeMenu;

            if (menu.getSubMenu().isEmpty()) {
                sbMenu.append("	
  • "); sbMenu.append(" "); } sbMenu.append(" " + nomeMenu + " "); sbMenu.append(" "); } else { if (archMenuParent.indexOf("->") > 0) { archMenuParent = archMenuParent.substring(0, archMenuParent.indexOf("->")); } sbMenu.append("
  • "); sbMenu.append(" "); sbMenu.append(" " + nomeMenu + " "); sbMenu.append(" "); sbMenu.append(" "); sbMenu.append("
      "); montaMenu(menu.getSubMenu(), sbMenu, index, nomeVariavel + index, hierarchyNameMenu); sbMenu.append("
    "); } sbMenu.append("
  • "); } } public String parentHierarchy(IMenu menu, String hierarchyNameMenu) { String nomePai = menu.getName(); if (hierarchyNameMenu.contains("->")) nomePai = hierarchyNameMenu.substring(0, hierarchyNameMenu.indexOf("->")); return nomePai; } }




    © 2015 - 2024 Weber Informatics LLC | Privacy Policy