Search in sources :

Example 16 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation 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 17 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation 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 18 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project OpenOLAT by OpenOLAT.

the class MergedCourseContainer method addFolders.

private void addFolders(PersistingCourseImpl course, MergeSource nodesContainer, TreeNode courseNode) {
    if (courseNode == null)
        return;
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        TreeNode child = (TreeNode) courseNode.getChildAt(i);
        NodeEvaluation nodeEval;
        if (child.getUserObject() instanceof NodeEvaluation) {
            nodeEval = (NodeEvaluation) child.getUserObject();
        } else {
            continue;
        }
        if (nodeEval != null && nodeEval.getCourseNode() != null) {
            CourseNode courseNodeChild = nodeEval.getCourseNode();
            String folderName = RequestUtil.normalizeFilename(courseNodeChild.getShortTitle());
            if (courseNodeChild instanceof BCCourseNode) {
                final BCCourseNode bcNode = (BCCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                VFSContainer rootFolder = getBCContainer(course, bcNode, nodeEval, false);
                boolean canDownload = nodeEval.isCapabilityAccessible("download");
                if (canDownload && rootFolder != null) {
                    if (courseReadOnly) {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    } else if (nodeEval.isCapabilityAccessible("upload")) {
                    // inherit the security callback from the course as for author
                    } else {
                        rootFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    folderName = getFolderName(nodesContainer, bcNode, folderName);
                    // Create a container for this node content and wrap it with a merge source which is attached to tree
                    VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                    MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                    courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                    nodesContainer.addContainer(courseNodeContainer);
                    // Do recursion for all children
                    addFolders(course, courseNodeContainer, child);
                } else {
                    // For non-folder course nodes, add merge source (no files to show) ...
                    MergeSource courseNodeContainer = new MergeSource(null, folderName);
                    // , then do recursion for all children ...
                    addFolders(course, courseNodeContainer, child);
                    // ... but only add this container if it contains any children with at least one BC course node
                    if (courseNodeContainer.getItems().size() > 0) {
                        nodesContainer.addContainer(courseNodeContainer);
                    }
                }
            } else if (courseNodeChild instanceof PFCourseNode) {
                final PFCourseNode pfNode = (PFCourseNode) courseNodeChild;
                // add folder not to merge source. Use name and node id to have unique name
                PFManager pfManager = CoreSpringFactory.getImpl(PFManager.class);
                folderName = getFolderName(nodesContainer, pfNode, folderName);
                MergeSource courseNodeContainer = new MergeSource(nodesContainer, folderName);
                UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
                VFSContainer rootFolder = pfManager.provideCoachOrParticipantContainer(pfNode, userCourseEnv, identityEnv.getIdentity(), courseReadOnly);
                VFSContainer nodeContentContainer = new NamedContainerImpl(folderName, rootFolder);
                courseNodeContainer.addContainersChildren(nodeContentContainer, true);
                addFolders(course, courseNodeContainer, child);
                nodesContainer.addContainer(courseNodeContainer);
            } else {
                // For non-folder course nodes, add merge source (no files to show) ...
                MergeSource courseNodeContainer = new MergeSource(null, folderName);
                // , then do recursion for all children ...
                addFolders(course, courseNodeContainer, child);
                // ... but only add this container if it contains any children with at least one BC course node
                if (courseNodeContainer.getItems().size() > 0) {
                    nodesContainer.addContainer(courseNodeContainer);
                }
            }
        }
    }
}
Also used : PFCourseNode(org.olat.course.nodes.PFCourseNode) PFManager(org.olat.course.nodes.pf.manager.PFManager) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) BCCourseNode(org.olat.course.nodes.BCCourseNode) MergeSource(org.olat.core.util.vfs.MergeSource) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) TreeNode(org.olat.core.gui.components.tree.TreeNode) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseNode(org.olat.course.nodes.CourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl)

Example 19 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project OpenOLAT by OpenOLAT.

the class GenericCourseNode method eval.

@Override
public NodeEvaluation eval(ConditionInterpreter ci, TreeEvaluation treeEval, TreeFilter filter) {
    // each CourseNodeImplementation has the full control over all children eval.
    // default behaviour is to eval all visible children
    NodeEvaluation nodeEval = new NodeEvaluation(this);
    calcAccessAndVisibility(ci, nodeEval);
    if (filter != null && !filter.isVisible(this)) {
        nodeEval.setVisible(false);
    }
    nodeEval.build();
    treeEval.cacheCourseToTreeNode(this, nodeEval.getTreeNode());
    // atleastOneAccessible myself
    if (nodeEval.isVisible() && nodeEval.isAtLeastOneAccessible()) {
        int childcnt = getChildCount();
        for (int i = 0; i < childcnt; i++) {
            CourseNode cn = (CourseNode) getChildAt(i);
            NodeEvaluation chdEval = cn.eval(ci, treeEval, filter);
            if (chdEval.isVisible()) {
                // child is visible
                nodeEval.addNodeEvaluationChild(chdEval);
            }
        }
    }
    return nodeEval;
}
Also used : NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 20 with NodeEvaluation

use of org.olat.course.run.userview.NodeEvaluation in project openolat by klemens.

the class CourseTemplateSearchController method loadCourseModel.

private void loadCourseModel(CourseNode courseNode, UserCourseEnvironment uce, List<CourseTemplateRow> rows, Set<CurrentBinder> currentSet) {
    if (courseNode instanceof PortfolioCourseNode) {
        PortfolioCourseNode pNode = (PortfolioCourseNode) courseNode;
        NodeEvaluation ne = pNode.eval(uce.getConditionInterpreter(), new TreeEvaluation(), new VisibleTreeFilter());
        if (NavigationHandler.mayAccessWholeTreeUp(ne)) {
            RepositoryEntry refEntry = pNode.getReferencedRepositoryEntry();
            if ("BinderTemplate".equals(refEntry.getOlatResource().getResourceableTypeName())) {
                RepositoryEntry courseEntry = uce.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
                CurrentBinder binderKey = new CurrentBinder(courseEntry.getKey(), pNode.getIdent());
                if (!currentSet.contains(binderKey)) {
                    rows.add(new CourseTemplateRow(courseEntry, pNode, refEntry));
                }
            }
        }
    }
    for (int i = courseNode.getChildCount(); i-- > 0; ) {
        loadCourseModel((CourseNode) courseNode.getChildAt(i), uce, rows, currentSet);
    }
}
Also used : CourseTemplateRow(org.olat.modules.portfolio.ui.model.CourseTemplateRow) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryEntry(org.olat.repository.RepositoryEntry) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Aggregations

NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)24 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)16 CourseNode (org.olat.course.nodes.CourseNode)14 TreeNode (org.olat.core.gui.components.tree.TreeNode)12 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 RepositoryEntry (org.olat.repository.RepositoryEntry)10 GenericTreeModel (org.olat.core.gui.components.tree.GenericTreeModel)8 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)6 Controller (org.olat.core.gui.control.Controller)6 ControllerEventListener (org.olat.core.gui.control.ControllerEventListener)6 WindowControl (org.olat.core.gui.control.WindowControl)6 ContextEntry (org.olat.core.id.context.ContextEntry)6 AssertException (org.olat.core.logging.AssertException)6 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)6 STCourseNode (org.olat.course.nodes.STCourseNode)6 TitledWrapperController (org.olat.core.gui.control.generic.title.TitledWrapperController)4 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)4 OLATResourceable (org.olat.core.id.OLATResourceable)4