Search in sources :

Example 36 with GenericTreeModel

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

the class NavigationHandler method evaluateJumpToTreeNode.

/**
 * to be called when the users clickes on a node when in the course
 *
 * @param ureq
 * @param wControl
 * @param treeModel
 * @param treeEvent
 * @param listeningController
 * @param nodecmd null or a subcmd which activates a node-specific view (e.g. opens a certain uri in a contentpackaging- buildingblock)
 * @return the NodeClickedRef
 * @return currentNodeController the current node controller that will be dispose before creating the new one
 */
public NodeClickedRef evaluateJumpToTreeNode(UserRequest ureq, WindowControl wControl, TreeModel treeModel, TreeEvent treeEvent, ControllerEventListener listeningController, String nodecmd, Controller currentNodeController) {
    NodeClickedRef ncr;
    String treeNodeId = treeEvent.getNodeId();
    TreeNode selTN = treeModel.getNodeById(treeNodeId);
    if (selTN == null) {
        selTN = treeModel.getRootNode();
    }
    if (!selTN.isAccessible()) {
        // event to match the new node
        if (selTN.getDelegate() != null) {
            selTN = selTN.getDelegate();
            treeNodeId = selTN.getIdent();
            treeEvent = new TreeEvent(MenuTree.COMMAND_TREENODE_CLICKED, treeNodeId);
        }
    }
    // check if appropriate for subtreemodelhandler
    Object userObject = selTN.getUserObject();
    if (!(userObject instanceof NodeEvaluation)) {
        // yes, appropriate
        NodeRunConstructionResult nrcr = null;
        CourseNode internCourseNode = null;
        GenericTreeModel subTreeModel;
        ControllerEventListener subtreemodelListener = null;
        if (selTN != null) {
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            CourseNode courseNode = prevEval.getCourseNode();
            if (externalTreeModels.containsKey(courseNode.getIdent())) {
                SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                subtreemodelListener = subTree.getTreeModelListener();
            }
        }
        if (subtreemodelListener == null) {
            // throw new AssertException("no handler for subtreemodelcall!");
            // reattach the subtreemodellistener
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            internCourseNode = prevEval.getCourseNode();
            final OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.parseLong(internCourseNode.getIdent()));
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
            nrcr = internCourseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, prevEval, nodecmd);
            // remember as instance variable for next click
            subtreemodelListener = nrcr.getSubTreeListener();
            subTreeModel = (GenericTreeModel) nrcr.getSubTreeModel();
            externalTreeModels.put(internCourseNode.getIdent(), new SubTree(nrcr.getRunController(), subTreeModel, subtreemodelListener));
        } else {
            TreeNode internNode = getFirstInternParentNode(selTN);
            NodeEvaluation prevEval = (NodeEvaluation) internNode.getUserObject();
            internCourseNode = prevEval.getCourseNode();
            SubTree subTree = externalTreeModels.get(internCourseNode.getIdent());
            subtreemodelListener = subTree.getTreeModelListener();
            if (currentNodeController instanceof TitledWrapperController) {
                currentNodeController = ((TitledWrapperController) currentNodeController).getContentController();
            }
            if (subtreemodelListener != currentNodeController) {
                if (subtreemodelListener instanceof CPRunController) {
                    nrcr = ((CPRunController) subtreemodelListener).createNodeRunConstructionResult(ureq, selTN.getIdent());
                } else {
                    nrcr = new NodeRunConstructionResult((Controller) subtreemodelListener);
                }
            }
            subTreeModel = subTree.getTreeModel();
        }
        if (log.isDebug()) {
            log.debug("delegating to handler: treeNodeId = " + treeNodeId);
        }
        // used in multiple nodes.
        if (!selTN.getUserObject().equals(userObject)) {
            selTN = subTreeModel.findNodeByUserObject(userObject);
        }
        treeEvent = new TreeEvent(treeEvent.getCommand(), treeEvent.getSubCommand(), selTN.getIdent());
        boolean dispatch = true;
        String selectedNodeId = null;
        if (userObject instanceof String) {
            String sObject = (String) userObject;
            if (MenuTree.COMMAND_TREENODE_CLICKED.equals(treeEvent.getCommand()) && treeEvent.getSubCommand() == null) {
                openCourseNodeIds.add(sObject);
                if (!openTreeNodeIds.contains(sObject)) {
                    openTreeNodeIds.add(sObject);
                }
                selectedNodeId = selTN.getIdent();
            } else if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand())) {
                openCourseNodeIds.add(sObject);
                if (!openTreeNodeIds.contains(sObject)) {
                    openTreeNodeIds.add(sObject);
                }
                selectedNodeId = selTN.getIdent();
                dispatch = false;
            } else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
                removeChildrenFromOpenNodes(selTN);
                openCourseNodeIds.remove(sObject);
                openTreeNodeIds.remove(sObject);
                openCourseNodeIds.remove(selTN.getIdent());
                openTreeNodeIds.remove(selTN.getIdent());
                dispatch = false;
            }
        }
        if (dispatch) {
            // null as controller source since we are not a controller
            subtreemodelListener.dispatchEvent(ureq, null, treeEvent);
        // no node construction result indicates handled
        }
        ncr = new NodeClickedRef(treeModel, true, selectedNodeId, openTreeNodeIds, internCourseNode, nrcr, true);
    } else {
        // normal dispatching to a coursenode.
        // get the courseNode that was called
        NodeEvaluation prevEval = (NodeEvaluation) selTN.getUserObject();
        if (!prevEval.isVisible())
            throw new AssertException("clicked on a node which is not visible: treenode=" + selTN.getIdent() + ", " + selTN.getTitle());
        CourseNode calledCourseNode = prevEval.getCourseNode();
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrap(calledCourseNode));
        // might be used in both controllers with the same ID (e.g. the course folder)
        if (TreeEvent.COMMAND_TREENODE_OPEN.equals(treeEvent.getSubCommand()) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(treeEvent.getSubCommand())) {
            if (isInParentLine(calledCourseNode)) {
                if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
                    currentNodeController.dispose();
                }
            }
            ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
        } else {
            if (currentNodeController != null && !currentNodeController.isDisposed() && !isListening(currentNodeController)) {
                currentNodeController.dispose();
            }
            ncr = doEvaluateJumpTo(ureq, wControl, calledCourseNode, listeningController, nodecmd, treeEvent.getSubCommand(), currentNodeController);
        }
    }
    return ncr;
}
Also used : CPRunController(org.olat.course.nodes.cp.CPRunController) AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) WindowControl(org.olat.core.gui.control.WindowControl) 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) ContextEntry(org.olat.core.id.context.ContextEntry) TreeEvent(org.olat.core.gui.components.tree.TreeEvent) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) 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) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 37 with GenericTreeModel

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

the class NavigationHandler method reloadTreeAfterChanges.

public NodeClickedRef reloadTreeAfterChanges(CourseNode courseNode) {
    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);
    TreeNode treeNode = treeEval.getCorrespondingTreeNode(courseNode.getIdent());
    NodeClickedRef nclr;
    if (treeNode == null) {
        nclr = null;
    } else {
        Object uObject = treeNode.getUserObject();
        if (uObject instanceof NodeEvaluation) {
            NodeEvaluation nodeEval = (NodeEvaluation) uObject;
            ControllerEventListener subtreemodelListener = null;
            if (externalTreeModels.containsKey(courseNode.getIdent())) {
                SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                subtreemodelListener = subTree.getTreeModelListener();
                reattachExternalTreeModels(treeEval);
            }
            openTreeNodeIds = convertToTreeNodeIds(treeEval, openCourseNodeIds);
            selectedCourseNodeId = nodeEval.getCourseNode().getIdent();
            if (subtreemodelListener == null) {
                nclr = new NodeClickedRef(treeModel, true, selectedCourseNodeId, openTreeNodeIds, nodeEval.getCourseNode(), null, false);
            } else {
                nclr = new NodeClickedRef(treeModel, true, selectedCourseNodeId, openTreeNodeIds, nodeEval.getCourseNode(), null, true);
            }
        } else {
            nclr = null;
        }
    }
    return nclr;
}
Also used : ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) 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) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 38 with GenericTreeModel

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

the class RunMainController method updateTreeAndContent.

private CourseNode updateTreeAndContent(UserRequest ureq, CourseNode calledCourseNode, String nodecmd, List<ContextEntry> entries, StateEntry state) {
    // might be used in both controllers with the same ID (e.g. the course folder)
    if (currentNodeController != null && !currentNodeController.isDisposed() && !navHandler.isListening(currentNodeController)) {
        currentNodeController.dispose();
    }
    NodeClickedRef nclr = navHandler.evaluateJumpToCourseNode(ureq, getWindowControl(), calledCourseNode, this, nodecmd);
    if (!nclr.isVisible()) {
        // if not root -> fallback to root. e.g. when a direct node jump fails
        if (calledCourseNode != null) {
            nclr = navHandler.evaluateJumpToCourseNode(ureq, getWindowControl(), null, this, null);
        }
        if (!nclr.isVisible()) {
            MessageController msgController = MessageUIFactory.createInfoMessage(ureq, getWindowControl(), translate("course.noaccess.title"), translate("course.noaccess.text"));
            contentP.setContent(msgController.getInitialComponent());
            luTree.setTreeModel(new GenericTreeModel());
            return null;
        }
    }
    treeModel = nclr.getTreeModel();
    luTree.setTreeModel(treeModel);
    String selNodeId = nclr.getSelectedNodeId();
    luTree.setSelectedNodeId(selNodeId);
    luTree.setOpenNodeIds(nclr.getOpenNodeIds());
    // get new run controller.
    currentNodeController = nclr.getRunController();
    addToHistory(ureq, currentNodeController);
    if (currentNodeController instanceof TitledWrapperController) {
        Controller contentcontroller = ((TitledWrapperController) currentNodeController).getContentController();
        addToHistory(ureq, contentcontroller);
        if (contentcontroller instanceof Activateable2) {
            ((Activateable2) contentcontroller).activate(ureq, entries, state);
        }
    } else if (currentNodeController instanceof Activateable2) {
        ((Activateable2) currentNodeController).activate(ureq, entries, state);
    }
    if (currentNodeController != null) {
        contentP.setContent(currentNodeController.getInitialComponent());
    } else {
        MessageController msgCtrl = MessageUIFactory.createWarnMessage(ureq, getWindowControl(), null, translate("msg.nodenotavailableanymore"));
        listenTo(msgCtrl);
        contentP.setContent(msgCtrl.getInitialComponent());
    }
    updateNextPrevious();
    updateCourseDataAttributes(nclr.getCalledCourseNode());
    updateLastUsage(nclr.getCalledCourseNode());
    return nclr.getCalledCourseNode();
}
Also used : MessageController(org.olat.core.gui.control.generic.messages.MessageController) Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) NodeClickedRef(org.olat.course.run.navigation.NodeClickedRef) DisposedCourseRestartController(org.olat.course.DisposedCourseRestartController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) MessageController(org.olat.core.gui.control.generic.messages.MessageController) CourseGlossaryToolLinkController(org.olat.course.run.glossary.CourseGlossaryToolLinkController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) Controller(org.olat.core.gui.control.Controller) GlossaryMarkupItemController(org.olat.core.gui.control.generic.textmarker.GlossaryMarkupItemController) MainLayoutBasicController(org.olat.core.gui.control.controller.MainLayoutBasicController)

Example 39 with GenericTreeModel

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

the class GenericMainController method createController.

/**
 * creates Controller for clicked Node, default implementation.
 *
 * @param ae
 * @param ureq
 * @return corresponding controller
 */
protected Controller createController(ActionExtension ae, UserRequest ureq) {
    // default implementation for simple case where action extension.
    WindowControl bwControl = getWindowControl();
    if (olatMenuTree.getTreeModel() instanceof GenericTreeModel) {
        if (ae instanceof Extension) {
            Extension nE = (Extension) ae;
            // get our ores for the extension
            OLATResourceable ores;
            if (ae instanceof GenericActionExtension && StringHelper.containsNonWhitespace(((GenericActionExtension) ae).getNavigationKey())) {
                // there is a navigation-key, use the nice way
                ores = OresHelper.createOLATResourceableInstance(((GenericActionExtension) ae).getNavigationKey(), 0L);
            } else {
                ores = OresHelper.createOLATResourceableInstance(GMCMT, CodeHelper.getUniqueIDFromString(nE.getUniqueExtensionID()));
            }
            ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapBusinessPath(ores));
            bwControl = addToHistory(ureq, ores, null);
        }
    }
    Controller ctrl = ae.createController(ureq, bwControl, null);
    if (ctrl instanceof BreadcrumbPanelAware) {
        ((BreadcrumbPanelAware) ctrl).setBreadcrumbPanel(stackVC);
    }
    return ctrl;
}
Also used : Extension(org.olat.core.extensions.Extension) ActionExtension(org.olat.core.extensions.action.ActionExtension) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) BreadcrumbPanelAware(org.olat.core.gui.components.stack.BreadcrumbPanelAware) OLATResourceable(org.olat.core.id.OLATResourceable) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) WindowControl(org.olat.core.gui.control.WindowControl) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) Controller(org.olat.core.gui.control.Controller) MainLayoutBasicController(org.olat.core.gui.control.controller.MainLayoutBasicController)

Example 40 with GenericTreeModel

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

the class GenericMainController method buildTreeModel.

private TreeModel buildTreeModel(UserRequest ureq) {
    GenericTreeNode rootTreeNode = new GenericTreeNode();
    rootTreeNode.setTitle(getTranslator().translate("main.menu.title"));
    rootTreeNode.setAltText(getTranslator().translate("main.menu.title.alt"));
    GenericTreeModel gtm = new GenericTreeModel();
    gtm.setRootNode(rootTreeNode);
    // Prepend
    boolean rootNodeSet = false;
    if (nodesToPrepend.size() != 0) {
        for (GenericTreeNode node : nodesToPrepend) {
            rootTreeNode.addChild(node);
            if (!rootNodeSet) {
                rootTreeNode.setDelegate(node);
                rootTreeNode.setUserObject(node.getUserObject());
                rootNodeSet = true;
            }
        }
    }
    // add extension menues
    ExtManager extm = ExtManager.getInstance();
    int j = 0;
    GenericTreeNode gtnChild;
    Map<GenericTreeNode, String> subMenuNodes = new LinkedHashMap<GenericTreeNode, String>();
    for (Extension anExt : extm.getExtensions()) {
        // check for sites
        ActionExtension ae = (ActionExtension) anExt.getExtensionFor(className, ureq);
        if (ae != null && ae instanceof GenericActionExtension) {
            if (anExt.isEnabled()) {
                GenericActionExtension gAe = (GenericActionExtension) ae;
                gtnChild = gAe.createMenuNode(ureq);
                if (StringHelper.containsNonWhitespace(gAe.getNavigationKey())) {
                    gtnChild.setCssClass("o_sel_" + gAe.getNavigationKey());
                }
                if (gAe.getNodeIdentifierIfParent() != null) {
                    // it's a parent-node, set identifier
                    gtnChild.setIdent(gAe.getNodeIdentifierIfParent());
                }
                if (j == 0 && !rootNodeSet) {
                    // first node, set as delegate of rootTreenode
                    rootTreeNode.setDelegate(gtnChild);
                    rootTreeNode.setUserObject(gAe);
                    rootTreeNode.addChild(gtnChild);
                } else // navigation (submenues)
                if (gAe.getParentTreeNodeIdentifier() != null) {
                    // this is a sub-menu-node, do not add to tree-model already, since
                    // parent tree may not yet be in model
                    // (parent could be "after" child, in ActionExtensions-Collection)
                    String parentNodeID = gAe.getParentTreeNodeIdentifier();
                    subMenuNodes.put(gtnChild, parentNodeID);
                } else // "normal" menu-entry
                {
                    rootTreeNode.addChild(gtnChild);
                }
                j++;
            } else {
                logInfo("found disabled GenericActionExtension for " + className + " ", ae.toString());
            }
        }
    }
    // loop over submenuNodes and add to their parents
    for (Entry<GenericTreeNode, String> childNodeEntry : subMenuNodes.entrySet()) {
        GenericTreeNode childNode = childNodeEntry.getKey();
        GenericTreeNode parentNode = (GenericTreeNode) gtm.getNodeById(childNodeEntry.getValue());
        if (parentNode != null) {
            parentNode.addChild(childNode);
            if (parentNode.getDelegate() == null) {
                boolean addDelegate = true;
                // add delegate only if hte parent hasn't not a controller defined
                Object uo = parentNode.getUserObject();
                if (uo instanceof GenericActionExtension) {
                    GenericActionExtension gae = (GenericActionExtension) uo;
                    if (StringHelper.containsNonWhitespace(gae.getClassNameOfCorrespondingController())) {
                        addDelegate = false;
                    }
                }
                if (addDelegate) {
                    parentNode.setDelegate(childNode);
                    parentNode.setUserObject(childNode.getUserObject());
                }
            }
        } else {
            logWarn("Could not add navigation-menu (" + childNode.getTitle() + ") to parent:: " + childNodeEntry.getValue(), null);
            // make it at least appear on top level
            rootTreeNode.addChild(childNode);
        }
    }
    // Append
    if (nodesToAppend.size() != 0) {
        for (GenericTreeNode node : nodesToAppend) {
            rootTreeNode.addChild(node);
        }
    }
    return gtm;
}
Also used : ExtManager(org.olat.core.extensions.ExtManager) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) LinkedHashMap(java.util.LinkedHashMap) Extension(org.olat.core.extensions.Extension) ActionExtension(org.olat.core.extensions.action.ActionExtension) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) ActionExtension(org.olat.core.extensions.action.ActionExtension) GenericActionExtension(org.olat.core.extensions.action.GenericActionExtension) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel)

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