use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method doDrop.
private void doDrop(UserRequest ureq, String droppedNodeId, String targetnodeId, boolean asChild) {
TreeNode droppedNode = menuTree.getTreeModel().getNodeById(droppedNodeId);
TreeNode targetNode = menuTree.getTreeModel().getNodeById(targetnodeId);
if (droppedNode == null || targetNode == null)
return;
Object droppedObject = droppedNode.getUserObject();
Object targetObject = targetNode.getUserObject();
if (droppedObject == null || targetObject == null || droppedObject == targetObject)
return;
if (asChild) {
if (droppedObject instanceof AssessmentItemRef && (targetObject instanceof AssessmentSection || targetObject instanceof AssessmentItemRef)) {
AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
if (targetObject instanceof AssessmentSection) {
AssessmentSection targetSection = (AssessmentSection) targetObject;
targetSection.getSectionParts().add(droppedItemRef);
} else if (targetObject instanceof AssessmentItemRef) {
AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
AssessmentSection targetSection = targetItemRef.getParentSection();
int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef);
targetSection.getChildAbstractParts().add(pos, droppedItemRef);
}
} else if (droppedObject instanceof AssessmentSection && (targetObject instanceof AssessmentSection || targetObject instanceof TestPart || (targetObject instanceof AssessmentTest && ((AssessmentTest) targetObject).getTestParts().size() == 1))) {
AssessmentSection droppedSection = (AssessmentSection) droppedObject;
if (droppedSection.getParentSection() != null) {
droppedSection.getParentSection().getSectionParts().remove(droppedSection);
} else {
droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
}
if (targetObject instanceof AssessmentSection) {
AssessmentSection targetSection = (AssessmentSection) targetObject;
targetSection.getChildAbstractParts().add(droppedSection);
} else if (targetObject instanceof TestPart) {
TestPart targetTestPart = (TestPart) targetObject;
targetTestPart.getAssessmentSections().add(droppedSection);
} else if (targetObject instanceof AssessmentTest) {
TestPart targetTestPart = ((AssessmentTest) targetObject).getTestParts().get(0);
targetTestPart.getAssessmentSections().add(droppedSection);
}
}
} else {
if (droppedObject instanceof AssessmentItemRef && targetObject instanceof AssessmentItemRef) {
AssessmentItemRef droppedItemRef = (AssessmentItemRef) droppedObject;
droppedItemRef.getParentSection().getSectionParts().remove(droppedItemRef);
AssessmentItemRef targetItemRef = (AssessmentItemRef) targetObject;
AssessmentSection targetSection = targetItemRef.getParentSection();
int pos = targetSection.getChildAbstractParts().indexOf(targetItemRef) + 1;
if (pos < 0) {
targetSection.getChildAbstractParts().add(droppedItemRef);
} else if (pos >= targetSection.getChildAbstractParts().size()) {
targetSection.getChildAbstractParts().add(droppedItemRef);
} else {
targetSection.getChildAbstractParts().add(pos, droppedItemRef);
}
} else if (droppedObject instanceof AssessmentSection && targetObject instanceof AssessmentSection) {
AssessmentSection droppedSection = (AssessmentSection) droppedObject;
if (droppedSection.getParentSection() != null) {
droppedSection.getParentSection().getSectionParts().remove(droppedSection);
} else {
droppedSection.getParent().getChildAbstractParts().remove(droppedSection);
}
AssessmentSection targetSection = (AssessmentSection) targetObject;
if (targetSection.getParentSection() != null) {
AssessmentSection targetParentSection = targetSection.getParentSection();
int pos = targetParentSection.getChildAbstractParts().indexOf(targetSection) + 1;
if (pos >= targetParentSection.getChildAbstractParts().size()) {
targetParentSection.getChildAbstractParts().add(droppedSection);
} else {
targetParentSection.getChildAbstractParts().add(pos, droppedSection);
}
} else if (targetSection.getParent() instanceof TestPart) {
TestPart targetTestPart = (TestPart) targetSection.getParent();
int pos = targetTestPart.getChildAbstractParts().indexOf(targetSection) + 1;
if (pos >= targetTestPart.getChildAbstractParts().size()) {
targetTestPart.getChildAbstractParts().add(droppedSection);
} else {
targetTestPart.getChildAbstractParts().add(pos, droppedSection);
}
}
}
}
// quickly saved the assessment test with wrong parent
doSaveAssessmentTest(ureq, null);
// reload a clean instance
updateTreeModel(false);
TreeNode droppedItemNode = menuTree.getTreeModel().getNodeById(droppedNode.getIdent());
if (droppedItemNode != null) {
menuTree.setSelectedNode(droppedItemNode);
menuTree.open(droppedItemNode);
partEditorFactory(ureq, droppedItemNode);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection 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);
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class AssessmentTestComposerController method doDeleteTestPart.
private void doDeleteTestPart(UserRequest ureq, TestPart testPart) {
List<AssessmentSection> sections = new ArrayList<>(testPart.getAssessmentSections());
for (AssessmentSection section : sections) {
doDeleteAssessmentSection(ureq, section);
}
testPart.getParent().getTestParts().remove(testPart);
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project OpenOLAT by OpenOLAT.
the class AssessmentTestEditorAndComposerTreeModel method buildRecursively.
private void buildRecursively(TestPart part, int pos, TreeNode parentNode) {
GenericTreeNode partNode = new GenericTreeNode(part.getIdentifier().toString());
partNode.setTitle(pos + ". Test part");
partNode.setIconCssClass("o_icon o_qtiassessment_icon");
partNode.setUserObject(part);
parentNode.addChild(partNode);
List<AssessmentSection> sections = part.getAssessmentSections();
for (AssessmentSection section : sections) {
buildRecursively(section, partNode);
}
}
Aggregations