Search in sources :

Example 51 with INode

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

the class CourseEditorEnvImpl method checkFolderNodes.

private List<StatusDescription> checkFolderNodes(INode rootNode, ICourse course, List<StatusDescription> descriptions) {
    List<StatusDescription> descriptionsI = descriptions;
    Visitor visitor = new Visitor() {

        @Override
        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()) {
                    String translPackage = Util.getPackageName(BCCourseNodeEditController.class);
                    StatusDescription status = new StatusDescription(StatusDescription.ERROR, "warning.no.sharedfolder", "warning.no.sharedfolder", null, translPackage);
                    status.setDescriptionForUnit(bcNode.getIdent());
                    // set which pane is affected by error
                    status.setActivateableViewIdentifier(BCCourseNodeEditController.PANE_TAB_FOLDER);
                    descriptionsI.add(status);
                }
            }
        }
    };
    TreeVisitor v = new TreeVisitor(visitor, rootNode, false);
    v.visitAll();
    return descriptionsI;
}
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)

Example 52 with INode

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

the class NavigationHandler method copyIdent.

private void copyIdent(TreeNode guiNode, TreeNode originalNode) {
    if (guiNode instanceof GenericTreeNode) {
        ((GenericTreeNode) guiNode).setIdent(originalNode.getIdent());
    }
    for (int i = originalNode.getChildCount(); i-- > 0; ) {
        INode originalChild = originalNode.getChildAt(i);
        INode guiChild = guiNode.getChildAt(i);
        copyIdent((TreeNode) guiChild, (TreeNode) originalChild);
    }
}
Also used : INode(org.olat.core.util.nodes.INode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode)

Example 53 with INode

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

the class QTIEditorMainController method createChangeMessage.

/**
 * helper method to create the change log message
 *
 * @return
 */
private String createChangeMessage() {
    // FIXME:pb:break down into smaller pieces
    final StringBuilder result = new StringBuilder();
    if (isRestrictedEdit()) {
        Visitor v = new Visitor() {

            /*
				 * a history key is built as follows
				 * sectionkey+"/"+itemkey+"/"+questionkey+"/"+responsekey
				 */
            String sectionKey = null;

            Map<String, String> itemMap = new HashMap<>();

            public void visit(INode node) {
                if (node instanceof AssessmentNode) {
                    AssessmentNode an = (AssessmentNode) node;
                    String key = "null/null/null/null";
                    if (history.containsKey(key)) {
                        // some assessment top level data changed
                        Memento mem = history.get(key);
                        result.append("---+ Changes in test " + formatVariable(startedWithTitle) + ":");
                        result.append(an.createChangeMessage(mem));
                    }
                } else if (node instanceof SectionNode) {
                    SectionNode sn = (SectionNode) node;
                    String tmpKey = ((Section) sn.getUnderlyingQTIObject()).getIdent();
                    String key = tmpKey + "/null/null/null";
                    if (history.containsKey(key)) {
                        // some section only data changed
                        Memento mem = history.get(key);
                        result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
                        result.append(sn.createChangeMessage(mem));
                    }
                } else if (node instanceof ItemNode) {
                    ItemNode in = (ItemNode) node;
                    SectionNode sn = (SectionNode) in.getParent();
                    String parentSectkey = ((Section) ((SectionNode) in.getParent()).getUnderlyingQTIObject()).getIdent();
                    Item item = (Item) in.getUnderlyingQTIObject();
                    Question question = item.getQuestion();
                    String itemKey = item.getIdent();
                    String prefixKey = "null/" + itemKey;
                    String questionIdent = question != null ? question.getQuestion().getId() : "null";
                    String key = prefixKey + "/" + questionIdent + "/null";
                    StringBuilder changeMessage = new StringBuilder();
                    boolean hasChanges = false;
                    if (!itemMap.containsKey(itemKey)) {
                        Memento questMem = null;
                        Memento respMem = null;
                        if (history.containsKey(key)) {
                            // question changed!
                            questMem = history.get(key);
                            hasChanges = true;
                        }
                        // if(!hasChanges){
                        // check if a response changed
                        // new prefix for responses
                        prefixKey += "/null/";
                        // list contains org.olat.ims.qti.editor.beecom.objects.Response
                        List<Response> responses = question != null ? question.getResponses() : null;
                        if (responses != null && responses.size() > 0) {
                            // check for changes in each response
                            for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
                                Response resp = iter.next();
                                if (history.containsKey(prefixKey + resp.getIdent())) {
                                    // this response changed!
                                    Memento tmpMem = history.get(prefixKey + resp.getIdent());
                                    if (respMem != null) {
                                        respMem = respMem.getTimestamp() > tmpMem.getTimestamp() ? tmpMem : respMem;
                                    } else {
                                        hasChanges = true;
                                        respMem = tmpMem;
                                    }
                                }
                            }
                        }
                        // output message
                        if (hasChanges) {
                            Memento mem = null;
                            if (questMem != null && respMem != null) {
                                // use the earlier memento
                                mem = questMem.getTimestamp() > respMem.getTimestamp() ? respMem : questMem;
                            } else if (questMem != null) {
                                mem = questMem;
                            } else if (respMem != null) {
                                mem = respMem;
                            }
                            changeMessage.append(in.createChangeMessage(mem));
                            itemMap.put(itemKey, itemKey);
                            if (!parentSectkey.equals(sectionKey)) {
                                // either this item belongs to a new section or no section
                                // is active
                                result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
                                result.append("\n").append(changeMessage);
                                sectionKey = parentSectkey;
                            } else {
                                result.append("\n").append(changeMessage);
                            }
                        }
                    }
                }
            }

            private String formatVariable(String var) {
                if (StringHelper.containsNonWhitespace(var)) {
                    return var;
                }
                return "[no entry]";
            }
        };
        TreeVisitor tv = new TreeVisitor(v, menuTreeModel.getRootNode(), false);
        tv.visitAll();
    }
    /*
		 * 
		 */
    return result.toString();
}
Also used : INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) SectionNode(org.olat.ims.qti.editor.tree.SectionNode) Section(org.olat.ims.qti.editor.beecom.objects.Section) Response(org.olat.ims.qti.editor.beecom.objects.Response) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Memento(org.olat.core.util.memento.Memento) Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) Map(java.util.Map) HashMap(java.util.HashMap)

Example 54 with INode

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

the class QuestionPoolMenuTreeModel method setFirstChildAsDelegate.

private void setFirstChildAsDelegate(INode node) {
    if (node.getChildCount() > 0) {
        INode childNode = node.getChildAt(0);
        if (node instanceof GenericTreeNode && childNode instanceof TreeNode) {
            GenericTreeNode parent = (GenericTreeNode) node;
            TreeNode child = (TreeNode) childNode;
            parent.setDelegate(child);
        }
    }
}
Also used : INode(org.olat.core.util.nodes.INode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode)

Example 55 with INode

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

the class MoveTaxonomyLevelController method isParent.

private boolean isParent(TaxonomyLevel levelToMove) {
    TreeNode nodeToMove = taxonomyModel.getNodeById(TaxonomyAllTreesBuilder.nodeKey(levelToMove));
    TreeNode selectedNode = taxonomyEl.getSelectedNode();
    if (selectedNode == taxonomyModel.getRootNode()) {
        // can move to root
        return false;
    }
    for (INode node = nodeToMove; node != null; node = node.getParent()) {
        if (selectedNode == node) {
            return true;
        }
    }
    return false;
}
Also used : INode(org.olat.core.util.nodes.INode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode)

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