use of org.apache.myfaces.custom.tree2.TreeNodeBase in project TNTConcept by autentia.
the class MenuBean method addLeaf.
/**
* Add leaf node to parent node if it is accesible by current user
* @param path path of current node
* @param creds current user
* @param neededRole role needed to render the node
* @param parent parent node
* @param cmd command name
* @return true if node was added
*/
private boolean addLeaf(Stack<TreeNode> path, Principal creds, GrantedAuthority neededRole, String cmd) {
boolean added = false;
if (neededRole == null || creds.hasAuthority(neededRole)) {
String text;
try {
text = msg.getString("menu." + cmd);
} catch (MissingResourceException e) {
text = "MISSING : " + cmd + " : MISSING";
}
TreeNode child = new TreeNodeBase("document", text, cmd, true);
path.peek().getChildren().add(child);
added = true;
}
log.debug("addLeaf - " + (added ? "ADD " : "IGNORE") + ": " + cmd);
return added;
}
use of org.apache.myfaces.custom.tree2.TreeNodeBase in project gdmatrix by gdmatrix.
the class TreeModelUtils method findChildNode.
private static TreeNodeBase findChildNode(TreeNodeBase node, String pathElem) {
TreeNodeBase childNode = null;
boolean found = false;
Iterator iter = node.getChildren().iterator();
while (!found && iter.hasNext()) {
childNode = (TreeNodeBase) iter.next();
String nodeDesc = childNode.getDescription();
found = nodeDesc.equals(pathElem);
}
return found ? childNode : null;
}
use of org.apache.myfaces.custom.tree2.TreeNodeBase in project gdmatrix by gdmatrix.
the class TreeModelUtils method addNode.
/* private methods */
private static void addNode(TreeNodeBase rootNode, String[] pathArray, Map row) throws Exception {
TreeNodeBase currentNode = rootNode;
for (int i = 0; i < pathArray.length; i++) {
String pathElem = pathArray[i];
String[] name = splitName(pathElem);
String desc = name[0];
String info = name[1];
TreeNodeBase childNode = findChildNode(currentNode, desc);
if (childNode == null) {
boolean isLeaf = (i == pathArray.length - 1);
if (isLeaf) {
childNode = createNode("document", desc, info, row);
} else // create inner tree node
{
childNode = createNode("folder", desc, info, null);
}
currentNode.getChildren().add(childNode);
}
currentNode.setType("folder");
currentNode.setLeaf(false);
currentNode = childNode;
}
}
use of org.apache.myfaces.custom.tree2.TreeNodeBase in project TNTConcept by autentia.
the class MenuBean method getMenu.
/**
* Get menu tree
* @return menu tree
*/
public TreeNode getMenu() {
// Create menu only the first time
if (menu == null) {
Principal creds = SpringUtils.getPrincipal();
Stack<TreeNode> path = new Stack<TreeNode>();
menu = new TreeNodeBase("menu", "Menu", false);
path.push(menu);
if (openNode(path, creds, null, "admin")) {
addLeaf(path, creds, Permission.Entity_Menu(User.class), "users");
addLeaf(path, creds, Permission.Entity_Menu(UserCategory.class), "userCategorys");
addLeaf(path, creds, null, "changePassword");
addLeaf(path, creds, Permission.Entity_Menu(Department.class), "departments");
// addLeaf( path, creds, Permission.Entity_Menu(Setting.class), "settings" );
closeNode(path);
}
if (openNode(path, creds, null, "masterTables")) {
addLeaf(path, creds, Permission.Entity_Menu(AccountEntryType.class), "accountEntryTypes");
addLeaf(path, creds, Permission.Entity_Menu(OrganizationType.class), "organizationTypes");
addLeaf(path, creds, Permission.Entity_Menu(InteractionType.class), "interactionTypes");
addLeaf(path, creds, Permission.Entity_Menu(OrganizationISOCategory.class), "organizationISOCategorys");
addLeaf(path, creds, Permission.Entity_Menu(ContractType.class), "contractTypes");
addLeaf(path, creds, Permission.Entity_Menu(Magazine.class), "magazines");
addLeaf(path, creds, Permission.Entity_Menu(OfferRejectReason.class), "offerRejectReasons");
closeNode(path);
}
if (openNode(path, creds, null, "billing")) {
addLeaf(path, creds, Permission.Entity_Menu(Bill.class), "bills");
addLeaf(path, creds, Permission.Entity_Menu(Account.class), "accounts");
addLeaf(path, creds, Permission.Entity_Menu(AccountEntry.class), "accountEntrys");
addLeaf(path, creds, Permission.Entity_Menu(PeriodicalAccountEntry.class), "periodicalAccountEntrys");
addLeaf(path, creds, Permission.Action_NOF, "nof");
addLeaf(path, creds, Permission.Entity_Menu(FinancialRatio.class), "financialRatios");
closeNode(path);
}
if (openNode(path, creds, null, "contacts")) {
addLeaf(path, creds, Permission.Entity_Menu(Organization.class), "organizations");
addLeaf(path, creds, Permission.Entity_Menu(Interaction.class), "interactions");
addLeaf(path, creds, Permission.Entity_Menu(Contact.class), "contacts");
addLeaf(path, creds, Permission.Entity_Menu(Offer.class), "offers");
addLeaf(path, creds, Permission.Entity_Menu(Project.class), "projects");
closeNode(path);
}
if (openNode(path, creds, null, "quality")) {
addLeaf(path, creds, Permission.Action_ListQualityDocuments, "qualityDocuments");
closeNode(path);
}
if (openNode(path, creds, null, "bulletin")) {
addLeaf(path, creds, Permission.Entity_Menu(BulletinBoard.class), "bulletinBoards");
addLeaf(path, creds, Permission.Entity_Menu(CompanyState.class), "companyStates");
addLeaf(path, creds, Permission.Entity_Menu(BulletinBoardCategory.class), "bulletinBoardCategorys");
addLeaf(path, creds, Permission.Entity_Menu(Idea.class), "ideas");
closeNode(path);
}
if (openNode(path, creds, null, "activity")) {
addLeaf(path, creds, Permission.Entity_Menu(Activity.class), "activitys");
addLeaf(path, creds, Permission.Entity_Menu(Objective.class), "objectives");
closeNode(path);
}
if (openNode(path, creds, null, "reports")) {
addLeaf(path, creds, Permission.Action_GeneralReports, "generalReports");
addLeaf(path, creds, Permission.Action_BitacoreReports, "bitacoreReports");
addLeaf(path, creds, Permission.Action_BillReports, "billReports");
addLeaf(path, creds, Permission.Action_ProjectReports, "projectReports");
addLeaf(path, creds, Permission.Action_InteractionReports, "interactionReports");
addLeaf(path, creds, Permission.Action_OrganizationReports, "organizationReports");
addLeaf(path, creds, Permission.Action_OfferReports, "offerReports");
addLeaf(path, creds, Permission.Action_OwnReports, "ownReports");
addLeaf(path, creds, Permission.Action_PersonalReports, "personalReports");
closeNode(path);
}
if (openNode(path, creds, null, "publish")) {
addLeaf(path, creds, Permission.Entity_Menu(Tutorial.class), "tutorials");
addLeaf(path, creds, Permission.Entity_Menu(Publication.class), "publications");
closeNode(path);
}
if (openNode(path, creds, null, "holiday")) {
addLeaf(path, creds, Permission.Entity_Menu(Holiday.class), "holidays");
addLeaf(path, creds, Permission.Entity_Menu(RequestHoliday.class), "requestHolidays");
addLeaf(path, creds, Permission.Entity_Menu(AdminHoliday.class), "adminHolidays");
closeNode(path);
}
if (openNode(path, creds, null, "utils")) {
addLeaf(path, creds, Permission.Entity_Menu(Book.class), "books");
addLeaf(path, creds, Permission.Entity_Menu(Inventary.class), "inventarys");
closeNode(path);
}
}
return menu;
}
use of org.apache.myfaces.custom.tree2.TreeNodeBase in project TNTConcept by autentia.
the class MenuBean method openNode.
/**
* Add non-leaf node to current node if it is accesible by current user
* @param path path of current node
* @param creds current user
* @param neededRole role needed to render the node
* @param parent parent node
* @param cmd command name
* @return true if node has been created
*/
private boolean openNode(Stack<TreeNode> path, Principal creds, GrantedAuthority neededRole, String cmd) {
boolean added = false;
if (neededRole == null || creds.hasAuthority(neededRole)) {
String text;
try {
text = msg.getString("menu." + cmd);
} catch (MissingResourceException e) {
text = "MISSING : " + cmd + " : MISSING";
}
TreeNode child = new TreeNodeBase("folder", text, cmd, false);
path.peek().getChildren().add(child);
path.push(child);
added = true;
}
log.debug("openNode - " + (added ? "OPEN " : "IGNORE") + ": " + cmd);
return added;
}
Aggregations