Search in sources :

Example 1 with Memento

use of org.olat.core.util.memento.Memento in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialog) {
        // event from delete dialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
            doDelete(clickedNode);
            event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
            // ask user to confirm referenced media removal
            if (deletableMediaFiles != null && deletableMediaFiles.size() > 0) {
                String msg = translate("delete.item.media", deletableMediaFiles.toString());
                deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
            }
            updateWarning();
        }
        // cleanup controller
        removeAsListenerAndDispose(deleteDialog);
        deleteDialog = null;
    } else if (source == deleteMediaDialog) {
        // event from deleteMediaDialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            qtiPackage.removeMediaFiles(deletableMediaFiles);
            deleteMediaDialog = null;
            deletableMediaFiles = null;
        }
    } else if (event instanceof NodeBeforeChangeEvent) {
        NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
        // active node changed some data
        String activeQtiNodeId = menuTree.getSelectedNodeId();
        GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
        // force rerendering for ajax mode
        menuTree.setDirty(true);
        /*
			 * mementos are only created in restricted mode
			 */
        if (isRestrictedEdit()) {
            String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
            if (!history.containsKey(key)) {
                Memento memento = activeQtiNode.createMemento();
                history.put(key, memento);
                qtiPackage.serializeChangelog(history);
            }
        }
        /*
			 * generate a Memento, store it for further use
			 */
        if (nce.hasNewTitle) {
            // update the treemodel to reflect the change of the underlying qti node
            activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
            main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
        }
    } else if (source == proceedRestricedEditDialog) {
        // restricted edit warning
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // remove dialog and continue with real content
            columnLayoutCtr.setCol3(mainPanel);
            columnLayoutCtr.hideCol1(false);
            columnLayoutCtr.hideCol2(false);
            removeAsListenerAndDispose(proceedRestricedEditDialog);
            proceedRestricedEditDialog = null;
        } else {
            // remove lock as user is not interested in restricted edit
            // and quick editor
            removeLocksAndExit(ureq);
        }
    } else if (source == cfc) {
        // dispose the content only controller we live in
        // remove modal dialog and cleanup exit process
        // modal dialog must be removed before fire DONE event
        // within the saveAndExit() call, otherwise the wrong
        // gui stack is popped see also OLAT-3056
        cmcExit.deactivate();
        removeAsListenerAndDispose(cmcExit);
        cmcExit = null;
        if (event == Event.CANCELLED_EVENT) {
        // nothing to do, back to editor
        } else {
            QTIChangeLogMessage clm = new QTIChangeLogMessage(changeLog, chngMsgFrom.hasInformLearners());
            qtiPackage.commitChangelog(clm);
            StringBuilder traceMsg = new StringBuilder(chngMsgFrom.hasInformLearners() ? "Visible for ALL \n" : "Visible for GROUP only \n");
            logAudit(traceMsg.append(changeLog).toString(), null);
            // save, remove locks and tmp files
            saveAndExit(ureq);
        }
        removeAsListenerAndDispose(cfc);
        cfc = null;
    } else if (source == chngMsgFrom) {
        if (event == Event.DONE_EVENT) {
            // the changemessage is created and user is willing to send it
            String userMsg = chngMsgFrom.getUserMsg();
            changeLog = changeEmail.getBodyText();
            if (StringHelper.containsNonWhitespace(userMsg)) {
                changeEmail.setBodyText("<p>" + userMsg + "</p>\n<pre>" + changeLog + "</pre>");
            }
            // else nothing was added!
            changeEmail.setSubject("Change log for " + startedWithTitle);
            cfc = new ContactFormController(ureq, getWindowControl(), true, false, false, changeEmail);
            listenTo(cfc);
            exitPanel.setContent(cfc.getInitialComponent());
            return;
        } else {
            // cancel button was pressed
            // just go back to the editor - remove modal dialog
            cmcExit.deactivate();
        }
    } else if (source == selectQItemCtrl) {
        cmc.deactivate();
        cleanUp();
        if (event instanceof QItemViewEvent) {
            QItemViewEvent e = (QItemViewEvent) event;
            List<QuestionItemView> items = e.getItemList();
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, items);
        }
    } else if (source == importTableWizard) {
        ItemsPackage importPackage = (ItemsPackage) importTableWizard.getRunContext().get("importPackage");
        getWindowControl().pop();
        cleanUp();
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, importPackage);
        }
    } else if (createConvertedTestController == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            showInfo("test.converted");
            RepositoryEntry convertedEntry = createConvertedTestController.getAddedEntry();
            String businessPath = "[RepositoryEntry:" + convertedEntry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        }
        cleanUp();
    } else if (source == insertCtrl) {
        // catch insert operations
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            TreePosition tp = insertCtrl.getInsertPosition();
            if (tp != null) {
                doInsert(ureq, tp, insertCtrl.getUserObject());
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == moveCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = moveCtrl.getInsertPosition();
            if (tp != null) {
                doMove(tp);
                // force rerendering for ajax mode
                menuTree.setDirty(true);
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == copyCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = copyCtrl.getInsertPosition();
            if (tp != null) {
                doCopy(ureq, tp);
                updateWarning();
            }
        }
        cleanUp();
    }
}
Also used : GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) RepositoryEntry(org.olat.repository.RepositoryEntry) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) TreePosition(org.olat.core.gui.components.tree.TreePosition) Memento(org.olat.core.util.memento.Memento) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ContactFormController(org.olat.modules.co.ContactFormController) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 2 with Memento

use of org.olat.core.util.memento.Memento in project OpenOLAT by OpenOLAT.

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 3 with Memento

use of org.olat.core.util.memento.Memento in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method init.

private void init(UserRequest ureq) {
    main = createVelocityContainer("index");
    JSAndCSSComponent jsAndCss;
    // Add html header js
    jsAndCss = new JSAndCSSComponent("qitjsandcss", new String[] { "js/openolat/qti.js" }, null);
    main.put("qitjsandcss", jsAndCss);
    mainPanel = new Panel("p_qti_editor");
    mainPanel.setContent(main);
    if (notEditable) {
        // test not editable
        VelocityContainer notEditableVc = createVelocityContainer("notEditable");
        notEditableButton = LinkFactory.createButton("ok", notEditableVc, this);
        Panel panel = new Panel("notEditable");
        panel.setContent(notEditableVc);
        columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, panel, null);
        putInitialPanel(columnLayoutCtr.getInitialComponent());
        return;
    }
    stackedPanel = new TooledStackedPanel("qtiEditorStackedPanel", getTranslator(), this);
    stackedPanel.setCssClass("o_edit_mode");
    // initialize the history
    if (qtiPackage.isResumed() && qtiPackage.hasSerializedChangelog()) {
        // there were already changes made -> reload!
        history = qtiPackage.loadChangelog();
    } else {
        // start with a fresh history. Editor is resumed but no changes were made
        // so far.
        history = new HashMap<String, Memento>();
    }
    // The menu tree model represents the structure of the qti document.
    // All insert/move operations on the model are propagated to the structure
    // by the node
    menuTreeModel = new QTIEditorTreeModel(qtiPackage);
    menuTree = new MenuTree("QTIDocumentTree");
    menuTree.setTreeModel(menuTreeModel);
    menuTree.setSelectedNodeId(menuTree.getTreeModel().getRootNode().getIdent());
    // listen to the tree
    menuTree.addListener(this);
    // remember the qtidoc title when we started this editor, to correctly name
    // the history report
    startedWithTitle = menuTree.getSelectedNode().getAltText();
    // 
    main.put("tabbedPane", menuTreeModel.getQtiRootNode().createEditTabbedPane(ureq, getWindowControl(), getTranslator(), this));
    main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
    main.contextPut("isRestrictedEdit", restrictedEdit ? Boolean.TRUE : Boolean.FALSE);
    // 
    columnLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), menuTree, mainPanel, "qtieditor" + qtiPackage.getRepresentingResourceable());
    listenTo(columnLayoutCtr);
    stackedPanel.pushController("Editor", columnLayoutCtr);
    // qtiPackage must be loaded previousely
    populateToolC();
    // Add css background
    if (restrictedEdit) {
        addSectionLink.setEnabled(false);
        addSCLink.setEnabled(false);
        addMCLink.setEnabled(false);
        addPoolLink.setEnabled(false);
        addFIBLink.setEnabled(false);
        if (!qtiPackage.getQTIDocument().isSurvey()) {
            addKPrimLink.setEnabled(false);
        }
        addEssayLink.setEnabled(false);
        columnLayoutCtr.addCssClassToMain("o_editor_qti_correct");
    } else {
        columnLayoutCtr.addCssClassToMain("o_editor_qti");
    }
    deleteLink.setEnabled(false);
    moveLink.setEnabled(false);
    copyLink.setEnabled(false);
    putInitialPanel(stackedPanel);
    if (restrictedEdit) {
        // we would like to us a modal dialog here, but this does not work! we
        // can't push to stack because the outher workflows pushes us after the
        // controller to the stack. Thus, if we used a modal dialog here the
        // dialog would never show up.
        columnLayoutCtr.setCol3(new Panel("empty"));
        columnLayoutCtr.hideCol1(true);
        columnLayoutCtr.hideCol2(true);
        String text = translate("qti.restricted.edit.warning") + "<br/><br/>" + createReferenceesMsg(ureq);
        proceedRestricedEditDialog = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, text);
        listenTo(proceedRestricedEditDialog);
        proceedRestricedEditDialog.activate();
    }
}
Also used : QTIEditorTreeModel(org.olat.ims.qti.editor.tree.QTIEditorTreeModel) MenuTree(org.olat.core.gui.components.tree.MenuTree) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Panel(org.olat.core.gui.components.panel.Panel) TooledStackedPanel(org.olat.core.gui.components.stack.TooledStackedPanel) Memento(org.olat.core.util.memento.Memento) JSAndCSSComponent(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) VelocityContainer(org.olat.core.gui.components.velocity.VelocityContainer)

Example 4 with Memento

use of org.olat.core.util.memento.Memento 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 5 with Memento

use of org.olat.core.util.memento.Memento in project openolat by klemens.

the class QTIEditorMainController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialog) {
        // event from delete dialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
            doDelete(clickedNode);
            event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
            // ask user to confirm referenced media removal
            if (deletableMediaFiles != null && deletableMediaFiles.size() > 0) {
                String msg = translate("delete.item.media", deletableMediaFiles.toString());
                deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
            }
            updateWarning();
        }
        // cleanup controller
        removeAsListenerAndDispose(deleteDialog);
        deleteDialog = null;
    } else if (source == deleteMediaDialog) {
        // event from deleteMediaDialog
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // yes, delete
            qtiPackage.removeMediaFiles(deletableMediaFiles);
            deleteMediaDialog = null;
            deletableMediaFiles = null;
        }
    } else if (event instanceof NodeBeforeChangeEvent) {
        NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
        // active node changed some data
        String activeQtiNodeId = menuTree.getSelectedNodeId();
        GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
        // force rerendering for ajax mode
        menuTree.setDirty(true);
        /*
			 * mementos are only created in restricted mode
			 */
        if (isRestrictedEdit()) {
            String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
            if (!history.containsKey(key)) {
                Memento memento = activeQtiNode.createMemento();
                history.put(key, memento);
                qtiPackage.serializeChangelog(history);
            }
        }
        /*
			 * generate a Memento, store it for further use
			 */
        if (nce.hasNewTitle) {
            // update the treemodel to reflect the change of the underlying qti node
            activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
            main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
        }
    } else if (source == proceedRestricedEditDialog) {
        // restricted edit warning
        if (DialogBoxUIFactory.isYesEvent(event)) {
            // remove dialog and continue with real content
            columnLayoutCtr.setCol3(mainPanel);
            columnLayoutCtr.hideCol1(false);
            columnLayoutCtr.hideCol2(false);
            removeAsListenerAndDispose(proceedRestricedEditDialog);
            proceedRestricedEditDialog = null;
        } else {
            // remove lock as user is not interested in restricted edit
            // and quick editor
            removeLocksAndExit(ureq);
        }
    } else if (source == cfc) {
        // dispose the content only controller we live in
        // remove modal dialog and cleanup exit process
        // modal dialog must be removed before fire DONE event
        // within the saveAndExit() call, otherwise the wrong
        // gui stack is popped see also OLAT-3056
        cmcExit.deactivate();
        removeAsListenerAndDispose(cmcExit);
        cmcExit = null;
        if (event == Event.CANCELLED_EVENT) {
        // nothing to do, back to editor
        } else {
            QTIChangeLogMessage clm = new QTIChangeLogMessage(changeLog, chngMsgFrom.hasInformLearners());
            qtiPackage.commitChangelog(clm);
            StringBuilder traceMsg = new StringBuilder(chngMsgFrom.hasInformLearners() ? "Visible for ALL \n" : "Visible for GROUP only \n");
            logAudit(traceMsg.append(changeLog).toString(), null);
            // save, remove locks and tmp files
            saveAndExit(ureq);
        }
        removeAsListenerAndDispose(cfc);
        cfc = null;
    } else if (source == chngMsgFrom) {
        if (event == Event.DONE_EVENT) {
            // the changemessage is created and user is willing to send it
            String userMsg = chngMsgFrom.getUserMsg();
            changeLog = changeEmail.getBodyText();
            if (StringHelper.containsNonWhitespace(userMsg)) {
                changeEmail.setBodyText("<p>" + userMsg + "</p>\n<pre>" + changeLog + "</pre>");
            }
            // else nothing was added!
            changeEmail.setSubject("Change log for " + startedWithTitle);
            cfc = new ContactFormController(ureq, getWindowControl(), true, false, false, changeEmail);
            listenTo(cfc);
            exitPanel.setContent(cfc.getInitialComponent());
            return;
        } else {
            // cancel button was pressed
            // just go back to the editor - remove modal dialog
            cmcExit.deactivate();
        }
    } else if (source == selectQItemCtrl) {
        cmc.deactivate();
        cleanUp();
        if (event instanceof QItemViewEvent) {
            QItemViewEvent e = (QItemViewEvent) event;
            List<QuestionItemView> items = e.getItemList();
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, items);
        }
    } else if (source == importTableWizard) {
        ItemsPackage importPackage = (ItemsPackage) importTableWizard.getRunContext().get("importPackage");
        getWindowControl().pop();
        cleanUp();
        if (event == Event.DONE_EVENT || event == Event.CHANGED_EVENT) {
            doSelectInsertionPoint(ureq, CMD_TOOLS_ADD_QPOOL, importPackage);
        }
    } else if (createConvertedTestController == source) {
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            showInfo("test.converted");
            RepositoryEntry convertedEntry = createConvertedTestController.getAddedEntry();
            String businessPath = "[RepositoryEntry:" + convertedEntry.getKey() + "]";
            NewControllerFactory.getInstance().launch(businessPath, ureq, getWindowControl());
        }
        cleanUp();
    } else if (source == insertCtrl) {
        // catch insert operations
        cmc.deactivate();
        if (event == Event.DONE_EVENT) {
            TreePosition tp = insertCtrl.getInsertPosition();
            if (tp != null) {
                doInsert(ureq, tp, insertCtrl.getUserObject());
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == moveCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = moveCtrl.getInsertPosition();
            if (tp != null) {
                doMove(tp);
                // force rerendering for ajax mode
                menuTree.setDirty(true);
                updateWarning();
            }
        }
        cleanUp();
    } else if (source == copyCtrl) {
        cmc.deactivate();
        if (Event.DONE_EVENT == event) {
            TreePosition tp = copyCtrl.getInsertPosition();
            if (tp != null) {
                doCopy(ureq, tp);
                updateWarning();
            }
        }
        cleanUp();
    }
}
Also used : GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) RepositoryEntry(org.olat.repository.RepositoryEntry) ItemsPackage(org.olat.ims.qti.questionimport.ItemsPackage) TreePosition(org.olat.core.gui.components.tree.TreePosition) Memento(org.olat.core.util.memento.Memento) QTIChangeLogMessage(org.olat.ims.qti.QTIChangeLogMessage) ContactFormController(org.olat.modules.co.ContactFormController) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Aggregations

Memento (org.olat.core.util.memento.Memento)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)2 JSAndCSSComponent (org.olat.core.gui.components.htmlheader.jscss.JSAndCSSComponent)2 Panel (org.olat.core.gui.components.panel.Panel)2 TooledStackedPanel (org.olat.core.gui.components.stack.TooledStackedPanel)2 MenuTree (org.olat.core.gui.components.tree.MenuTree)2 TreePosition (org.olat.core.gui.components.tree.TreePosition)2 VelocityContainer (org.olat.core.gui.components.velocity.VelocityContainer)2 Event (org.olat.core.gui.control.Event)2 INode (org.olat.core.util.nodes.INode)2 TreeVisitor (org.olat.core.util.tree.TreeVisitor)2 Visitor (org.olat.core.util.tree.Visitor)2 QTIChangeLogMessage (org.olat.ims.qti.QTIChangeLogMessage)2 ChoiceQuestion (org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 Question (org.olat.ims.qti.editor.beecom.objects.Question)2 Response (org.olat.ims.qti.editor.beecom.objects.Response)2 Section (org.olat.ims.qti.editor.beecom.objects.Section)2