示例#1
0
 private String calculatePathByDeepestNode(final PortfolioStructure pStruct) {
   final StringBuffer path = new StringBuffer();
   PortfolioStructure ps = pStruct;
   while (ps.getRootMap() != null) {
     path.insert(0, "/" + ps.getKey().toString());
     ps = ps.getRoot();
   }
   return path.toString();
 }
示例#2
0
 public void update(UserRequest ureq, final PortfolioStructure structure) {
   final String path = idToPath.get(structure.getKey());
   if (path != null) {
     treeCtr.reloadPath(path);
     treeCtr.selectPath(path);
   }
   refreshAddElements(ureq, structure);
 }
 public static void setReference(
     final RepositoryEntry repoEntry,
     final PortfolioStructure map,
     final ModuleConfiguration moduleConfig) {
   moduleConfig.set(PortfolioCourseNodeConfiguration.MAP_KEY, map.getKey());
   if (repoEntry != null && repoEntry.getSoftkey() != null) {
     moduleConfig.set(PortfolioCourseNodeConfiguration.REPO_SOFT_KEY, repoEntry.getSoftkey());
   }
 }
示例#4
0
  public EPTOCController(
      final UserRequest ureq,
      final WindowControl wControl,
      final PortfolioStructure selectedEl,
      final PortfolioStructure rootNode,
      final EPSecurityCallback secCallback) {
    super(ureq, wControl);
    this.secCallback = secCallback;
    tocV = createVelocityContainer("toc");
    ePFMgr = (EPFrontendManager) CoreSpringFactory.getBean(EPFrontendManager.class);
    eSTMgr = (PortfolioStructureDao) CoreSpringFactory.getBean(PortfolioStructureDao.class);
    this.rootNode = rootNode;
    final AjaxTreeModel treeModel = buildTreeModel();
    treeCtr =
        new TreeController(
            ureq, getWindowControl(), translate("toc.root"), treeModel, "myjsCallback");
    treeCtr.setTreeSorting(false, false, false);
    listenTo(treeCtr);
    tocV.put("tocTree", treeCtr.getInitialComponent());
    delButton =
        LinkFactory.createCustomLink(
            "deleteButton", DELETE_LINK_CMD, "   ", Link.NONTRANSLATED, tocV, this);
    delButton.setTooltip(translate("deleteButton"), false);
    delButton.setCustomEnabledLinkCSS("b_delete_icon b_eportfolio_del_link ");
    tocV.put("deleteButton", delButton);

    if (selectedEl == null) {
      treeCtr.selectPath("/" + ROOT_NODE_IDENTIFIER + "/" + rootNode.getKey()); // select map
      refreshAddElements(ureq, rootNode);
    } else {
      final String pagePath = calculatePathByDeepestNode(selectedEl);
      treeCtr.selectPath("/" + ROOT_NODE_IDENTIFIER + "/" + rootNode.getKey() + pagePath);
      structureClicked = selectedEl;
      refreshAddElements(ureq, selectedEl);
    }

    putInitialPanel(tocV);
  }
示例#5
0
 @Override
 protected void event(final UserRequest ureq, final Controller source, final Event event) {
   if (event instanceof TreeNodeClickedEvent) {
     resetClickedNodes();
     final TreeNodeClickedEvent treeEv = (TreeNodeClickedEvent) event;
     final String nodeClicked = treeEv.getNodeId();
     final boolean isArtefactNode = nodeClicked.startsWith(ARTEFACT_NODE_IDENTIFIER);
     if (!nodeClicked.equals(ROOT_NODE_IDENTIFIER) && !isArtefactNode) {
       structureClicked = ePFMgr.loadPortfolioStructureByKey(new Long(nodeClicked));
       refreshAddElements(ureq, structureClicked);
       delButton.setVisible(true);
       // send event to load this page
       fireEvent(
           ureq, new EPStructureChangeEvent(EPStructureChangeEvent.SELECTED, structureClicked));
       // needed because refreshAddElements set flc dirty, therefore selected node gets lost
       final String path = idToPath.get(structureClicked.getKey());
       treeCtr.selectPath(path);
     } else if (isArtefactNode) {
       artefactNodeClicked = nodeClicked;
       refreshAddElements(ureq, null);
       delButton.setVisible(true);
       final String artIdent = getArtefactIdFromNodeId(nodeClicked);
       final String path = idToPath.get(new Long(artIdent));
       final PortfolioStructure structure = pathToStructure.get(path);
       fireEvent(ureq, new EPArtefactClicked(ARTEFACT_NODE_CLICKED, structure));
       // needed because refreshAddElements set flc dirty, therefore selected node gets lost
       treeCtr.selectPath(path);
     } else {
       // root tree node clicked, no add/delete link
       delButton.setVisible(false);
       refreshAddElements(ureq, null);
       fireEvent(ureq, new Event(ARTEFACT_NODE_CLICKED));
     }
   } else if (event instanceof MoveTreeNodeEvent) {
     resetClickedNodes();
     final MoveTreeNodeEvent moveEvent = (MoveTreeNodeEvent) event;
     final String movedNode = moveEvent.getNodeId();
     final String oldParent = moveEvent.getOldParentNodeId();
     final String newParent = moveEvent.getNewParentNodeId();
     int newPos = moveEvent.getPosition();
     final boolean isArtefactNode = movedNode.startsWith(ARTEFACT_NODE_IDENTIFIER);
     if (isArtefactNode) {
       final String nodeId = getArtefactIdFromNodeId(movedNode);
       if (checkNewArtefactTarget(nodeId, newParent)) {
         if (moveArtefactToNewParent(nodeId, oldParent, newParent)) {
           if (log.isDebugEnabled()) {
             log.info(
                 "moved artefact " + nodeId + " from structure " + oldParent + " to " + newParent,
                 null);
           }
           moveEvent.setResult(true, null, null);
           // refresh the view
           final EPMoveEvent movedEvent = new EPMoveEvent(newParent, nodeId);
           fireEvent(ureq, movedEvent);
         } else {
           moveEvent.setResult(
               false, translate("move.error.title"), translate("move.artefact.error.move"));
         }
       } else {
         moveEvent.setResult(
             false, translate("move.error.title"), translate("move.artefact.error.target"));
       }
     } else {
       if (checkNewStructureTarget(movedNode, oldParent, newParent)) {
         if (moveStructureToNewParent(movedNode, oldParent, newParent, newPos)) {
           if (log.isDebugEnabled()) {
             log.debug(
                 "moved structure "
                     + movedNode
                     + " from structure "
                     + oldParent
                     + " to "
                     + newParent,
                 null);
           }
           moveEvent.setResult(true, null, null);
           // refresh the view
           final EPMoveEvent movedEvent = new EPMoveEvent(newParent, movedNode);
           fireEvent(ureq, movedEvent);
         } else {
           moveEvent.setResult(
               false, translate("move.error.title"), translate("move.struct.error.move"));
         }
       } else {
         moveEvent.setResult(
             false, translate("move.error.title"), translate("move.struct.error.target"));
       }
     }
   } else if (source == addElCtrl) {
     // refresh the view, this is a EPStructureChangeEvent
     fireEvent(ureq, event);
   }
 }
示例#6
0
  private AjaxTreeModel buildTreeModel() {
    idToPath.put(rootNode.getKey(), "/" + ROOT_NODE_IDENTIFIER);

    final AjaxTreeModel model =
        new AjaxTreeModel(ROOT_NODE_IDENTIFIER) {

          @Override
          public List<AjaxTreeNode> getChildrenFor(final String nodeId) {
            final List<AjaxTreeNode> children = new ArrayList<AjaxTreeNode>();
            AjaxTreeNode child;
            boolean isRoot = false;
            PortfolioStructure selStruct = null;
            try {
              List<PortfolioStructure> structs = new ArrayList<PortfolioStructure>();
              if (nodeId.equals(ROOT_NODE_IDENTIFIER)) {
                structs.add(rootNode);
                isRoot = true;
              } else if (!nodeId.startsWith(ARTEFACT_NODE_IDENTIFIER)) {
                selStruct = ePFMgr.loadPortfolioStructureByKey(new Long(nodeId));
                structs = ePFMgr.loadStructureChildren(selStruct);
              } else {
                // its an artefact -> no childs anymore
                return null;
              }
              if (structs != null && structs.size() != 0) {
                for (final PortfolioStructure portfolioStructure : structs) {
                  final String childNodeId = String.valueOf(portfolioStructure.getKey());
                  final boolean hasStructureChild =
                      eSTMgr.countStructureChildren(portfolioStructure) > 0;
                  final boolean hasArtefacts = eSTMgr.countArtefacts(portfolioStructure) > 0;
                  final boolean hasChilds = hasStructureChild || hasArtefacts;
                  child = new AjaxTreeNode(childNodeId, portfolioStructure.getTitle());
                  if (log.isDebugEnabled()) {
                    child =
                        new AjaxTreeNode(
                            childNodeId,
                            portfolioStructure.getTitle()
                                + "drop:"
                                + !isRoot
                                + "drag:"
                                + !isRoot
                                + "leaf:"
                                + !hasChilds);
                  }
                  // seems to be a bug, nothing can be dropped on a leaf, therefore we need to tweak
                  // with expanded/expandable ourself!
                  // child.put(AjaxTreeNode.CONF_LEAF, !hasChilds);
                  child.put(AjaxTreeNode.CONF_IS_TYPE_LEAF, !hasChilds);
                  child.put(AjaxTreeNode.CONF_ALLOWDRAG, !isRoot);

                  child.put(AjaxTreeNode.CONF_EXPANDED, hasStructureChild);
                  child.put(AjaxTreeNode.CONF_EXPANDABLE, hasChilds);
                  child.put(AjaxTreeNode.CONF_ALLOWDROP, true);
                  child.put(AjaxTreeNode.CONF_ISTARGET, !isRoot);

                  child.put(AjaxTreeNode.CONF_ICON_CSS_CLASS, portfolioStructure.getIcon());
                  final String description =
                      FilterFactory.getHtmlTagAndDescapingFilter()
                          .filter(portfolioStructure.getDescription());
                  child.put(AjaxTreeNode.CONF_QTIP, description);
                  children.add(child);

                  String path;
                  if (isRoot) {
                    path = "/" + ROOT_NODE_IDENTIFIER;
                  } else {
                    path = idToPath.get(selStruct.getKey());
                  }

                  idToPath.put(portfolioStructure.getKey(), path + "/" + childNodeId);
                }
              }
              if (selStruct != null && ePFMgr.countArtefactsRecursively(selStruct) != 0) {
                final List<AbstractArtefact> artList = ePFMgr.getArtefacts(selStruct);
                for (final AbstractArtefact abstractArtefact : artList) {
                  // include struct also, to still be unique if an artefact is linked multiple times
                  final String childNodeId =
                      ARTEFACT_NODE_IDENTIFIER
                          + String.valueOf(selStruct.getKey())
                          + "_"
                          + String.valueOf(abstractArtefact.getKey());
                  child = new AjaxTreeNode(childNodeId, abstractArtefact.getTitle());
                  child.put(AjaxTreeNode.CONF_LEAF, true);
                  child.put(AjaxTreeNode.CONF_IS_TYPE_LEAF, true);
                  child.put(AjaxTreeNode.CONF_ALLOWDRAG, true);
                  child.put(AjaxTreeNode.CONF_EXPANDED, false);
                  child.put(AjaxTreeNode.CONF_ALLOWDROP, false);
                  child.put(AjaxTreeNode.CONF_ICON_CSS_CLASS, getArtefactHandler(abstractArtefact));
                  final String description =
                      FilterFactory.getHtmlTagAndDescapingFilter()
                          .filter(abstractArtefact.getDescription());
                  child.put(AjaxTreeNode.CONF_QTIP, description);
                  children.add(child);

                  final String path = idToPath.get(selStruct.getKey());

                  final String artefactPath = path + "/" + childNodeId;
                  idToPath.put(abstractArtefact.getKey(), artefactPath);
                  pathToStructure.put(artefactPath, selStruct);
                }
              }
            } catch (final JSONException e) {
              throw new OLATRuntimeException(
                  "Error while creating tree model for map/page/structure selection", e);
            }
            return children;
          }
        };
    model.setCustomRootIconCssClass("o_st_icon");
    return model;
  }
示例#7
0
 protected void refreshTree(final PortfolioStructure root) {
   this.rootNode = root;
   treeCtr.reloadPath("/" + ROOT_NODE_IDENTIFIER + "/" + rootNode.getKey());
 }