Package org.olat.ims.qti.editor.tree

Examples of org.olat.ims.qti.editor.tree.ItemNode


      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();
View Full Code Here


        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,
View Full Code Here

              Memento mem = (Memento) history.get(key);
              result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
              result.append(sn.createChangeMessage(mem));
            }
          } else if (node instanceof ItemNode) {
            ItemNode in = (ItemNode) node;
            SectionNode sn = (SectionNode) in.getParent();
            String parentSectkey = ((Section) ((SectionNode) in.getParent()).getUnderlyingQTIObject()).getIdent();
            Item item = (Item) in.getUnderlyingQTIObject();
            Question question = item.getQuestion();
            String itemKey = item.getIdent();
            String prefixKey = "null/" + itemKey;
            String questionIdent = question != null ? question.getQuestion().getId() : "null";
            String key = prefixKey + "/" + questionIdent + "/null";
            StringBuilder changeMessage = new StringBuilder();
            boolean hasChanges = false;

            if (!itemMap.containsKey(itemKey)) {
              Memento questMem = null;
              Memento respMem = null;
              if (history.containsKey(key)) {
                // question changed!
                questMem = (Memento) history.get(key);
                hasChanges = true;
              }
              // if(!hasChanges){
              // check if a response changed
              // new prefix for responses
              prefixKey += "/null/";
              // list contains org.olat.ims.qti.editor.beecom.objects.Response
              List responses = question != null ? question.getResponses() : null;
              if (responses != null && responses.size() > 0) {
                // check for changes in each response
                for (Iterator iter = responses.iterator(); iter.hasNext();) {
                  Response resp = (Response) iter.next();
                  if (history.containsKey(prefixKey + resp.getIdent())) {
                    // this response changed!
                    Memento tmpMem = (Memento) history.get(prefixKey + resp.getIdent());
                    if (respMem != null) {
                      respMem = respMem.getTimestamp() > tmpMem.getTimestamp() ? tmpMem : respMem;
                    } else {
                      hasChanges = true;
                      respMem = tmpMem;
                    }
                  }
                }
              }
              // }
              // output message
              if (hasChanges) {
                Memento mem = null;
                if (questMem != null && respMem != null) {
                  // use the earlier memento
                  mem = questMem.getTimestamp() > respMem.getTimestamp() ? respMem : questMem;
                } else if (questMem != null) {
                  mem = questMem;
                } else if (respMem != null) {
                  mem = respMem;
                }
                changeMessage.append(in.createChangeMessage(mem));
                itemMap.put(itemKey, itemKey);
                if (!parentSectkey.equals(sectionKey)) {
                  // either this item belongs to a new section or no section
                  // is active
                  result.append("\n---++ Section " + formatVariable(sn.getAltText()) + " changes:");
View Full Code Here

TOP

Related Classes of org.olat.ims.qti.editor.tree.ItemNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.