Search in sources :

Example 66 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class MenuTreeRenderer method render.

/**
 * @see org.olat.core.gui.render.ui.ComponentRenderer#render(org.olat.core.gui.render.Renderer,
 *      org.olat.core.gui.render.StringOutput, org.olat.core.gui.components.Component,
 *      org.olat.core.gui.render.URLBuilder, org.olat.core.gui.translator.Translator,
 *      org.olat.core.gui.render.RenderResult, java.lang.String[])
 */
@Override
public void render(Renderer renderer, StringOutput target, Component source, URLBuilder ubu, Translator translator, RenderResult renderResult, String[] args) {
    MenuTree tree = (MenuTree) source;
    if (tree.getMenuTreeItem() != null) {
        tree.getMenuTreeItem().clearVisibleNodes();
    }
    TreeNode root = tree.getTreeModel().getRootNode();
    // tree is completely empty
    if (root == null)
        return;
    INode selNode = tree.getSelectedNode();
    Collection<String> openNodeIds = tree.getOpenNodeIds();
    List<INode> selPath = new ArrayList<>(5);
    INode cur = selNode;
    if (cur == null && !tree.isUnselectNodes()) {
        cur = root;
    } else if (cur == null && tree.isUnselectNodes() && openNodeIds.isEmpty()) {
        // always open the root
        openNodeIds.add(root.getIdent());
    }
    // selected nodeid of the root node
    while (cur != null) {
        selPath.add(0, cur);
        cur = cur.getParent();
    }
    List<DndElement> elements = new ArrayList<>();
    AJAXFlags flags = renderer.getGlobalSettings().getAjaxFlags();
    target.append("\n<div class='o_tree");
    // marker classes to differentiate rendering when root node is visible
    if (!tree.isRootVisible()) {
        target.append(" o_tree_root_hidden");
    } else {
        target.append(" o_tree_root_visible");
    }
    if (tree.isInsertToolEnabled()) {
        target.append(" o_tree_insert_tool");
    }
    // add element CSS
    if (StringHelper.containsNonWhitespace(tree.getElementCssClass())) {
        target.append(" ").append(tree.getElementCssClass());
    }
    target.append("'><ul class=\"o_tree_l0\">");
    if (tree.isRootVisible()) {
        renderLevel(renderer, target, 0, root, selPath, openNodeIds, elements, ubu, flags, tree);
    } else {
        selPath.remove(0);
        int chdCnt = root.getChildCount();
        for (int i = 0; i < chdCnt; i++) {
            TreeNode curChd = (TreeNode) root.getChildAt(i);
            renderLevel(renderer, target, 0, curChd, selPath, openNodeIds, elements, ubu, flags, tree);
        }
    }
    target.append("</ul>");
    appendDragAndDropScript(elements, tree, target).append("</div>");
}
Also used : INode(org.olat.core.util.nodes.INode) AJAXFlags(org.olat.core.gui.control.winmgr.AJAXFlags) ArrayList(java.util.ArrayList)

Example 67 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class EditorMainController method dropNodeAsChild.

private void dropNodeAsChild(UserRequest ureq, ICourse course, String droppedNodeId, String targetNodeId, boolean asChild, boolean atTheEnd) {
    // setDirty when moving
    menuTree.setDirty(true);
    CourseNode droppedNode = cetm.getCourseNode(droppedNodeId);
    int position;
    CourseEditorTreeNode insertParent;
    if (asChild) {
        insertParent = cetm.getCourseEditorNodeById(targetNodeId);
        position = atTheEnd ? -1 : 0;
    } else {
        CourseEditorTreeNode selectedNode = cetm.getCourseEditorNodeById(targetNodeId);
        if (selectedNode.getParent() == null) {
            // root node
            insertParent = selectedNode;
            position = 0;
        } else {
            insertParent = course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getParent().getIdent());
            position = 0;
            for (position = insertParent.getChildCount(); position-- > 0; ) {
                if (insertParent.getChildAt(position).getIdent().equals(selectedNode.getIdent())) {
                    position++;
                    break;
                }
            }
        }
    }
    CourseEditorTreeNode moveFrom = course.getEditorTreeModel().getCourseEditorNodeById(droppedNode.getIdent());
    // check if an ancestor is not dropped on a child
    if (course.getEditorTreeModel().checkIfIsChild(insertParent, moveFrom)) {
        showError("movecopynode.error.overlap");
        fireEvent(ureq, Event.CANCELLED_EVENT);
        return;
    }
    // don't generate red screen for that. If the position is too high -> add the node at the end
    if (position >= insertParent.getChildCount()) {
        position = -1;
    }
    try {
        if (position >= 0) {
            insertParent.insert(moveFrom, position);
        } else {
            insertParent.addChild(moveFrom);
        }
    } catch (IndexOutOfBoundsException e) {
        logError("", e);
        // reattach the node as security, if not, the node is lost
        insertParent.addChild(moveFrom);
    }
    moveFrom.setDirty(true);
    // mark subtree as dirty
    TreeVisitor tv = new TreeVisitor(new Visitor() {

        public void visit(INode node) {
            CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
            cetn.setDirty(true);
        }
    }, moveFrom, true);
    tv.visitAll();
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
    showInfo("movecopynode.info.condmoved");
    ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_MOVED, getClass());
    euce.getCourseEditorEnv().validateCourse();
    StatusDescription[] courseStatus = euce.getCourseEditorEnv().getCourseStatus();
    updateCourseStatusMessages(ureq.getLocale(), courseStatus);
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 68 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class MoveCopySubtreeController method doInsert.

private void doInsert(UserRequest ureq, TreePosition tp) {
    ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
    int insertPos = tp.getChildpos();
    CourseNode selectedNode = getCourseNode(tp.getParentTreeNode());
    CourseEditorTreeNode insertParent = course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getIdent());
    // check if insert position is within the to-be-copied tree
    if (course.getEditorTreeModel().checkIfIsChild(insertParent, moveCopyFrom)) {
        showError("movecopynode.error.overlap");
        fireEvent(ureq, Event.CANCELLED_EVENT);
    } else if (copy) {
        // do a copy
        // copy subtree and save model
        recursiveCopy(moveCopyFrom, insertParent, insertPos, true, CourseFactory.getCourseEditSession(ores.getResourceableId()));
        CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_COPIED, getClass());
        fireEvent(ureq, Event.DONE_EVENT);
    } else {
        // move only
        if (insertParent.getIdent().equals(moveCopyFrom.getParent().getIdent())) {
            // same parent, adjust insertPos
            if (insertPos > moveCopyFrom.getPosition())
                insertPos--;
        }
        insertParent.insert(moveCopyFrom, insertPos);
        moveCopyFrom.setDirty(true);
        // mark subtree as dirty
        TreeVisitor tv = new TreeVisitor(new Visitor() {

            @Override
            public void visit(INode node) {
                CourseEditorTreeNode cetn = (CourseEditorTreeNode) node;
                cetn.setDirty(true);
            }
        }, moveCopyFrom, true);
        tv.visitAll();
        CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
        showInfo("movecopynode.info.condmoved");
        ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_EDITOR_NODE_MOVED, getClass());
        fireEvent(ureq, Event.DONE_EVENT);
    }
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode)

Example 69 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class CourseEditorEnvImpl method getCourseStatus.

/**
 * @see org.olat.course.editor.CourseEditorEnv#getCourseStatus()
 */
public StatusDescription[] getCourseStatus() {
    String[] a = statusDescs.keySet().toArray(new String[statusDescs.keySet().size()]);
    Arrays.sort(a);
    List<StatusDescription> all2gether = new ArrayList<StatusDescription>();
    for (int i = a.length - 1; i >= 0; i--) {
        all2gether.addAll(statusDescs.get(a[i]));
    }
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    if (course != null) {
        if (course.getCourseConfig().getSharedFolderSoftkey().equals("sf.notconfigured")) {
            INode rootNode = course.getEditorTreeModel().getRootNode();
            List<StatusDescription> descriptions = new ArrayList<StatusDescription>();
            descriptions = checkFolderNodes(rootNode, course, descriptions);
            if (!descriptions.isEmpty()) {
                all2gether.addAll(descriptions);
            }
        }
    }
    StatusDescription[] retVal = new StatusDescription[all2gether.size()];
    retVal = all2gether.toArray(retVal);
    return retVal;
}
Also used : INode(org.olat.core.util.nodes.INode) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse)

Example 70 with INode

use of org.olat.core.util.nodes.INode in project OpenOLAT by OpenOLAT.

the class CourseOptionsController method checkFolderNodes.

private boolean checkFolderNodes(INode rootNode, ICourse course) {
    hasFolderNode = false;
    Visitor visitor = new Visitor() {

        public void visit(INode node) {
            CourseEditorTreeNode courseNode = (CourseEditorTreeNode) course.getEditorTreeModel().getNodeById(node.getIdent());
            if (!courseNode.isDeleted() && courseNode.getCourseNode() instanceof BCCourseNode) {
                BCCourseNode bcNode = (BCCourseNode) courseNode.getCourseNode();
                if (bcNode.isSharedFolder()) {
                    hasFolderNode = true;
                }
            }
        }
    };
    TreeVisitor v = new TreeVisitor(visitor, rootNode, false);
    v.visitAll();
    return hasFolderNode;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) BCCourseNode(org.olat.course.nodes.BCCourseNode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode)

Aggregations

INode (org.olat.core.util.nodes.INode)106 Visitor (org.olat.core.util.tree.Visitor)44 CourseNode (org.olat.course.nodes.CourseNode)44 ICourse (org.olat.course.ICourse)40 TreeVisitor (org.olat.core.util.tree.TreeVisitor)30 ArrayList (java.util.ArrayList)28 Identity (org.olat.core.id.Identity)26 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)24 TreeNode (org.olat.core.gui.components.tree.TreeNode)18 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Test (org.junit.Test)16 BCCourseNode (org.olat.course.nodes.BCCourseNode)14 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)14 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)14 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)12 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)12 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)12 HashMap (java.util.HashMap)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10 GET (javax.ws.rs.GET)8