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

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


   */
  public void event(UserRequest ureq, Component source, Event event) {
    //
    if (source == menuTree) { // catch menu tree clicks
      if (event.getCommand().equals(MenuTree.COMMAND_TREENODE_CLICKED)) {
        GenericQtiNode clickedNode;       
        clickedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());       
        TabbedPane tabbedPane = clickedNode.createEditTabbedPane(ureq, getWindowControl(), getTranslator(), this);
        if(tabbedPane!=null) {
          main.put("tabbedPane",tabbedPane);
        } else {
          VelocityContainer itemNotEditable = createVelocityContainer("tab_itemAlien");           
          main.put("tabbedPane", itemNotEditable);
          return;         
        }
       
        // enable/disable delete and move
        // if (!restrictedEdit) {
        // only available in full edit mode
        if (clickedNode instanceof AssessmentNode) {
          mainToolC.setEnabled(CMD_TOOLS_CHANGE_DELETE, false);
          mainToolC.setEnabled(CMD_TOOLS_CHANGE_MOVE, false);
          mainToolC.setEnabled(CMD_TOOLS_CHANGE_COPY, false);
        } else {
          mainToolC.setEnabled(CMD_TOOLS_CHANGE_DELETE, true && !restrictedEdit);
          mainToolC.setEnabled(CMD_TOOLS_CHANGE_MOVE, true && !restrictedEdit);
          if (clickedNode instanceof ItemNode) {
            mainToolC.setEnabled(CMD_TOOLS_CHANGE_COPY, true && !restrictedEdit);
          } else {
            mainToolC.setEnabled(CMD_TOOLS_CHANGE_COPY, false);
          }
        }
        // }
      }
    } else if (source == moveTree) { // catch move 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 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();
      }
View Full Code Here


        } else {
          getWindowControl().setWarning(translate("error.preview"));
        }
      } else if (cmd.equals(CMD_TOOLS_CHANGE_DELETE)) { // prepare delete

        GenericQtiNode clickedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());
        String msg = "";
        if (clickedNode instanceof SectionNode) {
          if (QTIEditHelper.countSections(qtiPackage.getQTIDocument().getAssessment()) == 1) {
            // At least one section
            getWindowControl().setError(translate("error.atleastonesection"));
            return;
          }
          msg = translate("delete.section", clickedNode.getTitle());
        } else if (clickedNode instanceof ItemNode) {
          if (((SectionNode) clickedNode.getParent()).getChildCount() == 1) {
            // At least one item
            getWindowControl().setError(translate("error.atleastoneitem"));
            return;
          }
          msg = translate("delete.item", clickedNode.getTitle());
        }
        deleteDialog = activateYesNoDialog(ureq, null, msg, deleteDialog);
        deleteDialog.setUserObject(clickedNode);
        return;
      } else if (cmd.equals(CMD_TOOLS_CHANGE_MOVE)) {     
        //cannot move the last item
        GenericQtiNode clickedNode = menuTreeModel.getQtiNode(menuTree.getSelectedNodeId());
        if (clickedNode instanceof ItemNode && ((SectionNode) clickedNode.getParent()).getChildCount() == 1) {       
          getWindowControl().setError(translate("error.move.atleastoneitem"));
          return;
        }
        TreeNode selectedNode = menuTree.getSelectedNode();
        moveTree = new SelectionTree("moveTree", getTranslator());
        moveTree.setFormButtonKey("submit");
        insertTreeModel = new InsertItemTreeModel(menuTreeModel,
            (selectedNode instanceof SectionNode) ? InsertItemTreeModel.INSTANCE_ASSESSMENT : InsertItemTreeModel.INSTANCE_SECTION);
        moveTree.setTreeModel(insertTreeModel);
        moveTree.addListener(this);
        cmc = new CloseableModalController(getWindowControl(),translate("close"), moveTree, true, translate("title.move"));
        cmc.activate();
        listenTo(cmc);
       
      } else if (cmd.equals(CMD_TOOLS_CHANGE_COPY)) {
        copyTree = new SelectionTree("copyTree", getTranslator());
        copyTree.setFormButtonKey("submit");
        insertTreeModel = new InsertItemTreeModel(menuTreeModel, InsertItemTreeModel.INSTANCE_SECTION);
        copyTree.setTreeModel(insertTreeModel);
        copyTree.addListener(this);
        cmc = new CloseableModalController(getWindowControl(), translate("close"), copyTree, true, translate("title.copy"));
        cmc.activate();
        listenTo(cmc);
       
      } 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());
                       
        // remove from tree model
        clickedNode.removeFromParent();
        qtiPackage.serializeQTIDocument();
        menuTree.setSelectedNodeId(clickedNode.getParent().getIdent());
        event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
        //ask user to confirm referenced media removal
        if(deletableMediaFiles!=null && deletableMediaFiles.size()>0) {         
          String msg = translate("delete.item.media", deletableMediaFiles.toString());
          deleteMediaDialog = activateYesNoDialog(ureq, null, msg, deleteMediaDialog);
        }   
      }
      // cleanup controller
      removeAsListenerAndDispose(deleteDialog);
      deleteDialog = null;
   
    } else if (source == deleteMediaDialog) { // event from deleteMediaDialog
      if (DialogBoxUIFactory.isYesEvent(event)) { // yes, delete         
        qtiPackage.removeMediaFiles(deletableMediaFiles);
        deleteMediaDialog = null;
        deletableMediaFiles = null;
      }
    } else if (event instanceof NodeBeforeChangeEvent) {
      NodeBeforeChangeEvent nce = (NodeBeforeChangeEvent) event;
      // active node changed some data
      String activeQtiNodeId = menuTree.getSelectedNodeId();
      GenericQtiNode activeQtiNode = menuTreeModel.getQtiNode(activeQtiNodeId);
      menuTree.setDirty(true); //force rerendering for ajax mode
      /*
       * mementos are only created in restricted mode
       */
      if (isRestrictedEdit()) {
        String key = nce.getSectionIdent() + "/" + nce.getItemIdent() + "/" + nce.getQuestionIdent() + "/" + nce.getResponseIdent();
        if (!history.containsKey(key)) {
          Memento memento = activeQtiNode.createMemento();
          history.put(key, memento);
          qtiPackage.serializeChangelog(history);
        }
      }

      /*
       * generate a Memento, store it for further use
       */
      if (nce.hasNewTitle) {
        // update the treemodel to reflect the change of the underlying qti node
        activeQtiNode.setMenuTitleAndAlt(nce.getNewTitle());
        main.contextPut("qtititle", menuTreeModel.getQtiRootNode().getAltText());
      }
    } else if (source == proceedRestricedEditDialog) {
      // restricted edit warning
      if (event == DialogController.EVENT_FIRSTBUTTON) {
View Full Code Here

TOP

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

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.