use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection 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.AssessmentSection in project openolat by klemens.
the class AssessmentTestComposerController method doCopy.
private void doCopy(UserRequest ureq) {
TreeNode selectedNode = menuTree.getSelectedNode();
if (selectedNode == null || !(selectedNode.getUserObject() instanceof AssessmentItemRef))
return;
AssessmentItemRef itemRefToCopy = (AssessmentItemRef) selectedNode.getUserObject();
AssessmentSection section = itemRefToCopy.getParentSection();
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRefToCopy);
AssessmentItem originalAssessmentItem = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
if (originalAssessmentItem == null) {
showError("error.assessment.item");
return;
}
QTI21QuestionType type = QTI21QuestionType.getType(originalAssessmentItem);
File itemFile = null;
try {
AssessmentItemRef itemRef = new AssessmentItemRef(section);
String itemId = IdentifierGenerator.newAsString(getTypePrefix(type));
itemRef.setIdentifier(Identifier.parseString(itemId));
itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
try (OutputStream out = new FileOutputStream(itemFile)) {
// make the copy
qtiService.qtiSerializer().serializeJqtiObject(originalAssessmentItem, out);
// change identifier and title
ResolvedAssessmentItem resolvedCopyItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), unzippedDirRoot);
AssessmentItem copiedAssessmentItem = resolvedCopyItem.getRootNodeLookup().extractIfSuccessful();
copiedAssessmentItem.setIdentifier(IdentifierGenerator.newAsString(getTypePrefix(type)));
copiedAssessmentItem.setTitle(originalAssessmentItem.getTitle() + " (Copy)");
qtiService.updateAssesmentObject(itemFile, resolvedCopyItem);
// add to section
section.getSectionParts().add(itemRef);
Map<AssessmentItemRef, AssessmentItem> flyingObjects = Collections.singletonMap(itemRef, copiedAssessmentItem);
doSaveAssessmentTest(ureq, flyingObjects);
manifestBuilder.appendAssessmentItem(itemFile.getName());
doSaveManifest();
} catch (Exception e) {
logError("", e);
}
updateTreeModel(false);
TreeNode newItemNode = menuTree.getTreeModel().getNodeById(itemId);
menuTree.setSelectedNode(newItemNode);
menuTree.open(newItemNode);
partEditorFactory(ureq, newItemNode);
} catch (URISyntaxException e) {
logError("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection 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.AssessmentSection in project openolat by klemens.
the class AssessmentTestEditorAndComposerTreeModel method buildRecursively.
private void buildRecursively(AssessmentSection section, TreeNode parentNode) {
GenericTreeNode sectionNode = new GenericTreeNode(section.getIdentifier().toString());
sectionNode.setTitle(section.getTitle());
sectionNode.setIconCssClass("o_icon o_mi_qtisection");
sectionNode.setUserObject(section);
parentNode.addChild(sectionNode);
for (SectionPart part : section.getSectionParts()) {
if (part instanceof AssessmentItemRef) {
buildRecursively((AssessmentItemRef) part, sectionNode);
} else if (part instanceof AssessmentSection) {
buildRecursively((AssessmentSection) part, sectionNode);
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21StatisticResourceResult method buildRecursively.
private TreeNode buildRecursively(AssessmentSection section, TreeNode parentNode) {
GenericTreeNode sectionNode = new GenericTreeNode();
sectionNode.setTitle(section.getTitle());
sectionNode.setIconCssClass("o_icon o_mi_qtisection");
sectionNode.setUserObject(section);
parentNode.addChild(sectionNode);
TreeNode firstItem = null;
for (SectionPart part : section.getSectionParts()) {
TreeNode itemNode = null;
if (part instanceof AssessmentItemRef) {
itemNode = buildRecursively((AssessmentItemRef) part, sectionNode);
} else if (part instanceof AssessmentSection) {
itemNode = buildRecursively((AssessmentSection) part, sectionNode);
}
if (firstItem == null) {
firstItem = itemNode;
}
}
sectionNode.setDelegate(firstItem);
return firstItem;
}
Aggregations