Search in sources :

Example 31 with TreeNode

use of org.olat.core.gui.components.tree.TreeNode in project OpenOLAT by OpenOLAT.

the class QTI21StatisticsToolController method event.

@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (courseTree == source) {
        if (event instanceof TreeEvent) {
            TreeEvent te = (TreeEvent) event;
            if (MenuTree.COMMAND_TREENODE_CLICKED.equals(te.getCommand())) {
                String ident = te.getNodeId();
                TreeNode selectedNode = courseTree.getTreeModel().getNodeById(ident);
                doSelectNode(ureq, selectedNode);
            }
        }
    }
}
Also used : TreeEvent(org.olat.core.gui.components.tree.TreeEvent) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 32 with TreeNode

use of org.olat.core.gui.components.tree.TreeNode in project OpenOLAT by OpenOLAT.

the class TaxonomyAllTreesBuilder method toTree.

public List<TaxonomyLevelRow> toTree(List<TaxonomyLevelRow> taxonomyLevels) {
    GenericTreeNode rootNode = new GenericTreeNode();
    Map<Long, GenericTreeNode> fieldKeyToNode = new HashMap<Long, GenericTreeNode>();
    for (TaxonomyLevelRow taxonomyLevel : taxonomyLevels) {
        Long key = taxonomyLevel.getKey();
        GenericTreeNode node = fieldKeyToNode.get(key);
        if (node == null) {
            node = new GenericTreeNode(nodeKey(taxonomyLevel));
            node.setUserObject(taxonomyLevel);
            fieldKeyToNode.put(key, node);
        }
        TaxonomyLevelRow parentLevel = taxonomyLevel.getParent();
        if (parentLevel == null) {
            // this is a root
            rootNode.addChild(node);
        } else {
            Long parentKey = parentLevel.getKey();
            GenericTreeNode parentNode = fieldKeyToNode.get(parentKey);
            if (parentNode == null) {
                parentNode = new GenericTreeNode("level-" + parentLevel.getKey());
                parentNode.setUserObject(parentLevel);
                fieldKeyToNode.put(parentKey, parentNode);
            }
            parentNode.addChild(node);
        }
    }
    List<TreeNode> nodeList = new ArrayList<>();
    TreeHelper.makeTreeFlat(rootNode, nodeList);
    List<TaxonomyLevelRow> sortedRows = new ArrayList<>();
    for (TreeNode node : nodeList) {
        if (node.getUserObject() != null) {
            sortedRows.add((TaxonomyLevelRow) node.getUserObject());
        }
    }
    return sortedRows;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) HashMap(java.util.HashMap) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) ArrayList(java.util.ArrayList) TaxonomyLevelRow(org.olat.modules.taxonomy.ui.TaxonomyLevelRow)

Example 33 with TreeNode

use of org.olat.core.gui.components.tree.TreeNode in project OpenOLAT by OpenOLAT.

the class TaxonomyModel method validateContinuousSelection.

/**
 * Check the selection of levels doesn't contains
 * a select parent with only part of its children selected.
 * No children selected is allowed, all children selected
 * are allowed but not part of them.
 *
 * @param levels The list of levels
 * @return true if the selection is continous
 */
public boolean validateContinuousSelection(List<? extends TaxonomyLevelRef> levels) {
    boolean allOk = true;
    Set<String> selectedNodeIds = new HashSet<>();
    for (TaxonomyLevelRef level : levels) {
        selectedNodeIds.add(nodeKey(level));
    }
    for (TaxonomyLevelRef level : levels) {
        String nodeId = nodeKey(level);
        TreeNode node = getNodeById(nodeId);
        if (node.getChildCount() > 0) {
            int count = node.getChildCount();
            for (int i = count; i-- > 0; ) {
                String childId = node.getChildAt(i).getIdent();
                if (selectedNodeIds.contains(childId)) {
                    count--;
                }
            }
            if (count > 0 && count != node.getChildCount()) {
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef) HashSet(java.util.HashSet)

Example 34 with TreeNode

use of org.olat.core.gui.components.tree.TreeNode in project OpenOLAT by OpenOLAT.

the class TaxonomyLevelLibraryIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    if (roles.isOLATAdmin())
        return true;
    if ("TaxonomyLevel".equals(contextEntry.getOLATResourceable().getResourceableTypeName())) {
        Long levelKey = contextEntry.getOLATResourceable().getResourceableId();
        TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelKey));
        TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(level.getTaxonomy(), identity, null, false, true, "Templates", null);
        TreeModel model = builder.buildTreeModel();
        List<TreeNode> flat = new ArrayList<>();
        TreeHelper.makeTreeFlat(model.getRootNode(), flat);
        for (TreeNode node : flat) {
            TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
            if (taxonomyNode.getType() == TaxonomyTreeNodeType.taxonomyLevel && level.equals(taxonomyNode.getTaxonomyLevel())) {
                if (taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) ArrayList(java.util.ArrayList) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) TaxonomyLevelRefImpl(org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl) TaxonomyTreeBuilder(org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)

Example 35 with TreeNode

use of org.olat.core.gui.components.tree.TreeNode in project OpenOLAT by OpenOLAT.

the class EditTaxonomyLevelController method buildPathKeysAndValues.

private void buildPathKeysAndValues(List<String> pathKeyList, List<String> pathValueList) {
    pathKeyList.add("-");
    pathValueList.add("");
    List<TreeNode> nodeList = new TaxonomyAllTreesBuilder().getFlattedModel(taxonomy, false);
    for (TreeNode node : nodeList) {
        TaxonomyLevel taxonomyLevel = (TaxonomyLevel) node.getUserObject();
        pathKeyList.add(taxonomyLevel.getKey().toString());
        pathValueList.add(taxonomyLevel.getMaterializedPathIdentifiers());
    }
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyAllTreesBuilder(org.olat.modules.taxonomy.manager.TaxonomyAllTreesBuilder)

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