Search in sources :

Example 1 with AbstractPart

use of uk.ac.ed.ph.jqtiplus.node.test.AbstractPart in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doNewSection.

private void doNewSection(UserRequest ureq, TreeNode selectedNode) {
    AbstractPart parentPart;
    TreeNode sectionNode = getNearestSection(selectedNode);
    if (sectionNode != null) {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        parentPart = section.getParent();
    } else if (selectedNode.getUserObject() instanceof TestPart) {
        parentPart = (TestPart) selectedNode.getUserObject();
    } else {
        TreeNode rootNode = menuTree.getTreeModel().getRootNode();
        AssessmentTest assessmentTest = (AssessmentTest) rootNode.getUserObject();
        List<TestPart> parts = assessmentTest.getTestParts();
        if (parts != null && parts.size() > 0) {
            parentPart = parts.get(0);
        } else {
            showWarning("error.cannot.create.section");
            return;
        }
    }
    AssessmentSection newSection;
    if (parentPart instanceof TestPart) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (TestPart) parentPart);
    } else if (parentPart instanceof AssessmentSection) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (AssessmentSection) parentPart);
    } else {
        showWarning("error.cannot.create.section");
        return;
    }
    // save the test
    URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
    File testFile = new File(testUri);
    qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
    assessmentChanged(ureq);
    // reload the test
    updateTreeModel(false);
    TreeNode newSectionNode = menuTree.getTreeModel().getNodeById(newSection.getIdentifier().toString());
    menuTree.setSelectedNode(newSectionNode);
    menuTree.open(newSectionNode);
    partEditorFactory(ureq, newSectionNode);
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AbstractPart(uk.ac.ed.ph.jqtiplus.node.test.AbstractPart) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) File(java.io.File)

Example 2 with AbstractPart

use of uk.ac.ed.ph.jqtiplus.node.test.AbstractPart in project openolat by klemens.

the class AssessmentTestComposerController method doNewSection.

private void doNewSection(UserRequest ureq, TreeNode selectedNode) {
    AbstractPart parentPart;
    TreeNode sectionNode = getNearestSection(selectedNode);
    if (sectionNode != null) {
        AssessmentSection section = (AssessmentSection) sectionNode.getUserObject();
        parentPart = section.getParent();
    } else if (selectedNode.getUserObject() instanceof TestPart) {
        parentPart = (TestPart) selectedNode.getUserObject();
    } else {
        TreeNode rootNode = menuTree.getTreeModel().getRootNode();
        AssessmentTest assessmentTest = (AssessmentTest) rootNode.getUserObject();
        List<TestPart> parts = assessmentTest.getTestParts();
        if (parts != null && parts.size() > 0) {
            parentPart = parts.get(0);
        } else {
            showWarning("error.cannot.create.section");
            return;
        }
    }
    AssessmentSection newSection;
    if (parentPart instanceof TestPart) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (TestPart) parentPart);
    } else if (parentPart instanceof AssessmentSection) {
        newSection = AssessmentTestFactory.appendAssessmentSection(translate("new.section"), (AssessmentSection) parentPart);
    } else {
        showWarning("error.cannot.create.section");
        return;
    }
    // save the test
    URI testUri = resolvedAssessmentTest.getTestLookup().getSystemId();
    File testFile = new File(testUri);
    qtiService.updateAssesmentObject(testFile, resolvedAssessmentTest);
    assessmentChanged(ureq);
    // reload the test
    updateTreeModel(false);
    TreeNode newSectionNode = menuTree.getTreeModel().getNodeById(newSection.getIdentifier().toString());
    menuTree.setSelectedNode(newSectionNode);
    menuTree.open(newSectionNode);
    partEditorFactory(ureq, newSectionNode);
}
Also used : AssessmentTest(uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest) ResolvedAssessmentTest(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) AbstractPart(uk.ac.ed.ph.jqtiplus.node.test.AbstractPart) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) ArrayList(java.util.ArrayList) List(java.util.List) URI(java.net.URI) File(java.io.File)

Aggregations

File (java.io.File)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 TreeNode (org.olat.core.gui.components.tree.TreeNode)2 AbstractPart (uk.ac.ed.ph.jqtiplus.node.test.AbstractPart)2 AssessmentSection (uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection)2 AssessmentTest (uk.ac.ed.ph.jqtiplus.node.test.AssessmentTest)2 TestPart (uk.ac.ed.ph.jqtiplus.node.test.TestPart)2 ResolvedAssessmentTest (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentTest)2