Search in sources :

Example 81 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class EditorMainController method doCreateAlternateBuildingBlock.

/**
 * The following operation are done:
 * <ul>
 * 	<li>create a new instance of the replacement type
 * 	<li>add the new element below the original element
 * 	<li>copy the element title, description and the generic configuration options
 * 	<li>copy the access, visibility and scoring rules (easy and expert)
 * 	<li>optionally copy some other configuration if this is possible at all
 * 	<li>move all child elements from the original to the replacement element
 * 	<li>mark the original element as deleted
 * </ul>
 *
 * @param chosenNode
 * @param selectAlternative
 */
private void doCreateAlternateBuildingBlock(UserRequest ureq, ICourse course, CourseNode chosenNode, String selectAlternative) {
    if (!StringHelper.containsNonWhitespace(selectAlternative))
        return;
    // create the alternative node
    CourseNodeConfiguration newConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(selectAlternative);
    CourseNode newNode = newConfig.getInstance();
    // copy configurations
    chosenNode.copyConfigurationTo(newNode, course);
    // insert the node
    CourseEditorTreeNode cetn = (CourseEditorTreeNode) cetm.getNodeById(chosenNode.getIdent());
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) cetn.getParent();
    int position = cetn.getPosition() + 1;
    CourseEditorTreeNode newCetn = course.getEditorTreeModel().insertCourseNodeAt(newNode, parentNode.getCourseNode(), position);
    doInsert(ureq, newNode);
    // copy the children
    while (cetn.getChildCount() > 0) {
        CourseEditorTreeNode childNode = (CourseEditorTreeNode) cetn.getChildAt(0);
        newCetn.addChild(childNode);
    }
    // set all dirty
    TreeVisitor tv = new TreeVisitor(new Visitor() {

        public void visit(INode node) {
            ((CourseEditorTreeNode) node).setDirty(true);
        }
    }, newCetn, true);
    tv.visitAll();
    // mark as deleted
    doDelete(course, chosenNode.getIdent());
    // save
    CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
}
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) CourseNodeConfiguration(org.olat.course.nodes.CourseNodeConfiguration) CourseNode(org.olat.course.nodes.CourseNode)

Example 82 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class EditorMainController method doOpenNodeTypeChooser.

private void doOpenNodeTypeChooser(UserRequest ureq) {
    removeAsListenerAndDispose(cmc);
    removeAsListenerAndDispose(chooseNodeTypeCtr);
    menuTree.getSelectedNode();
    TreeNode tn = menuTree.getSelectedNode();
    CourseEditorTreeNode cetn = tn == null ? null : cetm.getCourseEditorNodeById(tn.getIdent());
    chooseNodeTypeCtr = new ChooseNodeController(ureq, getWindowControl(), ores, cetn);
    listenTo(chooseNodeTypeCtr);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), chooseNodeTypeCtr.getInitialComponent(), true, translate("header.insertnodes"));
    listenTo(cmc);
    cmc.activate();
}
Also used : TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode)

Example 83 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

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 84 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class MoveCopySubtreeController method getCourseNode.

private CourseNode getCourseNode(TreeNode tn) {
    CourseEditorTreeNode ctn = (CourseEditorTreeNode) tn;
    CourseNode cn = ctn.getCourseNode();
    return cn;
}
Also used : CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 85 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class MultiSPController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (nodeSelections.contains(source)) {
        MultipleSelectionElement nodeSelection = (MultipleSelectionElement) source;
        if (nodeSelection.isMultiselect()) {
            selectRec(nodeSelection, nodeSelection.isSelected(0));
        }
    } else if (source == selectAll) {
        for (MultipleSelectionElement nodeSelection : nodeSelections) {
            if (nodeSelection.isMultiselect() && !nodeSelection.isSelected(0)) {
                SelectNodeObject treeNode = (SelectNodeObject) nodeSelection.getUserObject();
                String id = treeNode.getId();
                nodeSelection.select(id, true);
            }
        }
    } else if (source == deselectAll) {
        for (MultipleSelectionElement nodeSelection : nodeSelections) {
            if (nodeSelection.isMultiselect() && nodeSelection.isSelected(0)) {
                SelectNodeObject treeNode = (SelectNodeObject) nodeSelection.getUserObject();
                String id = treeNode.getId();
                nodeSelection.select(id, false);
            }
        }
    } else if (source == asChild) {
        position = -1;
        ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
        create(rootSelection, course, selectedNode.getCourseNode());
        fireEvent(ureq, Event.CHANGED_EVENT);
    } else if (source == sameLevel) {
        ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
        CourseEditorTreeNode parentNode = (CourseEditorTreeNode) selectedNode.getParent();
        position = 0;
        for (position = parentNode.getChildCount(); position-- > 0; ) {
            if (selectedNode.getIdent().equals(parentNode.getChildAt(position).getIdent())) {
                position++;
                break;
            }
        }
        create(rootSelection, course, parentNode.getCourseNode());
        fireEvent(ureq, Event.CHANGED_EVENT);
    } else {
        super.formInnerEvent(ureq, source, event);
    }
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ICourse(org.olat.course.ICourse)

Aggregations

CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)88 CourseNode (org.olat.course.nodes.CourseNode)54 ICourse (org.olat.course.ICourse)38 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)24 INode (org.olat.core.util.nodes.INode)22 Test (org.junit.Test)20 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Identity (org.olat.core.id.Identity)14 TreeVisitor (org.olat.core.util.tree.TreeVisitor)14 Visitor (org.olat.core.util.tree.Visitor)14 CourseNodeVO (org.olat.restapi.support.vo.CourseNodeVO)12 TreeNode (org.olat.core.gui.components.tree.TreeNode)10 STCourseNode (org.olat.course.nodes.STCourseNode)10 ArrayList (java.util.ArrayList)9 File (java.io.File)8 URI (java.net.URI)8 HttpResponse (org.apache.http.HttpResponse)8 HttpPut (org.apache.http.client.methods.HttpPut)8 Structure (org.olat.course.Structure)8 BCCourseNode (org.olat.course.nodes.BCCourseNode)8