Search in sources :

Example 11 with TreeModel

use of org.olat.core.gui.components.tree.TreeModel in project openolat by klemens.

the class SelectionTreeComponentRenderer method render.

@Override
public void render(Renderer renderer, StringOutput sb, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    SelectionTreeComponent stc = (SelectionTreeComponent) source;
    Map<String, CheckboxElement> checkboxes = stc.getSubComponents();
    TreeModel tm = stc.getTreeModel();
    TreeNode rootNode = tm.getRootNode();
    if (rootNode.getChildCount() == 1) {
        rootNode = (TreeNode) rootNode.getChildAt(0);
    }
    INodeFilter selectableFilter = stc.getSelectableFilter();
    sb.append("<div class='o_selection_tree'><ul class='o_selection_tree_l0'>");
    renderNode(rootNode, rootNode, 0, stc.hashCode(), sb, renderer, stc, checkboxes, selectableFilter, args);
    sb.append("</ul></div>");
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) TreeNode(org.olat.core.gui.components.tree.TreeNode) INodeFilter(org.olat.core.util.tree.INodeFilter)

Example 12 with TreeModel

use of org.olat.core.gui.components.tree.TreeModel in project openolat by klemens.

the class NavigationHandler method reattachExternalTreeModels.

private void reattachExternalTreeModels(TreeEvaluation treeEval) {
    if (externalTreeModels == null || externalTreeModels.isEmpty())
        return;
    for (Map.Entry<String, SubTree> entry : externalTreeModels.entrySet()) {
        String courseNodeId = entry.getKey();
        SubTree subTree = entry.getValue();
        TreeModel treeModel = subTree.getTreeModel();
        CourseNode courseNode = userCourseEnv.getCourseEnvironment().getRunStructure().getNode(courseNodeId);
        TreeNode treeNode = treeEval.getCorrespondingTreeNode(courseNode);
        if (treeNode != null) {
            addSubTreeModel(treeNode, treeModel);
        }
    }
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with TreeModel

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

the class QPoolTaxonomyTreeBuilder method buildTreeModel.

public TreeModel buildTreeModel() {
    GenericTreeModel gtm = new GenericTreeModel();
    TaxonomyLevelNode root = new TaxonomyLevelNode();
    gtm.setRootNode(root);
    List<TaxonomyLevel> taxonomyLevels = qpoolService.getTaxonomyLevels();
    Map<Long, TaxonomyLevel> keytoLevels = taxonomyLevels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
    Map<Long, TaxonomyLevelNode> fieldKeyToNode = new HashMap<>();
    for (TaxonomyLevel taxonomyLevel : taxonomyLevels) {
        Long key = taxonomyLevel.getKey();
        TaxonomyLevelNode node = fieldKeyToNode.get(key);
        if (node == null) {
            node = new TaxonomyLevelNode(taxonomyLevel);
            TaxonomyLevelType type = taxonomyLevel.getType();
            if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                node.setIconCssClass(type.getCssClass());
            }
            fieldKeyToNode.put(key, node);
        }
        TaxonomyLevel parentLevel = taxonomyLevel.getParent();
        if (parentLevel == null) {
            // this is a root
            root.addChild(node);
        } else {
            Long parentKey = parentLevel.getKey();
            TaxonomyLevelNode parentNode = fieldKeyToNode.get(parentKey);
            if (parentNode == null) {
                // to use the fetched type
                parentLevel = keytoLevels.get(parentKey);
                parentNode = new TaxonomyLevelNode(parentLevel);
                TaxonomyLevelType type = parentLevel.getType();
                if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                    parentNode.setIconCssClass(type.getCssClass());
                }
                fieldKeyToNode.put(parentKey, parentNode);
            }
            parentNode.addChild(node);
        }
    }
    sort(root);
    return gtm;
}
Also used : INode(org.olat.core.util.nodes.INode) TreeModel(org.olat.core.gui.components.tree.TreeModel) QPoolService(org.olat.modules.qpool.QPoolService) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) QuestionPoolModule(org.olat.modules.qpool.QuestionPoolModule) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.springframework.stereotype.Component) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) Map(java.util.Map) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) Comparator(java.util.Comparator) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) HashMap(java.util.HashMap) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 14 with TreeModel

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

the class QPoolTaxonomyTreeBuilder method prefill.

private void prefill(List<TaxonomyLevel> levels) {
    prefillMaterializedPathKeysWithCompetence(levels);
    TreeModel tree = buildTreeModel();
    prefillTaxonomyLevels(tree.getRootNode());
    prefillSelectableTaxonomyLevelsArrays();
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 15 with TreeModel

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

the class TaxonomyTreeBuilder method buildTreeModel.

public TreeModel buildTreeModel() {
    GenericTreeModel gtm = new GenericTreeModel();
    TaxonomyTreeNode root = new TaxonomyTreeNode(taxonomy);
    root.setTitle("ROOT competence");
    gtm.setRootNode(root);
    if (taxonomy != null) {
        taxonomy = taxonomyService.getTaxonomy(taxonomy);
        if (StringHelper.containsNonWhitespace(rootTitle)) {
            root.setTitle(rootTitle);
        } else {
            root.setTitle(taxonomy.getDisplayName());
        }
        root.setUserObject(taxonomy);
        // taxonomy directory
        if (enableTemplates) {
            VFSContainer taxonomyDirectory = taxonomyService.getDocumentsLibrary(taxonomy);
            TaxonomyTreeNode taxonomyDirectorNode = new TaxonomyTreeNode(taxonomy, taxonomyDirectory, TaxonomyTreeNodeType.templates);
            if (locale == null) {
                locale = CoreSpringFactory.getImpl(I18nManager.class).getCurrentThreadLocale();
            }
            taxonomyDirectorNode.setTitle(templateDirectory);
            taxonomyDirectorNode.setUserObject(taxonomyDirectory);
            root.addChild(taxonomyDirectorNode);
        }
        // taxonomy levels
        List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
        Map<Long, TaxonomyLevel> keytoLevels = levels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
        Map<Long, TaxonomyTreeNode> fieldKeyToNode = new HashMap<>();
        for (TaxonomyLevel taxonomyLevel : levels) {
            Long key = taxonomyLevel.getKey();
            TaxonomyTreeNode node = fieldKeyToNode.get(key);
            if (node == null) {
                node = new TaxonomyTreeNode(taxonomy, taxonomyLevel, getType(taxonomyLevel));
                TaxonomyLevelType type = taxonomyLevel.getType();
                if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                    node.setIconCssClass(type.getCssClass());
                }
                fieldKeyToNode.put(key, node);
            }
            TaxonomyLevel parentLevel = taxonomyLevel.getParent();
            if (parentLevel == null) {
                // this is a root
                root.addChild(node);
            } else {
                Long parentKey = parentLevel.getKey();
                TaxonomyTreeNode parentNode = fieldKeyToNode.get(parentKey);
                if (parentNode == null) {
                    // to use the fetched type
                    parentLevel = keytoLevels.get(parentKey);
                    parentNode = new TaxonomyTreeNode(taxonomy, parentLevel, getType(parentLevel));
                    TaxonomyLevelType type = parentLevel.getType();
                    if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
                        parentNode.setIconCssClass(type.getCssClass());
                    }
                    fieldKeyToNode.put(parentKey, parentNode);
                }
                parentNode.addChild(node);
            }
        }
        computePermissions(root);
        trimVisiblity(root);
        sort(root);
    }
    return gtm;
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) Date(java.util.Date) I18nManager(org.olat.core.util.i18n.I18nManager) CoreSpringFactory(org.olat.core.CoreSpringFactory) HashMap(java.util.HashMap) TaxonomyCompetence(org.olat.modules.taxonomy.TaxonomyCompetence) Collectors(java.util.stream.Collectors) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) TaxonomyTreeNodeType(org.olat.modules.taxonomy.model.TaxonomyTreeNodeType) List(java.util.List) Locale(java.util.Locale) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Identity(org.olat.core.id.Identity) TaxonomyModule(org.olat.modules.taxonomy.TaxonomyModule) TaxonomyService(org.olat.modules.taxonomy.TaxonomyService) Map(java.util.Map) StringHelper(org.olat.core.util.StringHelper) TaxonomyCompetenceTypes(org.olat.modules.taxonomy.TaxonomyCompetenceTypes) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) Taxonomy(org.olat.modules.taxonomy.Taxonomy) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) HashMap(java.util.HashMap) VFSContainer(org.olat.core.util.vfs.VFSContainer) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) TaxonomyLevelType(org.olat.modules.taxonomy.TaxonomyLevelType) TaxonomyTreeNode(org.olat.modules.taxonomy.model.TaxonomyTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Aggregations

TreeModel (org.olat.core.gui.components.tree.TreeModel)28 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)16 TreeNode (org.olat.core.gui.components.tree.TreeNode)14 ArrayList (java.util.ArrayList)10 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 TaxonomyTreeNode (org.olat.modules.taxonomy.model.TaxonomyTreeNode)8 HashMap (java.util.HashMap)6 List (java.util.List)6 Map (java.util.Map)6 Identity (org.olat.core.id.Identity)6 StringHelper (org.olat.core.util.StringHelper)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 Taxonomy (org.olat.modules.taxonomy.Taxonomy)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 TaxonomyTreeBuilder (org.olat.modules.taxonomy.manager.TaxonomyTreeBuilder)6 Date (java.util.Date)4 Locale (java.util.Locale)4 Collectors (java.util.stream.Collectors)4 Component (org.olat.core.gui.components.Component)4 AssertException (org.olat.core.logging.AssertException)4