use of org.olat.core.gui.components.tree.GenericTreeModel in project openolat by klemens.
the class QPoolTaxonomyTreeBuilder method buildTreeModel.
public TreeModel buildTreeModel() {
GenericTreeModel gtm = new GenericTreeModel();
TaxonomyLevelNode root = new TaxonomyLevelNode();
gtm.setRootNode(root);
List<TaxonomyLevel> taxonomyLevels = qpoolService.getTaxonomyLevels();
Map<Long, TaxonomyLevel> keytoLevels = taxonomyLevels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
Map<Long, TaxonomyLevelNode> fieldKeyToNode = new HashMap<>();
for (TaxonomyLevel taxonomyLevel : taxonomyLevels) {
Long key = taxonomyLevel.getKey();
TaxonomyLevelNode node = fieldKeyToNode.get(key);
if (node == null) {
node = new TaxonomyLevelNode(taxonomyLevel);
TaxonomyLevelType type = taxonomyLevel.getType();
if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
node.setIconCssClass(type.getCssClass());
}
fieldKeyToNode.put(key, node);
}
TaxonomyLevel parentLevel = taxonomyLevel.getParent();
if (parentLevel == null) {
// this is a root
root.addChild(node);
} else {
Long parentKey = parentLevel.getKey();
TaxonomyLevelNode parentNode = fieldKeyToNode.get(parentKey);
if (parentNode == null) {
// to use the fetched type
parentLevel = keytoLevels.get(parentKey);
parentNode = new TaxonomyLevelNode(parentLevel);
TaxonomyLevelType type = parentLevel.getType();
if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
parentNode.setIconCssClass(type.getCssClass());
}
fieldKeyToNode.put(parentKey, parentNode);
}
parentNode.addChild(node);
}
}
sort(root);
return gtm;
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project openolat by klemens.
the class SelectTaxonomyLevelController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
taxonomyTreesModel = new GenericTreeModel();
taxonomyTreesEl = uifactory.addTreeMultiselect("taxonomy", null, formLayout, taxonomyTreesModel, this);
taxonomyTreesEl.setRootVisible(false);
uifactory.addFormCancelButton("cancel", formLayout, ureq, getWindowControl());
uifactory.addFormSubmitButton("ok", formLayout);
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project openolat by klemens.
the class TaxonomyTreeBuilder method buildTreeModel.
public TreeModel buildTreeModel() {
GenericTreeModel gtm = new GenericTreeModel();
TaxonomyTreeNode root = new TaxonomyTreeNode(taxonomy);
root.setTitle("ROOT competence");
gtm.setRootNode(root);
if (taxonomy != null) {
taxonomy = taxonomyService.getTaxonomy(taxonomy);
if (StringHelper.containsNonWhitespace(rootTitle)) {
root.setTitle(rootTitle);
} else {
root.setTitle(taxonomy.getDisplayName());
}
root.setUserObject(taxonomy);
// taxonomy directory
if (enableTemplates) {
VFSContainer taxonomyDirectory = taxonomyService.getDocumentsLibrary(taxonomy);
TaxonomyTreeNode taxonomyDirectorNode = new TaxonomyTreeNode(taxonomy, taxonomyDirectory, TaxonomyTreeNodeType.templates);
if (locale == null) {
locale = CoreSpringFactory.getImpl(I18nManager.class).getCurrentThreadLocale();
}
taxonomyDirectorNode.setTitle(templateDirectory);
taxonomyDirectorNode.setUserObject(taxonomyDirectory);
root.addChild(taxonomyDirectorNode);
}
// taxonomy levels
List<TaxonomyLevel> levels = taxonomyService.getTaxonomyLevels(taxonomy);
Map<Long, TaxonomyLevel> keytoLevels = levels.stream().collect(Collectors.toMap(l -> l.getKey(), l -> l));
Map<Long, TaxonomyTreeNode> fieldKeyToNode = new HashMap<>();
for (TaxonomyLevel taxonomyLevel : levels) {
Long key = taxonomyLevel.getKey();
TaxonomyTreeNode node = fieldKeyToNode.get(key);
if (node == null) {
node = new TaxonomyTreeNode(taxonomy, taxonomyLevel, getType(taxonomyLevel));
TaxonomyLevelType type = taxonomyLevel.getType();
if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
node.setIconCssClass(type.getCssClass());
}
fieldKeyToNode.put(key, node);
}
TaxonomyLevel parentLevel = taxonomyLevel.getParent();
if (parentLevel == null) {
// this is a root
root.addChild(node);
} else {
Long parentKey = parentLevel.getKey();
TaxonomyTreeNode parentNode = fieldKeyToNode.get(parentKey);
if (parentNode == null) {
// to use the fetched type
parentLevel = keytoLevels.get(parentKey);
parentNode = new TaxonomyTreeNode(taxonomy, parentLevel, getType(parentLevel));
TaxonomyLevelType type = parentLevel.getType();
if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) {
parentNode.setIconCssClass(type.getCssClass());
}
fieldKeyToNode.put(parentKey, parentNode);
}
parentNode.addChild(node);
}
}
computePermissions(root);
trimVisiblity(root);
sort(root);
}
return gtm;
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project openolat by klemens.
the class TaxonomyAllTreesBuilder method getFlattedModel.
/**
* @param taxonomy
* @return
*/
public List<TreeNode> getFlattedModel(Taxonomy taxonomy, boolean withRootNode) {
GenericTreeModel taxonomyTreeModel = new GenericTreeModel();
new TaxonomyAllTreesBuilder().loadTreeModel(taxonomyTreeModel, taxonomy);
List<TreeNode> nodeList = new ArrayList<>();
TreeHelper.makeTreeFlat(taxonomyTreeModel.getRootNode(), nodeList);
if (withRootNode) {
return nodeList;
}
return nodeList.subList(1, nodeList.size());
}
use of org.olat.core.gui.components.tree.GenericTreeModel in project openolat by klemens.
the class WikiMainController method getAndUseExternalTree.
public GenericTreeModel getAndUseExternalTree() {
final String resId = ores.getResourceableId().toString();
Wiki wiki = getWiki();
wikiMenuModel = new GenericTreeModel();
String root = "wiki-" + resId;
GenericTreeNode rootNode = new GenericTreeNode(root);
wikiMenuModel.setRootNode(rootNode);
// Index
String navMainItem = "nav-main-item-" + resId;
navMainPageNode = new GenericTreeNode(navMainItem, translate("navigation.mainpage"), navMainItem);
rootNode.addChild(navMainPageNode);
// Wiki-Menu
String wikiMenuTitle = translate("navigation.menu");
String wikiMenuItem = "menu-item-" + resId;
wikiMenuNode = new GenericTreeNode(wikiMenuItem, wikiMenuTitle, wikiMenuItem);
rootNode.addChild(wikiMenuNode);
String navAZItem = "nav-az-item-" + resId;
navAZNode = new GenericTreeNode(navAZItem, translate("navigation.a-z"), navAZItem);
rootNode.addChild(navAZNode);
String navChangesItem = "nav-changes-item-" + resId;
navChangesNode = new GenericTreeNode(navChangesItem, translate("navigation.changes"), navChangesItem);
rootNode.addChild(navChangesNode);
updateWikiMenu(wiki);
navigationDropdown.setVisible(false);
wikiMenuDropdown.setVisible(false);
navigationContent.contextPut("navigationEnabled", Boolean.FALSE);
return wikiMenuModel;
}
Aggregations