use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project openolat by klemens.
the class AssessmentTestComposerController method doNewTestPart.
/**
* Create a new test part and a section. Test part need a section,
* section ref as children, it's mandatory.
*
* @param ureq
*/
private void doNewTestPart(UserRequest ureq) {
TestPart testPart = AssessmentTestFactory.createTestPart(assessmentTestBuilder.getAssessmentTest());
AssessmentTestFactory.appendAssessmentSection(translate("new.section"), testPart);
// save the test
doSaveAssessmentTest(ureq, null);
// reload the test
updateTreeModel(false);
TreeNode newTestPartNode = menuTree.getTreeModel().getNodeById(testPart.getIdentifier().toString());
menuTree.setSelectedNode(newTestPartNode);
menuTree.open(newTestPartNode);
partEditorFactory(ureq, newTestPartNode);
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart 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);
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project openolat by klemens.
the class AssessmentTestComposerController method partEditorFactory.
private void partEditorFactory(UserRequest ureq, TreeNode selectedNode) {
// remove old one
if (currentEditorCtrl != null) {
mainVC.remove(currentEditorCtrl.getInitialComponent());
removeAsListenerAndDispose(currentEditorCtrl);
currentEditorCtrl = null;
}
// fill with the new
mainVC.contextPut("cssClass", selectedNode.getIconCssClass());
if (Settings.isDebuging()) {
mainVC.contextPut("identifier", selectedNode.getIdent());
}
mainVC.contextPut("title", selectedNode.getTitle());
mainVC.contextPut("restrictedEdit", restrictedEdit);
Object uobject = selectedNode.getUserObject();
if (uobject instanceof AssessmentTest) {
AssessmentTest test = (AssessmentTest) uobject;
URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testURI);
TestPart uniqueTestPart = test.getTestParts().size() == 1 ? test.getTestParts().get(0) : null;
currentEditorCtrl = new AssessmentTestEditorController(ureq, getWindowControl(), assessmentTestBuilder, uniqueTestPart, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit);
} else if (uobject instanceof TestPart) {
currentEditorCtrl = new AssessmentTestPartEditorController(ureq, getWindowControl(), (TestPart) uobject, restrictedEdit, assessmentTestBuilder.isEditable());
} else if (uobject instanceof AssessmentSection) {
URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testURI);
currentEditorCtrl = new AssessmentSectionEditorController(ureq, getWindowControl(), (AssessmentSection) uobject, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit, assessmentTestBuilder.isEditable());
} else if (uobject instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) uobject;
ResolvedAssessmentItem item = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
if (item == null || item.getItemLookup() == null) {
currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), null, unzippedDirRoot, itemRef.getHref());
} else if (item.getItemLookup().getBadResourceException() != null) {
currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), item.getItemLookup().getBadResourceException(), unzippedDirRoot, itemRef.getHref());
} else {
URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
File itemFile = new File(itemUri);
ManifestMetadataBuilder metadata = getMetadataBuilder(itemRef);
currentEditorCtrl = new AssessmentItemEditorController(ureq, getWindowControl(), testEntry, item, itemRef, metadata, unzippedDirRoot, unzippedContRoot, itemFile, restrictedEdit);
}
}
if (deleteLink != null) {
if (uobject instanceof AssessmentSection || uobject instanceof AssessmentItemRef) {
deleteLink.setEnabled(true);
} else if (uobject instanceof TestPart) {
TestPart testPart = (TestPart) uobject;
deleteLink.setEnabled(testPart.getParent().getTestParts().size() > 1);
} else {
deleteLink.setEnabled(false);
}
}
if (copyLink != null) {
copyLink.setEnabled(uobject instanceof AssessmentItemRef);
}
if (currentEditorCtrl != null) {
listenTo(currentEditorCtrl);
mainVC.put("content", currentEditorCtrl.getInitialComponent());
} else {
mainVC.put("content", new Panel("empty"));
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project openolat by klemens.
the class AssessmentTestComposerController method doConfirmDelete.
private void doConfirmDelete(UserRequest ureq) {
if (confirmDeleteCtrl != null)
return;
TreeNode selectedNode = menuTree.getSelectedNode();
if (selectedNode == null) {
showWarning("warning.atleastone");
return;
}
Object uobject = selectedNode.getUserObject();
if (uobject instanceof AssessmentTest) {
showWarning("error.cannot.delete");
} else if (uobject instanceof TestPart) {
TestPart testPart = (TestPart) uobject;
if (testPart.getParent().getTestParts().size() == 1) {
showWarning("error.cannot.delete");
}
String msg = translate("delete.testPart");
confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
confirmDeleteCtrl.setUserObject(selectedNode);
} else {
String msg;
if (uobject instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) uobject;
if (checkAtLeastOneSection(section)) {
msg = translate("delete.section", selectedNode.getTitle());
} else {
showWarning("warning.atleastonesection");
return;
}
} else if (uobject instanceof AssessmentItemRef) {
msg = translate("delete.item", selectedNode.getTitle());
} else {
showError("error.cannot.delete");
return;
}
confirmDeleteCtrl = activateYesNoDialog(ureq, translate("tools.change.delete"), msg, confirmDeleteCtrl);
confirmDeleteCtrl.setUserObject(selectedNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.TestPart in project openolat by klemens.
the class QTI21StatisticResourceResult method buildRecursively.
private void buildRecursively(AssessmentTest test, GenericTreeNode rootTreeNode) {
// list all test parts
List<TestPart> parts = test.getTestParts();
if (parts.size() == 1) {
TreeNode firstItem = null;
List<AssessmentSection> sections = test.getTestParts().get(0).getAssessmentSections();
for (AssessmentSection section : sections) {
TreeNode itemNode = buildRecursively(section, rootTreeNode);
if (firstItem == null) {
firstItem = itemNode;
}
}
} else {
int counter = 0;
for (TestPart part : parts) {
buildRecursively(part, ++counter, rootTreeNode);
}
}
}
Aggregations