private void updateNodeForSelected(final TreeNode treeNode, final TreeNode selectedTreeNode) { if ((selectedTreeNode != null) && (treeNode != null)) { if (treeNode == selectedTreeNode) { selectedTreeNode.setSelected(true); } else { treeNode.setSelected(false); } if (treeNode.getChildCount() != 0) { for (final TreeNode child : treeNode.getChildren()) { updateNodeForSelected(child, selectedTreeNode); } } } }
/** * Método que carrega a arvore para uma lista de permissoes * * @param permissoes - as permissoes a serem exibidas * @param permissoesParaSelecionar - as permissoes que ficarao selecionadas * @return */ public TreeNode getTreeNode( List<Permissao> permissoes, List<Permissao> permissoesParaSelecionar) { TreeNode root = new DefaultTreeNode(); root.setExpanded(true); Map<Permissao, TreeNode> nodeMap = new LinkedHashMap<Permissao, TreeNode>(); // criar nó para cada permissao for (Permissao permissao : permissoes) { adicionarPermissaoAoMap(root, permissao, nodeMap, permissoes, permissoesParaSelecionar, true); } for (Map.Entry<Permissao, TreeNode> entry : nodeMap.entrySet()) { Permissao permissao = entry.getKey(); TreeNode node = entry.getValue(); if (permissao.getPermissaoPai() != null) { TreeNode parent = nodeMap.get(permissao.getPermissaoPai()); // selecionar apenas ate o segundo nivel if (parent != null && parent.isSelected()) { node.setSelected(true); } node.setExpanded(false); if (parent != null) { parent.getChildren().add(node); } else { root.getChildren().add(node); } } } return root; }
private void selectClassificationInTree(TreeNode raiz, List<Classification> selectedlist) { List<TreeNode> children = raiz.getChildren(); for (Classification c : selectedlist) { if (raiz.getData() != null && raiz.getData().equals(c)) { raiz.setSelected(true); getSelectednodesList().add(raiz); } } for (TreeNode hijo : children) { selectClassificationInTree(hijo, selectedlist); } }
public void adicionarPermissaoAoMap( TreeNode root, Permissao permissao, Map<Permissao, TreeNode> nodeMap, List<Permissao> permissoes, List<Permissao> permissoesParaSelecionar, boolean selectable) { TreeNode node = new DefaultTreeNode(permissao, root); node.setExpanded(true); node.setSelectable(selectable); if (permissoesParaSelecionar != null && permissoesParaSelecionar.contains(permissao)) { node.setSelected(true); } nodeMap.put(permissao, node); if (permissao.getPermissaoPai() != null) { Permissao permissaoPai = permissaoDAO.getInitialized(permissao.getPermissaoPai()); if (!permissoes.contains(permissaoPai) && nodeMap.get(permissaoPai) == null) { adicionarPermissaoAoMap( root, permissaoPai, nodeMap, permissoes, permissoesParaSelecionar, false); } } }