Search in sources :

Example 66 with TreeNode

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);
    }
}
Also used : TreeEvent(org.olat.core.gui.components.tree.TreeEvent) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) Component(org.olat.core.gui.components.Component)

Example 67 with TreeNode

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;
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) ArrayList(java.util.ArrayList)

Example 68 with TreeNode

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;
}
Also used : AssertException(org.olat.core.logging.AssertException) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 69 with TreeNode

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);
        }
    }
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 70 with TreeNode

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;
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode)

Aggregations

TreeNode (org.olat.core.gui.components.tree.TreeNode)296 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)146 ArrayList (java.util.ArrayList)44 CourseNode (org.olat.course.nodes.CourseNode)38 TreeEvent (org.olat.core.gui.components.tree.TreeEvent)32 ContextEntry (org.olat.core.id.context.ContextEntry)30 Controller (org.olat.core.gui.control.Controller)28 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)24 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)22 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)20 INode (org.olat.core.util.nodes.INode)20 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)20 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)20 ICourse (org.olat.course.ICourse)18 Activateable2 (org.olat.core.gui.control.generic.dtabs.Activateable2)16 OLATResourceable (org.olat.core.id.OLATResourceable)16 List (java.util.List)14 TreeModel (org.olat.core.gui.components.tree.TreeModel)14 WindowControl (org.olat.core.gui.control.WindowControl)14 AssertException (org.olat.core.logging.AssertException)14