use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.
the class TaxonomyTreeNodeComparator method compare.
@Override
public int compare(INode i1, INode i2) {
if (i1 == null || i2 == null) {
return compareNullObjects(i1, i2);
}
Integer s1 = null;
Integer s2 = null;
String title1 = null;
String title2 = null;
TaxonomyTreeNodeType type1 = null;
TaxonomyTreeNodeType type2 = null;
if (i1 instanceof TaxonomyTreeNode) {
TaxonomyTreeNode t1 = (TaxonomyTreeNode) i1;
title1 = t1.getTitle();
type1 = t1.getType();
if (t1.getTaxonomyLevel() != null) {
s1 = t1.getTaxonomyLevel().getSortOrder();
}
} else if (i1 instanceof GenericTreeNode) {
GenericTreeNode node = (GenericTreeNode) i1;
title1 = node.getTitle();
Object uobject = node.getUserObject();
if (uobject instanceof TaxonomyLevel) {
TaxonomyLevel level = (TaxonomyLevel) uobject;
type1 = TaxonomyTreeNodeType.taxonomyLevel;
s1 = level.getSortOrder();
}
}
if (i2 instanceof TaxonomyTreeNode) {
TaxonomyTreeNode t2 = (TaxonomyTreeNode) i2;
title2 = t2.getTitle();
type2 = t2.getType();
if (t2.getTaxonomyLevel() != null) {
s2 = t2.getTaxonomyLevel().getSortOrder();
}
} else if (i1 instanceof GenericTreeNode) {
GenericTreeNode node = (GenericTreeNode) i2;
title2 = node.getTitle();
Object uobject = node.getUserObject();
if (uobject instanceof TaxonomyLevel) {
TaxonomyLevel level = (TaxonomyLevel) uobject;
type2 = TaxonomyTreeNodeType.taxonomyLevel;
s2 = level.getSortOrder();
}
}
int c = 0;
if (type1 == TaxonomyTreeNodeType.templates && type2 == TaxonomyTreeNodeType.templates) {
c = 0;
} else if (type1 == TaxonomyTreeNodeType.templates) {
return -1;
} else if (type2 == TaxonomyTreeNodeType.templates) {
return 1;
}
if (type1 == TaxonomyTreeNodeType.lostAndFound && type2 == TaxonomyTreeNodeType.lostAndFound) {
c = 0;
} else if (type1 == TaxonomyTreeNodeType.lostAndFound) {
return 1;
} else if (type2 == TaxonomyTreeNodeType.lostAndFound) {
return -1;
}
if (c == 0) {
if (s1 == null || s2 == null) {
c = compareNullObjects(s1, s2);
} else {
c = s1.compareTo(s2);
}
}
if (c == 0) {
if (title1 == null || title2 == null) {
c = compareNullObjects(title1, title2);
} else {
c = title1.compareTo(title2);
}
}
return c;
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.
the class CPManifestTreeModel method initDocument.
private void initDocument(Document doc) {
// get all organization elements. need to set namespace
rootElement = doc.getRootElement();
String nsuri = rootElement.getNamespace().getURI();
nsuris.put("ns", nsuri);
XPath meta = rootElement.createXPath("//ns:organization");
meta.setNamespaceURIs(nsuris);
// TODO: accept several organizations?
Element orgaEl = (Element) meta.selectSingleNode(rootElement);
if (orgaEl == null)
throw new AssertException("could not find element organization");
XPath metares = rootElement.createXPath("//ns:resources");
metares.setNamespaceURIs(nsuris);
Element elResources = (Element) metares.selectSingleNode(rootElement);
if (elResources == null)
throw new AssertException("could not find element resources");
@SuppressWarnings("unchecked") List<Element> resourcesList = elResources.elements("resource");
resources = new HashMap<String, String>(resourcesList.size());
for (Iterator<Element> iter = resourcesList.iterator(); iter.hasNext(); ) {
Element elRes = iter.next();
String identVal = elRes.attributeValue("identifier");
String hrefVal = elRes.attributeValue("href");
if (hrefVal != null) {
// href is optional element for resource element
try {
hrefVal = URLDecoder.decode(hrefVal, "UTF-8");
} catch (UnsupportedEncodingException e) {
// each JVM must implement UTF-8
}
}
resources.put(identVal, hrefVal);
}
GenericTreeNode gtn = buildNode(orgaEl);
setRootNode(gtn);
// help gc
rootElement = null;
resources = null;
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.
the class CoachMainController method buildTreeModel.
private TreeModel buildTreeModel(UserRequest ureq) {
GenericTreeModel gtm = new GenericTreeModel();
GenericTreeNode root = new GenericTreeNode();
gtm.setRootNode(root);
GenericTreeNode students = new GenericTreeNode();
students.setUserObject("Members");
students.setTitle(translate("students.menu.title"));
students.setAltText(translate("students.menu.title.alt"));
root.addChild(students);
GenericTreeNode groups = new GenericTreeNode();
groups.setUserObject("Groups");
groups.setTitle(translate("groups.menu.title"));
groups.setAltText(translate("groups.menu.title.alt"));
root.addChild(groups);
GenericTreeNode courses = new GenericTreeNode();
courses.setUserObject("Courses");
courses.setTitle(translate("courses.menu.title"));
courses.setAltText(translate("courses.menu.title.alt"));
root.addChild(courses);
if (lectureModule.isEnabled()) {
GenericTreeNode lectures = new GenericTreeNode();
lectures.setUserObject("Lectures");
lectures.setTitle(translate("lectures.menu.title"));
lectures.setAltText(translate("courses.menu.title.alt"));
root.addChild(lectures);
}
Roles roles = ureq.getUserSession().getRoles();
if (roles.isUserManager() || roles.isOLATAdmin()) {
GenericTreeNode search = new GenericTreeNode();
search.setUserObject("Search");
search.setTitle(translate("search.menu.title"));
search.setAltText(translate("search.menu.title.alt"));
root.addChild(search);
}
return gtm;
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.
the class CatalogTreeModel method addNode.
/**
* Create and add a node to the tree
* @param entry
* @return
*/
private GenericTreeNode addNode(CatalogEntry entry) {
GenericTreeNode node = entryMap.get(entry.getKey());
if (node == null && entry.getType() == CatalogEntry.TYPE_NODE) {
if (entry.getParent() != null) {
node = entryMap.get(entry.getParent().getKey());
if (node != null) {
GenericTreeNode build = buildNode(entry);
node.addChild(build);
build.setParent(node);
} else {
addMissingNodes(entry);
}
} else {
// it's the root
node = buildNode(entry);
}
}
return node;
}
use of org.olat.core.gui.components.tree.GenericTreeNode in project OpenOLAT by OpenOLAT.
the class CatalogTreeModel method calculateAccessibility.
/**
* Limit accessability to node to the nodes that are owned by the current user
*/
private void calculateAccessibility(GenericTreeNode rootNode) {
GenericTreeNode node = null;
// first : allow access to all children of the owned entries
if (ownedEntries != null) {
for (CatalogEntry entry : ownedEntries) {
node = entryMap.get(entry.getKey());
changeAccessibility(node, true);
}
}
// to avoid circles and not dissolve elements from the catalog root )
if (entryToMove != null && entryToMove.getType() == CatalogEntry.TYPE_NODE) {
node = entryMap.get(entryToMove.getKey());
changeAccessibility(node, false);
}
// entries are owned, we assume that all entries can be selected by user
if (entryToMove == null && ownedEntries == null) {
changeAccessibility(rootNode, true);
}
}
Aggregations