TreeEvent te = (TreeEvent) event;
if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) {
// user chose a position to insert a new node
String nodeId = te.getNodeId();
TreePosition tp = insertTreeModel.getTreePosition(nodeId);
GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
int targetPos = tp.getChildpos();
GenericQtiNode selectedNode = (GenericQtiNode) menuTree.getSelectedNode();
int selectedPos = selectedNode.getPosition();
GenericQtiNode parentSelectedNode = (GenericQtiNode) selectedNode.getParent();
if (parentTargetNode == parentSelectedNode) {
// if we're on the same subnode
if (targetPos > selectedNode.getPosition()) {
// if we're moving after our current position
targetPos--;
// decrease insert pos since we're going to be removed from the
// parent before re-insert
}
}
// insert into menutree (insert on GenericNode do a remove from parent)
parentTargetNode.insert(selectedNode, targetPos);
// insert into model (remove from parent needed prior to insert)
QTIObject subject = parentSelectedNode.removeQTIObjectAt(selectedPos);
parentTargetNode.insertQTIObjectAt(subject, targetPos);
qtiPackage.serializeQTIDocument();
menuTree.setDirty(true); //force rerendering for ajax mode
}
} else if (source == copyTree) { // catch copy operations
cmc.deactivate();
removeAsListenerAndDispose(cmc);
cmc = null;
TreeEvent te = (TreeEvent) event;
if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) {
// user chose a position to insert the node to be copied
String nodeId = te.getNodeId();
TreePosition tp = insertTreeModel.getTreePosition(nodeId);
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();
}
} else if (source == insertTree) { // catch insert operations
cmc.deactivate();
removeAsListenerAndDispose(cmc);
cmc = null;
TreeEvent te = (TreeEvent) event;
if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) { // insert
// new
// node
String nodeId = te.getNodeId();
TreePosition tp = insertTreeModel.getTreePosition(nodeId);
GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
// insert into menu tree
parentTargetNode.insert(insertObject, tp.getChildpos());
// insert into model
parentTargetNode.insertQTIObjectAt(insertObject.getUnderlyingQTIObject(), tp.getChildpos());
// activate inserted node
menuTree.setSelectedNodeId(insertObject.getIdent());
event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
qtiPackage.serializeQTIDocument();
}