Package org.olat.course.tree

Examples of org.olat.course.tree.TreePosition


    if (source == insertTree) {
      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 = insertModel.getTreePosition(nodeId);
        CourseNode selectedNode = insertModel.getCourseNode(tp.getParentTreeNode());
        CourseEditorTreeNode insertParent = course.getEditorTreeModel().getCourseEditorNodeById(selectedNode.getIdent());

        // check if insert position is within the to-be-copied tree
        if (checkIfIsChild(insertParent, moveCopyFrom)) {         
          this.showError("movecopynode.error.overlap");
          fireEvent(ureq, Event.CANCELLED_EVENT);
          return;
        }

        int insertPos = tp.getChildpos();
        if (copy) { // do a copy
          // copy subtree and save model
          recursiveCopy(moveCopyFrom, insertParent, insertPos, true, CourseFactory.getCourseEditSession(ores.getResourceableId()));         
          CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
View Full Code Here


      if (parentInstance == appendToInstancesOf) { // add insert pos
        GenericTreeNode gtn = new GenericTreeNode();
        gtn.setAccessible(true);
        gtn.setTitle("");
        gtn.setAltText("");
        gtn.setUserObject(new TreePosition(parent, i));
        ctn.addChild(gtn);
      }
      // add child itself
      GenericQtiNode cchild = (GenericQtiNode) parent.getChildAt(i);
      TreeNode ctchild = buildNode(cchild);
      ctn.addChild(ctchild);
    }
    if (parentInstance == appendToInstancesOf) {
      // add last insert position
      GenericTreeNode gtn = new GenericTreeNode();
      gtn.setAccessible(true);
      gtn.setTitle("");
      gtn.setAltText("");
      gtn.setUserObject(new TreePosition(parent, childcnt));
      ctn.addChild(gtn);
    }
    return ctn;
  }
View Full Code Here

   * @return TreePosition
   */
  public TreePosition getTreePosition(String nodeId) {
    TreeNode n = getNodeById(nodeId);
    GenericTreeNode gtn = (GenericTreeNode) n;
    TreePosition tp = (TreePosition) gtn.getUserObject();
    return tp;
  }
View Full Code Here

      TreeEvent te = (TreeEvent) event;
      if (te.getCommand().equals(TreeEvent.COMMAND_TREENODE_CLICKED)) {
        ICourse course = CourseFactory.getCourseEditSession(ores.getResourceableId());
        // user chose a position to insert a new node
        String nodeId = te.getNodeId();
        TreePosition tp = insertModel.getTreePosition(nodeId);
        int pos = tp.getChildpos();
        CourseNodeConfiguration newNodeConfig = CourseNodeFactory.getInstance().getCourseNodeConfiguration(type);
        insertedNode = newNodeConfig.getInstance();

        // Set some default values
        ///// START Special inline translation case: disable inline translation rendering (generates too long titles)
        I18nManager i18nMgr = I18nManager.getInstance();
        boolean isInlineTrans = i18nMgr.isCurrentThreadMarkLocalizedStringsEnabled();
        if (isInlineTrans) {
          i18nMgr.setMarkLocalizedStringsEnabled(ureq.getUserSession(), false);
        }
        //--
        String title = new String(newNodeConfig.getLinkText(ureq.getLocale()));
        insertedNode.setShortTitle(title);
        String longTitle = new String(translate("longtitle.default") + " " + title);
        insertedNode.setLongTitle(longTitle);
        insertedNode.setNoAccessExplanation(translate("form.noAccessExplanation.default"));
        //--
        if (isInlineTrans) {
          i18nMgr.setMarkLocalizedStringsEnabled(ureq.getUserSession(), true);
        }
        ///// END Special inline translation case
       
        // Insert it now
        CourseNode selectedNode = insertModel.getCourseNode(tp.getParentTreeNode());
        course.getEditorTreeModel().insertCourseNodeAt(insertedNode, selectedNode, pos);       
        CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());

        fireEvent(ureq, Event.DONE_EVENT);
      } else {
View Full Code Here

     
      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

TOP

Related Classes of org.olat.course.tree.TreePosition

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.