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);
}
}
}
}
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;
}
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;
}
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;
}
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());
}
}
Aggregations