Search in sources :

Example 81 with GenericTreeNode

use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.

the class AssessmentHelper method assessmentTreeModel.

/**
 * @param course
 * @return
 */
public static TreeModel assessmentTreeModel(ICourse course) {
    CourseNode rootNode = course.getRunStructure().getRootNode();
    GenericTreeModel gtm = new GenericTreeModel();
    GenericTreeNode node = new GenericTreeNode();
    node.setTitle(rootNode.getShortTitle());
    node.setUserObject(rootNode);
    node.setIconCssClass(CourseNodeFactory.getInstance().getCourseNodeConfiguration(rootNode.getType()).getIconCSSClass());
    gtm.setRootNode(node);
    List<GenericTreeNode> children = addAssessableNodesToList(rootNode);
    children.forEach((child) -> node.addChild(child));
    return gtm;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode)

Example 82 with GenericTreeNode

use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.

the class CourseInternalLinkTreeModel method convertToTreeNode.

/**
 * Internal helper to convert the given course node into a tree node. The
 * course node identifyer will be transfered onto the tree nodes identifyer
 *
 * @param courseNode
 * @return the course node as converted tree node
 */
private TreeNode convertToTreeNode(CourseNode courseNode) {
    // create convert this course node to a tree node
    GenericTreeNode treeNode = new GenericTreeNode();
    treeNode.setIdent(courseNode.getIdent());
    treeNode.setTitle(courseNode.getShortTitle());
    treeNode.setIconCssClass(CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).getIconCSSClass());
    // go through all children and add them as converted tree nodes
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        CourseNode child = (CourseNode) courseNode.getChildAt(i);
        treeNode.addChild(convertToTreeNode(child));
    }
    return treeNode;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 83 with GenericTreeNode

use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.

the class CPTreeDataModel method update.

public void update() {
    String realNodeId = getIdentifierForNodeID(rootNodeId);
    DefaultElement el = cp.getElementByIdentifier(realNodeId);
    if (el instanceof CPOrganization) {
        CPOrganization item = (CPOrganization) el;
        String rootTitle = cp.getFirstOrganizationInManifest().getTitle();
        GenericTreeNode rootNode = new GenericTreeNode(rootNodeId, rootTitle, item);
        rootNode.setIconCssClass("o_cp_org");
        List<TreeNode> children = getChildrenFor(rootNodeId);
        for (TreeNode child : children) {
            rootNode.addChild(child);
            buildTreeModel(child);
        }
        setRootNode(rootNode);
    }
}
Also used : DefaultElement(org.dom4j.tree.DefaultElement) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CPOrganization(org.olat.ims.cp.objects.CPOrganization)

Example 84 with GenericTreeNode

use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.

the class CPManifestTreeModel method buildNode.

private GenericTreeNode buildNode(Element item) {
    GenericTreeNode gtn = new GenericTreeNode();
    // fxdiff VCRP-13: cp navigation
    treeNodes.add(gtn);
    // extract title
    String title = item.elementText("title");
    if (title == null)
        title = item.attributeValue("identifier");
    String identifier = item.attributeValue("identifier");
    gtn.setAltText(title);
    gtn.setTitle(title);
    if (item.getName().equals("organization")) {
        // Add first level item for organization
        gtn.setIconCssClass("o_cp_org");
        gtn.setAccessible(false);
        // Special case check: CP with only one page: hide the page and show it directly under the organization element
        @SuppressWarnings("unchecked") List<Element> chds = item.elements("item");
        if (chds.size() == 1) {
            // check 1: only one child
            Element childitem = chds.get(0);
            @SuppressWarnings("unchecked") List<Element> grandChds = childitem.elements("item");
            if (grandChds.size() == 0) {
                // check 2: no grand children
                String identifierref = childitem.attributeValue("identifierref");
                String href = resources.get(identifierref);
                if (href != null) {
                    // check 3: a resource is attached to the child
                    // = success, we have a CP with only one page. Use this page and exit
                    XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']");
                    meta.setNamespaceURIs(nsuris);
                    gtn.setAccessible(true);
                    gtn.setUserObject(href);
                    if (hrefToTreeNode.containsKey(href)) {
                        log.debug("Duplicate href::" + href + " for identifierref::" + identifierref + " and identifier::" + identifier + ", use first one");
                    } else {
                        hrefToTreeNode.put(href, gtn);
                    }
                    return gtn;
                }
            }
        }
    } else if (item.getName().equals("item")) {
        gtn.setIconCssClass("o_cp_item");
        // set resolved file path directly
        String identifierref = item.attributeValue("identifierref");
        if (identifierref != null) {
            gtn.setIdent("cp" + Encoder.md5hash(identPrefix + identifierref));
        }
        XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']");
        meta.setNamespaceURIs(nsuris);
        String href = resources.get(identifierref);
        if (href != null) {
            gtn.setUserObject(href);
            // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text
            if (hrefToTreeNode.containsKey(href)) {
                log.debug("Duplicate href::" + href + " for identifierref::" + identifierref + " and identifier::" + identifier + ", use first one");
            } else {
                hrefToTreeNode.put(href, gtn);
            }
        } else {
            gtn.setAccessible(false);
        }
    }
    @SuppressWarnings("unchecked") List<Element> chds = item.elements("item");
    int childcnt = chds.size();
    for (int i = 0; i < childcnt; i++) {
        Element childitem = chds.get(i);
        GenericTreeNode gtnchild = buildNode(childitem);
        gtn.addChild(gtnchild);
        // set the first accessible child in the hierarchy as delegate when the node itself is not accessible
        if (gtn.isAccessible() == false) {
            GenericTreeNode nextHierarchyChild = gtnchild;
            while (gtn.getDelegate() == null && nextHierarchyChild != null) {
                if (nextHierarchyChild.isAccessible()) {
                    gtn.setDelegate(nextHierarchyChild);
                } else {
                    if (nextHierarchyChild.getChildCount() > 0) {
                        nextHierarchyChild = (GenericTreeNode) nextHierarchyChild.getChildAt(0);
                    } else {
                        nextHierarchyChild = null;
                    }
                }
            }
            if (!gtn.isAccessible()) {
                log.debug("No accessible child found that could be used as delegate for identifier::" + identifier);
            }
        }
    }
    return gtn;
}
Also used : XPath(org.dom4j.XPath) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) Element(org.dom4j.Element)

Example 85 with GenericTreeNode

use of org.olat.core.gui.components.tree.GenericTreeNode in project openolat by klemens.

the class CatalogTreeModel method buildTree.

/**
 * Build the selection tree from the given list of entries
 * @param entryList
 * @return The root node of the tree
 */
private GenericTreeNode buildTree(List<CatalogEntry> entryList) {
    GenericTreeNode rootNode = null;
    // build the tree - note that the entry list is not ordered in any way
    if (entryList != null) {
        for (CatalogEntry elem : entryList) {
            // create a tree node and add it to the entry map
            GenericTreeNode n = addNode(elem);
            if (n != null) {
                // a node was created, keep it as a potential root node candidate
                rootNode = addNode(elem);
            }
        }
    }
    // walk to the final root node of the tree
    while (rootNode != null && rootNode.getParent() != null) {
        rootNode = (GenericTreeNode) rootNode.getParent();
    }
    // we always need a root
    if (rootNode == null) {
        rootNode = new GenericTreeNode("keine Node :(", null);
    }
    calculateAccessibility(rootNode);
    return rootNode;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) CatalogEntry(org.olat.repository.CatalogEntry)

Aggregations

GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)124 TreeNode (org.olat.core.gui.components.tree.TreeNode)30 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)24 CourseNode (org.olat.course.nodes.CourseNode)10 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)10 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)10 HashMap (java.util.HashMap)8 INode (org.olat.core.util.nodes.INode)8 ArrayList (java.util.ArrayList)6 Element (org.dom4j.Element)6 XPath (org.dom4j.XPath)6 ExtManager (org.olat.core.extensions.ExtManager)6 Extension (org.olat.core.extensions.Extension)6 CatalogEntry (org.olat.repository.CatalogEntry)6 ActionExtension (org.olat.core.extensions.action.ActionExtension)4 GenericActionExtension (org.olat.core.extensions.action.GenericActionExtension)4 CourseNodeConfiguration (org.olat.course.nodes.CourseNodeConfiguration)4 QTI21QuestionType (org.olat.ims.qti21.model.QTI21QuestionType)4 Taxonomy (org.olat.modules.taxonomy.Taxonomy)4 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)4