Search in sources :

Example 16 with GenericTreeModel

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

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 17 with GenericTreeModel

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

the class SelectTaxonomyLevelController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    taxonomyTreesModel = new GenericTreeModel();
    taxonomyTreesEl = uifactory.addTreeMultiselect("taxonomy", null, formLayout, taxonomyTreesModel, this);
    taxonomyTreesEl.setRootVisible(false);
    uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
    uifactory.addFormSubmitButton("ok", formLayout);
}
Also used : GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 18 with GenericTreeModel

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

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)

Example 19 with GenericTreeModel

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

the class TaxonomyAllTreesBuilder method getFlattedModel.

/**
 * @param taxonomy
 * @return
 */
public List<TreeNode> getFlattedModel(Taxonomy taxonomy, boolean withRootNode) {
    GenericTreeModel taxonomyTreeModel = new GenericTreeModel();
    new TaxonomyAllTreesBuilder().loadTreeModel(taxonomyTreeModel, taxonomy);
    List<TreeNode> nodeList = new ArrayList<>();
    TreeHelper.makeTreeFlat(taxonomyTreeModel.getRootNode(), nodeList);
    if (withRootNode) {
        return nodeList;
    }
    return nodeList.subList(1, nodeList.size());
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) ArrayList(java.util.ArrayList) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 20 with GenericTreeModel

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

the class WikiMainController method getAndUseExternalTree.

public GenericTreeModel getAndUseExternalTree() {
    final String resId = ores.getResourceableId().toString();
    Wiki wiki = getWiki();
    wikiMenuModel = new GenericTreeModel();
    String root = "wiki-" + resId;
    GenericTreeNode rootNode = new GenericTreeNode(root);
    wikiMenuModel.setRootNode(rootNode);
    // Index
    String navMainItem = "nav-main-item-" + resId;
    navMainPageNode = new GenericTreeNode(navMainItem, translate("navigation.mainpage"), navMainItem);
    rootNode.addChild(navMainPageNode);
    // Wiki-Menu
    String wikiMenuTitle = translate("navigation.menu");
    String wikiMenuItem = "menu-item-" + resId;
    wikiMenuNode = new GenericTreeNode(wikiMenuItem, wikiMenuTitle, wikiMenuItem);
    rootNode.addChild(wikiMenuNode);
    String navAZItem = "nav-az-item-" + resId;
    navAZNode = new GenericTreeNode(navAZItem, translate("navigation.a-z"), navAZItem);
    rootNode.addChild(navAZNode);
    String navChangesItem = "nav-changes-item-" + resId;
    navChangesNode = new GenericTreeNode(navChangesItem, translate("navigation.changes"), navChangesItem);
    rootNode.addChild(navChangesNode);
    updateWikiMenu(wiki);
    navigationDropdown.setVisible(false);
    wikiMenuDropdown.setVisible(false);
    navigationContent.contextPut("navigationEnabled", Boolean.FALSE);
    return wikiMenuModel;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Aggregations

GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)62 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)42 TreeNode (org.olat.core.gui.components.tree.TreeNode)20 CourseNode (org.olat.course.nodes.CourseNode)12 Extension (org.olat.core.extensions.Extension)10 GenericActionExtension (org.olat.core.extensions.action.GenericActionExtension)10 AssertException (org.olat.core.logging.AssertException)10 ArrayList (java.util.ArrayList)8 ActionExtension (org.olat.core.extensions.action.ActionExtension)8 Controller (org.olat.core.gui.control.Controller)8 WindowControl (org.olat.core.gui.control.WindowControl)8 Identity (org.olat.core.id.Identity)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 STCourseNode (org.olat.course.nodes.STCourseNode)8 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)8 List (java.util.List)6 ExtManager (org.olat.core.extensions.ExtManager)6 TreeModel (org.olat.core.gui.components.tree.TreeModel)6 ControllerEventListener (org.olat.core.gui.control.ControllerEventListener)6 TitledWrapperController (org.olat.core.gui.control.generic.title.TitledWrapperController)6