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