Search in sources :

Example 6 with TaxonomyLevelRef

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;
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) TaxonomyLevelRef(org.olat.modules.taxonomy.TaxonomyLevelRef) HashSet(java.util.HashSet)

Aggregations

TaxonomyLevelRef (org.olat.modules.taxonomy.TaxonomyLevelRef)6 HashSet (java.util.HashSet)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)4 ArrayList (java.util.ArrayList)2 TaxonomyLevelType (org.olat.modules.taxonomy.TaxonomyLevelType)2 TaxonomyLevelTypeRef (org.olat.modules.taxonomy.TaxonomyLevelTypeRef)2 TaxonomyLevelRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelRefImpl)2 TaxonomyLevelTypeRefImpl (org.olat.modules.taxonomy.model.TaxonomyLevelTypeRefImpl)2