use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.
the class GenericMainController method buildTreeModel.
private TreeModel buildTreeModel(UserRequest ureq) {
GenericTreeNode rootTreeNode = new GenericTreeNode();
rootTreeNode.setTitle(getTranslator().translate("main.menu.title"));
rootTreeNode.setAltText(getTranslator().translate("main.menu.title.alt"));
GenericTreeModel gtm = new GenericTreeModel();
gtm.setRootNode(rootTreeNode);
// Prepend
boolean rootNodeSet = false;
if (nodesToPrepend.size() != 0) {
for (GenericTreeNode node : nodesToPrepend) {
rootTreeNode.addChild(node);
if (!rootNodeSet) {
rootTreeNode.setDelegate(node);
rootTreeNode.setUserObject(node.getUserObject());
rootNodeSet = true;
}
}
}
// add extension menues
ExtManager extm = ExtManager.getInstance();
int j = 0;
GenericTreeNode gtnChild;
Map<GenericTreeNode, String> subMenuNodes = new LinkedHashMap<GenericTreeNode, String>();
for (Extension anExt : extm.getExtensions()) {
// check for sites
ActionExtension ae = (ActionExtension) anExt.getExtensionFor(className, ureq);
if (ae != null && ae instanceof GenericActionExtension) {
if (anExt.isEnabled()) {
GenericActionExtension gAe = (GenericActionExtension) ae;
gtnChild = gAe.createMenuNode(ureq);
if (StringHelper.containsNonWhitespace(gAe.getNavigationKey())) {
gtnChild.setCssClass("o_sel_" + gAe.getNavigationKey());
}
if (gAe.getNodeIdentifierIfParent() != null) {
// it's a parent-node, set identifier
gtnChild.setIdent(gAe.getNodeIdentifierIfParent());
}
if (j == 0 && !rootNodeSet) {
// first node, set as delegate of rootTreenode
rootTreeNode.setDelegate(gtnChild);
rootTreeNode.setUserObject(gAe);
rootTreeNode.addChild(gtnChild);
} else // navigation (submenues)
if (gAe.getParentTreeNodeIdentifier() != null) {
// this is a sub-menu-node, do not add to tree-model already, since
// parent tree may not yet be in model
// (parent could be "after" child, in ActionExtensions-Collection)
String parentNodeID = gAe.getParentTreeNodeIdentifier();
subMenuNodes.put(gtnChild, parentNodeID);
} else // "normal" menu-entry
{
rootTreeNode.addChild(gtnChild);
}
j++;
} else {
logInfo("found disabled GenericActionExtension for " + className + " ", ae.toString());
}
}
}
// loop over submenuNodes and add to their parents
for (Entry<GenericTreeNode, String> childNodeEntry : subMenuNodes.entrySet()) {
GenericTreeNode childNode = childNodeEntry.getKey();
GenericTreeNode parentNode = (GenericTreeNode) gtm.getNodeById(childNodeEntry.getValue());
if (parentNode != null) {
parentNode.addChild(childNode);
if (parentNode.getDelegate() == null) {
boolean addDelegate = true;
// add delegate only if hte parent hasn't not a controller defined
Object uo = parentNode.getUserObject();
if (uo instanceof GenericActionExtension) {
GenericActionExtension gae = (GenericActionExtension) uo;
if (StringHelper.containsNonWhitespace(gae.getClassNameOfCorrespondingController())) {
addDelegate = false;
}
}
if (addDelegate) {
parentNode.setDelegate(childNode);
parentNode.setUserObject(childNode.getUserObject());
}
}
} else {
logWarn("Could not add navigation-menu (" + childNode.getTitle() + ") to parent:: " + childNodeEntry.getValue(), null);
// make it at least appear on top level
rootTreeNode.addChild(childNode);
}
}
// Append
if (nodesToAppend.size() != 0) {
for (GenericTreeNode node : nodesToAppend) {
rootTreeNode.addChild(node);
}
}
return gtm;
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.
the class QuestionPoolMenuTreeModel method buildReviewSubTreeModel.
public void buildReviewSubTreeModel(TreeNode rootNode) {
if (!securityCallback.canUseReviewProcess())
return;
qpoolTaxonomyTreeBuilder.loadTaxonomyLevelsReview(identity);
List<TaxonomyLevel> taxonomyLevels = qpoolTaxonomyTreeBuilder.getTreeTaxonomyLevels();
if (!taxonomyLevels.isEmpty()) {
reviewNode = new GenericTreeNode(translator.translate("menu.review"));
reviewNode.setTitle(translator.translate("menu.review"));
rootNode.addChild(reviewNode);
for (TaxonomyLevel taxonomyLevel : taxonomyLevels) {
TreeNode node = new ReviewTreeNode(stackPanel, securityCallback, taxonomyLevel, identity, roles);
reviewNode.addChild(node);
}
setFirstChildAsDelegate(reviewNode);
}
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.
the class QuestionPoolMenuTreeModel method setFirstChildAsDelegate.
private void setFirstChildAsDelegate(INode node) {
if (node.getChildCount() > 0) {
INode childNode = node.getChildAt(0);
if (node instanceof GenericTreeNode && childNode instanceof TreeNode) {
GenericTreeNode parent = (GenericTreeNode) node;
TreeNode child = (TreeNode) childNode;
parent.setDelegate(child);
}
}
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.
the class CatalogTreeModel method calculateAccessibility.
/**
* Limit accessability to node to the nodes that are owned by the current user
*/
private void calculateAccessibility(GenericTreeNode rootNode) {
GenericTreeNode node = null;
// first : allow access to all children of the owned entries
if (ownedEntries != null) {
for (CatalogEntry entry : ownedEntries) {
node = entryMap.get(entry.getKey());
changeAccessibility(node, true);
}
}
// to avoid circles and not dissolve elements from the catalog root )
if (entryToMove != null && entryToMove.getType() == CatalogEntry.TYPE_NODE) {
node = entryMap.get(entryToMove.getKey());
changeAccessibility(node, false);
}
// entries are owned, we assume that all entries can be selected by user
if (entryToMove == null && ownedEntries == null) {
changeAccessibility(rootNode, true);
}
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.
the class CatalogTreeModel method buildNode.
/**
* Build a tree node from the given category entry
* @param catEntry
* @return
*/
private GenericTreeNode buildNode(CatalogEntry catEntry) {
GenericTreeNode node = new GenericTreeNode();
node.setAccessible(false);
node.setIdent(catEntry.getKey().toString());
node.setTitle(catEntry.getName());
node.setUserObject(catEntry);
entryMap.put(catEntry.getKey(), node);
return node;
}
Aggregations