use of org.olat.core.gui.components.tree.TreeNode in project openolat by klemens.
the class GenericMainController method event.
@Override
protected void event(UserRequest ureq, Component source, Event event) {
if (source == olatMenuTree) {
if (event instanceof TreeEvent && event.getCommand().equals(MenuTree.COMMAND_TREENODE_CLICKED)) {
TreeEvent te = (TreeEvent) event;
if (te.getSubCommand() != null) {
// filter open/close events
} else {
// process menu commands
TreeNode selTreeNode = olatMenuTree.getSelectedNode();
// cleanup old content controller (never null)
removeAsListenerAndDispose(contentCtr);
// create new content controller
// Following cases:
// 1a) Simple Action Extension using only ureq and windowControl ->
// handled by default implementation of createController
// 1b) Specialised Action Extension which needs some more internals ->
// handled by the class extending GenericMainController, by overwriting
// createController
// 2) uobject is something special which needs evaluation by class
// extending GenericMainController
Object uobject = selTreeNode.getUserObject();
TreeNode delegatee = selTreeNode.getDelegate();
if (delegatee != null) {
olatMenuTree.setSelectedNode(delegatee);
}
contentCtr = getContentCtr(uobject, ureq);
listenTo(contentCtr);
Component resComp = contentCtr.getInitialComponent();
content.setContent(resComp);
addToHistory(ureq, contentCtr);
}
} else {
// the action was not allowed anymore
// display an empty field (empty panel)
content.setContent(null);
}
} else {
logWarn("Unhandled olatMenuTree event: " + event.getCommand(), null);
}
}
use of org.olat.core.gui.components.tree.TreeNode in project openolat by klemens.
the class TreeHelper method getTreePath.
public static List<TreeNode> getTreePath(TreeNode node) {
List<TreeNode> conPath = new ArrayList<TreeNode>();
for (TreeNode cur = node; cur != null; cur = (TreeNode) cur.getParent()) {
conPath.add(cur);
}
Collections.reverse(conPath);
return conPath;
}
use of org.olat.core.gui.components.tree.TreeNode in project openolat by klemens.
the class TreeHelper method resolveTreeNode.
public static TreeNode resolveTreeNode(String treePath, TreeModel treeModel) {
// even for the root node, our parameter may not be the empty string, therefore the prefix to be chopped here
treePath = treePath.substring(1);
TreeNode cur = treeModel.getRootNode();
if (!treePath.equals("")) {
// if we are not the root node
String[] res = treePath.split("_");
for (int i = res.length - 1; i >= 0; i--) {
String spos = res[i];
Integer chdPos = Integer.parseInt(spos);
TreeNode chd = (TreeNode) cur.getChildAt(chdPos);
if (chd == null)
throw new AssertException("cannot find: " + treePath);
cur = chd;
}
}
return cur;
}
use of org.olat.core.gui.components.tree.TreeNode in project openolat by klemens.
the class TreeHelper method makeTreeFlat.
/**
* from tree structure to a flat list
* @param node
* @param outNodeList
*/
public static void makeTreeFlat(TreeNode node, List<TreeNode> outNodeList) {
// add node
if (node != null) {
outNodeList.add(node);
int childcnt = node.getChildCount();
for (int i = 0; i < childcnt; i++) {
// add all subnodes.
TreeNode child = (TreeNode) node.getChildAt(i);
makeTreeFlat(child, outNodeList);
}
}
}
use of org.olat.core.gui.components.tree.TreeNode in project openolat by klemens.
the class TreeHelper method findNodeByUserObject.
/**
* Depth-first traversal.
* @param nodeId
* @param node the root node to start the search with
* @return the first treenode with the given user object or null if not found
*/
public static TreeNode findNodeByUserObject(Object userObject, TreeNode node) {
if (node.getUserObject() != null && node.getUserObject().equals(userObject)) {
return node;
}
int childcnt = node.getChildCount();
for (int i = 0; i < childcnt; i++) {
TreeNode child = (TreeNode) node.getChildAt(i);
TreeNode result = findNodeByUserObject(userObject, child);
if (result != null)
return result;
}
return null;
}
Aggregations