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