daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest May 22nd, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.ecp.bean;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import javax.annotation.PostConstruct;
  7. import javax.faces.bean.ManagedBean;
  8. import javax.faces.bean.SessionScoped;
  9. import org.primefaces.model.DefaultTreeNode;
  10. import org.primefaces.model.TreeNode;
  11. import com.ecp.dto.MenuTree;
  12. import com.ecp.services.MenuTreeServiceImpl;
  13.  
  14. @ManagedBean(name = "treeBean")
  15. @SessionScoped
  16. public class TreeBean {
  17.     private TreeNode root;
  18.     private TreeNode arbre;
  19.     private TreeNode selectedNode;
  20.     private MenuTreeServiceImpl helper;
  21.     private List<MenuTree> nodeList;
  22.     private static List<MenuTree> araListe;
  23.     private List<MenuTree> subList;
  24.     private long menuId;
  25.     private String menuName;
  26.     private Long parentMenuId;
  27.  
  28.    
  29.  
  30.     public TreeNode getRoot() {
  31.         return root;
  32.     }
  33.  
  34.     public void setRoot(TreeNode root) {
  35.         this.root = root;
  36.     }
  37.  
  38.     @PostConstruct
  39.     private void init() {
  40.         root = new DefaultTreeNode("Root", null);
  41.         nodeList = new ArrayList<MenuTree>();
  42.         // récupérer les données de la base dans une liste
  43.         nodeList.addAll(helper.getMenuTrees());
  44.         arbre = new DefaultTreeNode("", root);
  45.         recursive(nodeList, 0, root);
  46.     }
  47.  
  48.     public void recursive(List<MenuTree> nodeList, long id, TreeNode node) {
  49.  
  50.         for (Iterator<MenuTree> iter = nodeList.iterator(); iter.hasNext();) {
  51.             MenuTree elem = iter.next();
  52.             if (elem.getParentMenuId() == id) {
  53.                 DefaultTreeNode resultNode = new DefaultTreeNode(elem);
  54.                 node.getChildren().add(resultNode);
  55.                 iter.remove();
  56.                 recursive(new ArrayList(nodeList), elem.getMenuId(), resultNode);
  57.             }
  58.         }
  59.     }
  60.  
  61.     public TreeNode getArbre() {
  62.         return arbre;
  63.     }
  64.  
  65.     public void setArbre(TreeNode arbre) {
  66.         this.arbre = arbre;
  67.     }
  68.  
  69.     public TreeNode getSelectedNode() {
  70.         return selectedNode;
  71.     }
  72.  
  73.     public void setSelectedNode(TreeNode selectedNode) {
  74.         this.selectedNode = selectedNode;
  75.     }
  76.  
  77.     public MenuTreeServiceImpl getHelper() {
  78.         return helper;
  79.     }
  80.  
  81.     public void setHelper(MenuTreeServiceImpl helper) {
  82.         this.helper = helper;
  83.     }
  84.  
  85.     public List<MenuTree> getNodeList() {
  86.         return nodeList;
  87.     }
  88.  
  89.     public void setNodeList(List<MenuTree> nodeList) {
  90.         this.nodeList = nodeList;
  91.     }
  92.  
  93.     public static List<MenuTree> getAraListe() {
  94.         return araListe;
  95.     }
  96.  
  97.     public static void setAraListe(List<MenuTree> araListe) {
  98.         TreeBean.araListe = araListe;
  99.     }
  100.  
  101.     public List<MenuTree> getSubList() {
  102.         return subList;
  103.     }
  104.  
  105.     public void setSubList(List<MenuTree> subList) {
  106.         this.subList = subList;
  107.     }
  108.  
  109.     public long getMenuId() {
  110.         return menuId;
  111.     }
  112.  
  113.     public void setMenuId(long menuId) {
  114.         this.menuId = menuId;
  115.     }
  116.  
  117.     public String getMenuName() {
  118.         return menuName;
  119.     }
  120.  
  121.     public void setMenuName(String menuName) {
  122.         this.menuName = menuName;
  123.     }
  124.  
  125.     public Long getParentMenuId() {
  126.         return parentMenuId;
  127.     }
  128.  
  129.     public void setParentMenuId(Long parentMenuId) {
  130.         this.parentMenuId = parentMenuId;
  131.     }
  132.  
  133. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top