use of org.olat.core.gui.components.tree.TreeModel in project openolat by klemens.
the class GenericMainController method init.
/**
* use after optional addChildNodeToAppend() or addChildNodeToPrepend() calls
* to initialize MainController and set Panel
*
* @param ureq
*/
public void init(UserRequest ureq) {
olatMenuTree = new MenuTree("olatMenuTree");
TreeModel tm = buildTreeModel(ureq);
olatMenuTree.setTreeModel(tm);
content = new Panel("content");
TreeNode firstNode = tm.getRootNode();
TreeNode nodeToSelect = getLastDelegate(firstNode);
olatMenuTree.setSelectedNodeId(nodeToSelect.getIdent());
olatMenuTree.addListener(this);
// default is to not display the root element and to let user open/close sub elements
olatMenuTree.setRootVisible(false);
olatMenuTree.setExpandSelectedNode(false);
Object uobject = nodeToSelect.getUserObject();
contentCtr = getContentCtr(uobject, ureq);
// auto dispose later
listenTo(contentCtr);
Component resComp = contentCtr.getInitialComponent();
content.setContent(resComp);
columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), olatMenuTree, content, className);
// auto dispose later
listenTo(columnLayoutCtr);
// create the stack
stackVC = new BreadcrumbedStackedPanel("genericStack", getTranslator(), this);
stackVC.pushController("content", columnLayoutCtr);
putInitialPanel(stackVC);
}
use of org.olat.core.gui.components.tree.TreeModel 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.TreeModel in project openolat by klemens.
the class TaxonomyLevelLibraryIndexer method checkAccess.
@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
if (roles.isOLATAdmin())
return true;
if ("TaxonomyLevel".equals(contextEntry.getOLATResourceable().getResourceableTypeName())) {
Long levelKey = contextEntry.getOLATResourceable().getResourceableId();
TaxonomyLevel level = taxonomyService.getTaxonomyLevel(new TaxonomyLevelRefImpl(levelKey));
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(level.getTaxonomy(), identity, null, false, true, "Templates", null);
TreeModel model = builder.buildTreeModel();
List<TreeNode> flat = new ArrayList<>();
TreeHelper.makeTreeFlat(model.getRootNode(), flat);
for (TreeNode node : flat) {
TaxonomyTreeNode taxonomyNode = (TaxonomyTreeNode) node;
if (taxonomyNode.getType() == TaxonomyTreeNodeType.taxonomyLevel && level.equals(taxonomyNode.getTaxonomyLevel())) {
if (taxonomyNode.isDocumentsLibraryEnabled() && taxonomyNode.isCanRead()) {
return true;
}
}
}
}
return false;
}
use of org.olat.core.gui.components.tree.TreeModel 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.TreeModel in project openolat by klemens.
the class DocumentPoolNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
SubscriptionInfo si;
String taxonomyKey = documentPoolModule.getTaxonomyTreeKey();
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews) && StringHelper.isLong(taxonomyKey)) {
Taxonomy taxonomy = taxonomyService.getTaxonomy(new TaxonomyRefImpl(new Long(taxonomyKey)));
if (taxonomy == null) {
return notificationsManager.getNoSubscriptionInfo();
}
Identity identity = subscriber.getIdentity();
Roles roles = securityManager.getRoles(identity);
boolean isTaxonomyAdmin = roles.isOLATAdmin();
Translator translator = Util.createPackageTranslator(DocumentPoolMainController.class, locale);
String templates = translator.translate("document.pool.templates");
TaxonomyTreeBuilder builder = new TaxonomyTreeBuilder(taxonomy, identity, null, isTaxonomyAdmin, documentPoolModule.isTemplatesDirectoryEnabled(), templates, locale);
TreeModel model = builder.buildTreeModel();
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), getTitleItemForPublisher(), null);
new TreeVisitor(node -> {
TaxonomyTreeNode tNode = (TaxonomyTreeNode) node;
if (tNode.getTaxonomyLevel() != null && tNode.isDocumentsLibraryEnabled() && tNode.isCanRead()) {
VFSContainer container = taxonomyService.getDocumentsLibrary(tNode.getTaxonomyLevel());
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][TaxonomyLevel:" + tNode.getTaxonomyLevel().getKey() + "][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
} else if (tNode.getType() == TaxonomyTreeNodeType.templates) {
VFSContainer container = taxonomyService.getDocumentsLibrary(taxonomy);
String prefixBusinessPath = "[DocumentPool:" + taxonomy.getKey() + "][Templates:0s][path=";
createSubscriptionInfo(container, prefixBusinessPath, compareDate, si, p, translator);
}
}, model.getRootNode(), false).visitAll();
} else {
si = NotificationsManager.getInstance().getNoSubscriptionInfo();
}
return si;
} catch (Exception e) {
log.error("Cannot create document pool notifications for subscriber: " + subscriber.getKey(), e);
return notificationsManager.getNoSubscriptionInfo();
}
}
Aggregations