Search in sources :

Example 1 with GenericTreeModel

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

the class NavigationHandler method doEvaluateJumpTo.

private NodeClickedRef doEvaluateJumpTo(UserRequest ureq, WindowControl wControl, CourseNode courseNode, ControllerEventListener listeningController, String nodecmd, String nodeSubCmd, Controller currentNodeController) {
    NodeClickedRef nclr;
    if (log.isDebug()) {
        log.debug("evaluateJumpTo courseNode = " + courseNode.getIdent() + ", " + courseNode.getShortName());
    }
    // build the new treemodel by evaluating the preconditions
    TreeEvaluation treeEval = new TreeEvaluation();
    GenericTreeModel treeModel = new GenericTreeModel();
    CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
    NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
    TreeNode treeRoot = rootNodeEval.getTreeNode();
    treeModel.setRootNode(treeRoot);
    // find the treenode that corresponds to the node (!= selectedTreeNode since
    // we built the TreeModel anew in the meantime
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        // the clicked node is not visible anymore!
        // if the new calculated model does not contain the selected node anymore
        // (because of visibility changes of at least one of the ancestors
        // -> issue an user infomative msg
        // nclr: the new treemodel, not visible, no selected nodeid, no
        // calledcoursenode, no nodeconstructionresult
        nclr = new NodeClickedRef(treeModel, false, null, null, null, null, false);
    } else {
        // calculate the NodeClickedRef
        // 1. get the correct (new) nodeevaluation
        NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
        if (nodeEval.getCourseNode() != courseNode) {
            throw new AssertException("error in structure");
        }
        if (!nodeEval.isVisible()) {
            throw new AssertException("node eval not visible!!");
        }
        // 2. start with the current NodeEvaluation, evaluate overall accessiblity
        // per node bottom-up to see if all ancestors still grant access to the
        // desired node
        boolean mayAccessWholeTreeUp = mayAccessWholeTreeUp(nodeEval);
        String newSelectedNodeId = newCalledTreeNode.getIdent();
        Controller controller;
        AdditionalConditionManager addMan = null;
        if (courseNode instanceof AbstractAccessableCourseNode) {
            Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
            CourseNodePasswordManager cnpm = CourseNodePasswordManagerImpl.getInstance();
            Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
            AdditionalConditionAnswerContainer answerContainer = cnpm.getAnswerContainer(identity);
            addMan = new AdditionalConditionManager((AbstractAccessableCourseNode) courseNode, courseId, answerContainer);
        }
        if (!mayAccessWholeTreeUp || (addMan != null && !addMan.evaluateConditions())) {
            if (nodeEval.oldStyleConditionsOk()) {
                controller = addMan.nextUserInputController(ureq, wControl, userCourseEnv);
                if (listeningController != null) {
                    controller.addControllerListener(listeningController);
                }
            } else {
                // NOTE: we do not take into account what node caused the non-access by
                // being !isAtLeastOneAccessible, but always state the
                // NoAccessExplanation of the Node originally called by the user
                String explan = courseNode.getNoAccessExplanation();
                String sExplan = (explan == null ? "" : Formatter.formatLatexFormulas(explan));
                controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, sExplan);
                // write log information
                ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_NO_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
            }
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
            // nodeconstructionresult
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else if (!CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).isEnabled()) {
            Translator pT = Util.createPackageTranslator(EditorMainController.class, ureq.getLocale());
            controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, pT.translate("course.building.block.disabled.user"));
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else {
            if (STCourseNode.isDelegatingSTCourseNode(courseNode) && (courseNode.getChildCount() > 0)) {
                // the clicked node is a STCourse node and is set to "delegate", so
                // delegate to its first visible child; if no child is visible, just skip and do normal eval
                INode child;
                for (int i = 0; i < courseNode.getChildCount(); i++) {
                    child = courseNode.getChildAt(i);
                    if (child instanceof CourseNode) {
                        CourseNode cn = (CourseNode) child;
                        NodeEvaluation cnEval = cn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
                        if (cnEval.isVisible()) {
                            return doEvaluateJumpTo(ureq, wControl, cn, listeningController, nodecmd, nodeSubCmd, currentNodeController);
                        }
                    }
                }
            }
            // access the node, display its result in the right pane
            NodeRunConstructionResult ncr;
            // calculate the new businesscontext for the coursenode being called.
            // type: class of node; key = node.getIdent;
            // don't use the concrete instance since for the course: to jump to a coursenode with a given id is all there is to know
            Class<CourseNode> oresC = CourseNode.class;
            Long oresK = new Long(Long.parseLong(courseNode.getIdent()));
            final OLATResourceable ores = OresHelper.createOLATResourceableInstance(oresC, oresK);
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
            if (previewMode) {
                ncr = new NodeRunConstructionResult(courseNode.createPreviewController(ureq, bwControl, userCourseEnv, nodeEval));
            } else {
                // cleanup already existing controllers with external models for this node first, never disposed otherwise
                if (externalTreeModels.containsKey(courseNode.getIdent()) && !(TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd))) {
                    SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                    ControllerEventListener existingSubtreemodelListener = subTree.getTreeModelListener();
                    if (existingSubtreemodelListener != null && currentNodeController != null && !currentNodeController.isDisposed()) {
                        currentNodeController.dispose();
                    }
                }
                ncr = courseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, nodeEval, nodecmd);
                // remember as instance variable for next click
                ControllerEventListener subtreemodelListener = ncr.getSubTreeListener();
                if (subtreemodelListener != null) {
                    GenericTreeModel subTreeModel = (GenericTreeModel) ncr.getSubTreeModel();
                    externalTreeModels.put(courseNode.getIdent(), new SubTree(ncr.getRunController(), subTreeModel, subtreemodelListener));
                    if (!newSelectedNodeId.equals(ncr.getSelectedTreeNodeId())) {
                        if (ncr.getSelectedTreeNodeId() != null) {
                            TreeNode selectedNode = subTreeModel.getNodeById(ncr.getSelectedTreeNodeId());
                            if (selectedNode != null && selectedNode.getUserObject() instanceof String) {
                                openCourseNodeIds.add((String) selectedNode.getUserObject());
                            }
                        }
                    }
                }
            }
            if (TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd)) {
                openCourseNodeIds.add(courseNode.getIdent());
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
            } else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) {
                removeChildrenFromOpenNodes(courseNode);
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
                if (!isInParentLine(courseNode)) {
                    selectedCourseNodeId = courseNode.getIdent();
                } else {
                    selectedCourseNodeId = null;
                    newSelectedNodeId = null;
                }
            } else {
                // add the selected node to the open one, if not, strange behaviour
                selectedCourseNodeId = courseNode.getIdent();
                openCourseNodeIds.add(selectedCourseNodeId);
                if (ncr != null) {
                    String subNodeId = ncr.getSelectedTreeNodeId();
                    if (subNodeId != null) {
                        openCourseNodeIds.add(subNodeId);
                    }
                }
            }
            openTreeNodeIds = convertToTreeNodeIds(treeEval, openCourseNodeIds);
            reattachExternalTreeModels(treeEval);
            if ((TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) && currentNodeController != null && !currentNodeController.isDisposed()) {
                nclr = new NodeClickedRef(treeModel, true, null, openTreeNodeIds, null, null, false);
            } else {
                // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
                // nodeconstructionresult
                nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, openTreeNodeIds, courseNode, ncr, false);
                // attach listener; we know we have a runcontroller here
                if (listeningController != null) {
                    nclr.getRunController().addControllerListener(listeningController);
                }
            }
            // write log information
            ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
        }
    }
    return nclr;
}
Also used : INode(org.olat.core.util.nodes.INode) OLATResourceable(org.olat.core.id.OLATResourceable) AdditionalConditionManager(org.olat.course.condition.additionalconditions.AdditionalConditionManager) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) Translator(org.olat.core.gui.translator.Translator) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) Identity(org.olat.core.id.Identity) EditorMainController(org.olat.course.editor.EditorMainController) AssertException(org.olat.core.logging.AssertException) EditorMainController(org.olat.course.editor.EditorMainController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) CPRunController(org.olat.course.nodes.cp.CPRunController) Controller(org.olat.core.gui.control.Controller) CourseNodePasswordManager(de.bps.course.nodes.CourseNodePasswordManager) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) AdditionalConditionAnswerContainer(org.olat.course.condition.additionalconditions.AdditionalConditionAnswerContainer)

Example 2 with GenericTreeModel

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

the class MembersManagementMainController method buildTreeModel.

private GenericTreeModel buildTreeModel() {
    GenericTreeModel gtm = new GenericTreeModel();
    GenericTreeNode root = new GenericTreeNode();
    root.setTitle(translate("menu.members"));
    root.setAltText(translate("menu.members.alt"));
    gtm.setRootNode(root);
    if (entryAdmin || memberManagementRight) {
        GenericTreeNode node = new GenericTreeNode(translate("menu.members"), CMD_MEMBERS);
        node.setAltText(translate("menu.members.alt"));
        node.setCssClass("o_sel_membersmgt_members");
        root.addChild(node);
    }
    if (entryAdmin || memberManagementRight || groupManagementRight) {
        GenericTreeNode node = new GenericTreeNode(translate("menu.groups"), CMD_GROUPS);
        node.setAltText(translate("menu.groups.alt"));
        node.setCssClass("o_sel_membersmgt_groups");
        root.addChild(node);
    }
    if (acModule.isEnabled() && (entryAdmin || memberManagementRight)) {
        // check if the course is managed and/or has offers
        if (!RepositoryEntryManagedFlag.isManaged(repoEntry, RepositoryEntryManagedFlag.bookings) || acService.isResourceAccessControled(repoEntry.getOlatResource(), null)) {
            GenericTreeNode node = new GenericTreeNode(translate("menu.orders"), CMD_BOOKING);
            node.setAltText(translate("menu.orders.alt"));
            node.setCssClass("o_sel_membersmgt_orders");
            root.addChild(node);
        }
    }
    if (entryAdmin) {
        GenericTreeNode node = new GenericTreeNode(translate("menu.rights"), CMD_RIGHTS);
        node.setAltText(translate("menu.rights.alt"));
        node.setCssClass("o_sel_membersmgt_rights");
        root.addChild(node);
    }
    return gtm;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 3 with GenericTreeModel

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

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;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 4 with GenericTreeModel

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

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);
}
Also used : GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

Example 5 with GenericTreeModel

use of org.olat.core.gui.components.tree.GenericTreeModel 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;
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) Roles(org.olat.core.id.Roles)

Aggregations

GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)62 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)42 TreeNode (org.olat.core.gui.components.tree.TreeNode)20 CourseNode (org.olat.course.nodes.CourseNode)12 Extension (org.olat.core.extensions.Extension)10 GenericActionExtension (org.olat.core.extensions.action.GenericActionExtension)10 AssertException (org.olat.core.logging.AssertException)10 ArrayList (java.util.ArrayList)8 ActionExtension (org.olat.core.extensions.action.ActionExtension)8 Controller (org.olat.core.gui.control.Controller)8 WindowControl (org.olat.core.gui.control.WindowControl)8 Identity (org.olat.core.id.Identity)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 STCourseNode (org.olat.course.nodes.STCourseNode)8 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)8 List (java.util.List)6 ExtManager (org.olat.core.extensions.ExtManager)6 TreeModel (org.olat.core.gui.components.tree.TreeModel)6 ControllerEventListener (org.olat.core.gui.control.ControllerEventListener)6 TitledWrapperController (org.olat.core.gui.control.generic.title.TitledWrapperController)6