} else if (cmd.startsWith(CMD_TOOLS_ADD_PREFIX)) { // add new object
// fetch new object
if (cmd.equals(CMD_TOOLS_ADD_SECTION)) {
Section newSection = QTIEditHelper.createSection(getTranslator());
Item newItem = QTIEditHelper.createSCItem(getTranslator());
newSection.getItems().add(newItem);
SectionNode scNode = new SectionNode(newSection, qtiPackage);
ItemNode itemNode = new ItemNode(newItem, qtiPackage);
scNode.addChild(itemNode);
insertObject = scNode;
} else if (cmd.equals(CMD_TOOLS_ADD_SINGLECHOICE)) insertObject = new ItemNode(QTIEditHelper.createSCItem(getTranslator()), qtiPackage);
else if (cmd.equals(CMD_TOOLS_ADD_MULTIPLECHOICE)) insertObject = new ItemNode(QTIEditHelper.createMCItem(getTranslator()), qtiPackage);
else if (cmd.equals(CMD_TOOLS_ADD_KPRIM)) insertObject = new ItemNode(QTIEditHelper.createKPRIMItem(getTranslator()), qtiPackage);
else if (cmd.equals(CMD_TOOLS_ADD_FIB)) insertObject = new ItemNode(QTIEditHelper.createFIBItem(getTranslator()), qtiPackage);
else if (cmd.equals(CMD_TOOLS_ADD_FREETEXT)) insertObject = new ItemNode(QTIEditHelper.createEssayItem(getTranslator()), qtiPackage);
// prepare insert tree
insertTree = new SelectionTree("insertTree", getTranslator());
insertTree.setFormButtonKey("submit");
if (cmd.equals(CMD_TOOLS_ADD_SECTION)) insertTreeModel = new InsertItemTreeModel(menuTreeModel,
InsertItemTreeModel.INSTANCE_ASSESSMENT);
else insertTreeModel = new InsertItemTreeModel(menuTreeModel, InsertItemTreeModel.INSTANCE_SECTION);
insertTree.setTreeModel(insertTreeModel);
insertTree.addListener(this);
cmc = new CloseableModalController(getWindowControl(), translate("close"), insertTree, true, translate("title.add") );
cmc.activate();
listenTo(cmc);
}
} else if (source == deleteDialog) { // event from delete dialog
if (DialogBoxUIFactory.isYesEvent(event)) { // yes, delete
GenericQtiNode clickedNode = (GenericQtiNode) deleteDialog.getUserObject();
//check if any media to delete as well
if(clickedNode.getUnderlyingQTIObject() instanceof Item) {
Item selectedItem = (Item)clickedNode.getUnderlyingQTIObject();
deletableMediaFiles = QTIEditHelper.getDeletableMedia(qtiPackage.getQTIDocument(), selectedItem);
}
// remove from underlying model
((GenericQtiNode) clickedNode.getParent()).removeQTIObjectAt(clickedNode.getPosition());