log.debug("Adding role: " + roleToAddPath);
}
// Add role.
roleMgr.addRole(roleToAddPath);
// Get the newly added role.
Role addedRole = roleMgr.getRole(roleToAddPath);
// Resolve the tree table.
FacesContext facesContext = FacesContext.getCurrentInstance();
VariableResolver vr = facesContext.getApplication().getVariableResolver();
RoleTreeTable roleTree = (RoleTreeTable) vr.resolveVariable(facesContext, RoleTreeTable.ROLE_TREE_TABLE);
// Get the listeners registered.
Collection listeners = roleTree.getTreeModel().getTreeModelListeners();
// TODO We could be more sophisticated and not rebuild the old tree. For now this will do.
roleTree.setTreeModel(SecurityApplicationUtils.buildRoleTreeModel());
// Get the new tree model.
DefaultTreeModel treeModel = roleTree.getTreeModel();
// Add the old listeners back...
treeModel.getTreeModelListeners().addAll(listeners);
// Get the index of the new node.
TreeNode parentNode = SecurityApplicationUtils.findTreeNode(roleTree, getParentRole().getFullPath());
TreeNode childNode = SecurityApplicationUtils.findTreeNode(roleTree, addedRole.getPreferences().absolutePath());
int [] childIndices = {treeModel.getIndexOfChild(parentNode, childNode)};
// Send the node inserted event.
treeModel.nodesWereInserted(parentNode, childIndices);
}
catch (SecurityException se)