Search in sources :

Example 11 with GenericQtiNode

use of org.olat.ims.qti.editor.tree.GenericQtiNode in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method doDelete.

private void doDelete(GenericQtiNode clickedNode) {
    // check if any media to delete as well
    if (clickedNode.getUnderlyingQTIObject() instanceof Item) {
        Item selectedItem = (Item) clickedNode.getUnderlyingQTIObject();
        deletableMediaFiles = QTIEditHelper.getDeletableMedia(qtiPackage.getQTIDocument(), selectedItem);
    }
    // remove from underlying model
    GenericQtiNode parentNode = (GenericQtiNode) clickedNode.getParent();
    parentNode.removeQTIObjectAt(clickedNode.getPosition());
    // remove from tree model
    clickedNode.removeFromParent();
    qtiPackage.serializeQTIDocument();
    menuTree.setSelectedNodeId(clickedNode.getParent().getIdent());
    parentNode.childNodeChanges();
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode)

Example 12 with GenericQtiNode

use of org.olat.ims.qti.editor.tree.GenericQtiNode in project OpenOLAT by OpenOLAT.

the class QTIEditorMainController method doCopy.

private void doCopy(UserRequest ureq, TreePosition tp) {
    // user chose a position to insert the node to be copied
    int targetPos = tp.getChildpos();
    ItemNode selectedNode = (ItemNode) menuTree.getSelectedNode();
    // only items are moveable
    // use XStream instead of ObjectCloner
    // Item qtiItem =
    // (Item)xstream.fromXML(xstream.toXML(selectedNode.getUnderlyingQTIObject()));
    Item toClone = (Item) selectedNode.getUnderlyingQTIObject();
    Item qtiItem = (Item) XStreamHelper.xstreamClone(toClone);
    // copy flow label class too, olat-2791
    Question orgQuestion = toClone.getQuestion();
    if (orgQuestion instanceof ChoiceQuestion) {
        String flowLabelClass = ((ChoiceQuestion) orgQuestion).getFlowLabelClass();
        Question copyQuestion = qtiItem.getQuestion();
        if (copyQuestion instanceof ChoiceQuestion) {
            ((ChoiceQuestion) copyQuestion).setFlowLabelClass(flowLabelClass);
        } else {
            throw new AssertException("Could not copy flow-label-class, wrong type of copy question , must be 'ChoiceQuestion' but is " + copyQuestion);
        }
    }
    String editorIdentPrefix = "";
    if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_SCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_MCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_KPRIM;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_FIB))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_FIB;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_ESSAY;
    // set new ident... this is all it needs for our engine to recognise it
    // as a new item.
    qtiItem.setIdent(editorIdentPrefix + CodeHelper.getForeverUniqueID());
    // insert into menutree (insert on GenericNode do a remove from parent)
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    GenericQtiNode newNode = new ItemNode(qtiItem, qtiPackage);
    parentTargetNode.insert(newNode, targetPos);
    // insert into model
    parentTargetNode.insertQTIObjectAt(qtiItem, targetPos);
    // activate copied node
    menuTree.setSelectedNodeId(newNode.getIdent());
    event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
    qtiPackage.serializeQTIDocument();
    parentTargetNode.childNodeChanges();
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) AssertException(org.olat.core.logging.AssertException) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Example 13 with GenericQtiNode

use of org.olat.ims.qti.editor.tree.GenericQtiNode 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)

Example 14 with GenericQtiNode

use of org.olat.ims.qti.editor.tree.GenericQtiNode in project openolat by klemens.

the class QTIEditorMainController method doExportQItem.

private void doExportQItem() {
    GenericQtiNode selectedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());
    if (selectedNode instanceof ItemNode) {
        ItemNode itemNode = (ItemNode) selectedNode;
        QTIObject qtiObject = itemNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Item) {
            ItemAndMetadata item = new ItemAndMetadata((Item) qtiObject);
            VFSContainer editorContainer = qtiPackage.getBaseDir();
            qtiQpoolServiceProvider.importBeecomItem(getIdentity(), item, editorContainer, getLocale());
            showInfo("export.qpool.successful", "1");
        }
    } else if (selectedNode instanceof SectionNode) {
        SectionNode sectionNode = (SectionNode) selectedNode;
        QTIObject qtiObject = sectionNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Section) {
            int count = doExportSection((Section) qtiObject);
            showInfo("export.qpool.successful", Integer.toString(count));
        }
    } else if (selectedNode instanceof AssessmentNode) {
        AssessmentNode assessmentNode = (AssessmentNode) selectedNode;
        QTIObject qtiObject = assessmentNode.getUnderlyingQTIObject();
        if (qtiObject instanceof Assessment) {
            int count = doExportAssessment((Assessment) qtiObject);
            showInfo("export.qpool.successful", Integer.toString(count));
        }
    }
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) QTIObject(org.olat.ims.qti.editor.beecom.objects.QTIObject) AssessmentNode(org.olat.ims.qti.editor.tree.AssessmentNode) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) ItemAndMetadata(org.olat.ims.qti.questionimport.ItemAndMetadata) SectionNode(org.olat.ims.qti.editor.tree.SectionNode) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 15 with GenericQtiNode

use of org.olat.ims.qti.editor.tree.GenericQtiNode in project openolat by klemens.

the class QTIEditorMainController method doCopy.

private void doCopy(UserRequest ureq, TreePosition tp) {
    // user chose a position to insert the node to be copied
    int targetPos = tp.getChildpos();
    ItemNode selectedNode = (ItemNode) menuTree.getSelectedNode();
    // only items are moveable
    // use XStream instead of ObjectCloner
    // Item qtiItem =
    // (Item)xstream.fromXML(xstream.toXML(selectedNode.getUnderlyingQTIObject()));
    Item toClone = (Item) selectedNode.getUnderlyingQTIObject();
    Item qtiItem = (Item) XStreamHelper.xstreamClone(toClone);
    // copy flow label class too, olat-2791
    Question orgQuestion = toClone.getQuestion();
    if (orgQuestion instanceof ChoiceQuestion) {
        String flowLabelClass = ((ChoiceQuestion) orgQuestion).getFlowLabelClass();
        Question copyQuestion = qtiItem.getQuestion();
        if (copyQuestion instanceof ChoiceQuestion) {
            ((ChoiceQuestion) copyQuestion).setFlowLabelClass(flowLabelClass);
        } else {
            throw new AssertException("Could not copy flow-label-class, wrong type of copy question , must be 'ChoiceQuestion' but is " + copyQuestion);
        }
    }
    String editorIdentPrefix = "";
    if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_SCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_MCQ;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_KPRIM;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_FIB))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_FIB;
    else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY))
        editorIdentPrefix = ItemParser.ITEM_PREFIX_ESSAY;
    // set new ident... this is all it needs for our engine to recognise it
    // as a new item.
    qtiItem.setIdent(editorIdentPrefix + CodeHelper.getForeverUniqueID());
    // insert into menutree (insert on GenericNode do a remove from parent)
    GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
    GenericQtiNode newNode = new ItemNode(qtiItem, qtiPackage);
    parentTargetNode.insert(newNode, targetPos);
    // insert into model
    parentTargetNode.insertQTIObjectAt(qtiItem, targetPos);
    // activate copied node
    menuTree.setSelectedNodeId(newNode.getIdent());
    event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
    qtiPackage.serializeQTIDocument();
    parentTargetNode.childNodeChanges();
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) ItemNode(org.olat.ims.qti.editor.tree.ItemNode) AssertException(org.olat.core.logging.AssertException) GenericQtiNode(org.olat.ims.qti.editor.tree.GenericQtiNode) QItemViewEvent(org.olat.modules.qpool.ui.events.QItemViewEvent) Event(org.olat.core.gui.control.Event) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion) Question(org.olat.ims.qti.editor.beecom.objects.Question) ChoiceQuestion(org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion)

Aggregations

GenericQtiNode (org.olat.ims.qti.editor.tree.GenericQtiNode)16 Item (org.olat.ims.qti.editor.beecom.objects.Item)10 ItemNode (org.olat.ims.qti.editor.tree.ItemNode)10 Event (org.olat.core.gui.control.Event)6 QItemViewEvent (org.olat.modules.qpool.ui.events.QItemViewEvent)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)4 Section (org.olat.ims.qti.editor.beecom.objects.Section)4 AssessmentNode (org.olat.ims.qti.editor.tree.AssessmentNode)4 SectionNode (org.olat.ims.qti.editor.tree.SectionNode)4 ItemAndMetadata (org.olat.ims.qti.questionimport.ItemAndMetadata)4 ItemsPackage (org.olat.ims.qti.questionimport.ItemsPackage)4 QuestionItemView (org.olat.modules.qpool.QuestionItemView)4 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Component (org.olat.core.gui.components.Component)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