use of org.olat.modules.taxonomy.ui.TaxonomyLevelRow 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;
}
use of org.olat.modules.taxonomy.ui.TaxonomyLevelRow in project openolat by klemens.
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;
}
Aggregations