use of org.olat.core.gui.components.tree.GenericTreeModel 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;
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project OpenOLAT by OpenOLAT.
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());
}
use of org.olat.core.gui.components.tree.GenericTreeModel 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;
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project OpenOLAT by OpenOLAT.
the class QTIStatisticResourceResult method getSubTreeModel.
@Override
public TreeModel getSubTreeModel() {
GenericTreeModel subTreeModel;
if (type == QTIType.onyx) {
subTreeModel = new GenericTreeModel();
StatisticResourceNode rootTreeNode = new StatisticResourceNode(courseNode, this);
subTreeModel.setRootNode(rootTreeNode);
} else if (qtiDocument == null) {
subTreeModel = null;
} else {
subTreeModel = new GenericTreeModel();
StatisticResourceNode rootTreeNode = new StatisticResourceNode(courseNode, this);
subTreeModel.setRootNode(rootTreeNode);
buildQTICourseNodeSubTree(qtiDocument, rootTreeNode);
}
return subTreeModel;
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project OpenOLAT by OpenOLAT.
the class CatalogHelper method createCatalogTree.
/**
* Map the OLAT catalog structure to a new tree model.
*
* @param rootEntry root catalog entry
* @return tree model with catalog structure
*/
public static final TreeModel createCatalogTree(final CatalogEntry rootEntry) {
final GenericTreeModel tm = new GenericTreeModel();
tm.setRootNode(buildCatalogNode(rootEntry));
return tm;
}
Aggregations