Exemple #1
0
  // really do the move
  private boolean moveStructureToNewParent(
      final String subjectStructId,
      final String oldParStructId,
      final String newParStructId,
      int newPos) {
    PortfolioStructure structToBeMvd;
    PortfolioStructure oldParStruct;
    PortfolioStructure newParStruct;
    try {
      structToBeMvd = ePFMgr.loadPortfolioStructureByKey(new Long(subjectStructId));
      oldParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(oldParStructId));
      newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParStructId));
    } catch (final Exception e) {
      log.error(
          "could not load: structure to be moved, old or new structure while trying to move", e);
      return false;
    }

    if (oldParStructId.equals(newParStructId)) {
      // this is only a position move
      return ePFMgr.moveStructureToPosition(structToBeMvd, newPos);
    }

    return ePFMgr.moveStructureToNewParentStructure(
        structToBeMvd, oldParStruct, newParStruct, newPos);
  }
Exemple #2
0
  /**
   * check if a structure (page/structEl/map may be dropped here! its only allowed to move: -
   * StructureElement from page -> page - change the order of pages - change the order of structures
   *
   * @param subjectStructId
   * @param oldParStructId
   * @param newParStructId
   * @return
   */
  private boolean checkNewStructureTarget(
      final String subjectStructId, final String oldParStructId, final String newParStructId) {
    PortfolioStructure structToBeMvd;
    PortfolioStructure newParStruct;
    if (oldParStructId.equals(newParStructId)) return true; // seems only to be a move in order
    if (newParStructId.equals(ROOT_NODE_IDENTIFIER)) return false;
    try {
      structToBeMvd = ePFMgr.loadPortfolioStructureByKey(new Long(subjectStructId));
      newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParStructId));
    } catch (final Exception e) {
      log.error("could not check for valid structure target", e);
      return false;
    }
    if (structToBeMvd instanceof EPPage && newParStruct instanceof EPPage) return false;
    if (structToBeMvd instanceof EPStructureElement && !(newParStruct instanceof EPPage))
      return false;

    return true;
  }
Exemple #3
0
 // really do the move!
 private boolean moveArtefactToNewParent(
     final String artefactId, final String oldParentId, final String newParentId) {
   PortfolioStructure newParStruct;
   PortfolioStructure oldParStruct;
   AbstractArtefact artefact;
   try {
     artefact = ePFMgr.loadArtefactByKey(new Long(artefactId));
     oldParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(oldParentId));
     newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(newParentId));
   } catch (final Exception e) {
     log.error("could not load artefact, old and new parent", e);
     return false;
   }
   return ePFMgr.moveArtefactFromStructToStruct(artefact, oldParStruct, newParStruct);
 }
Exemple #4
0
 @SuppressWarnings("unused")
 @Override
 protected void event(final UserRequest ureq, final Component source, final Event event) {
   if (source instanceof Link) {
     final Link link = (Link) source;
     if (link.getCommand().equals(DELETE_LINK_CMD)) {
       if (artefactNodeClicked != null) {
         final AbstractArtefact artefact =
             ePFMgr.loadArtefactByKey(new Long(getArtefactIdFromNodeId(artefactNodeClicked)));
         final PortfolioStructure parentStruct =
             ePFMgr.loadPortfolioStructureByKey(
                 new Long(getArtefactParentStructIdFromNodeId(artefactNodeClicked)));
         ePFMgr.removeArtefactFromStructure(artefact, parentStruct);
         // refresh the view
         fireEvent(ureq, Event.CHANGED_EVENT);
       } else if (structureClicked != null) {
         if ((structureClicked instanceof EPPage)
             && !(structureClicked instanceof EPAbstractMap)) {
           PortfolioStructure ps = structureClicked;
           while (ePFMgr.loadStructureParent(ps) != null) {
             ps = ePFMgr.loadStructureParent(ps);
           }
           final int childPages = ePFMgr.countStructureChildren(ps);
           if (childPages > 1) {
             eSTMgr.removeStructureRecursively(structureClicked);
             // refresh the view
             fireEvent(ureq, Event.CHANGED_EVENT);
           } else {
             showError("last.page.not.deletable");
           }
         } else if (structureClicked instanceof EPStructureElement
             && !(structureClicked instanceof EPAbstractMap)) {
           // structures should always be deletable
           eSTMgr.removeStructureRecursively(structureClicked);
           // refresh the view
           fireEvent(ureq, Event.CHANGED_EVENT);
         } else {
           showInfo("element.not.deletable");
         }
       }
     }
   }
 }
Exemple #5
0
  /**
   * check if an artefact might be moved to this new parent node artefact might be moved to pages or
   * structureElements, but not on maps
   *
   * @param artefactId
   * @param structureId
   * @return
   */
  private boolean checkNewArtefactTarget(final String artefactId, final String structureId) {
    // artefact cannot be moved directly under root
    if (ROOT_NODE_IDENTIFIER.equals(structureId)) {
      return false;
    }

    PortfolioStructure newParStruct;
    AbstractArtefact artefact;
    try {
      artefact = ePFMgr.loadArtefactByKey(new Long(artefactId));
      newParStruct = ePFMgr.loadPortfolioStructureByKey(new Long(structureId));
    } catch (final Exception e) {
      log.warn("could not check for valid artefact target", e);
      return false;
    }
    final boolean sameTarget = ePFMgr.isArtefactInStructure(artefact, newParStruct);
    if (sameTarget) {
      return false;
    }
    if (newParStruct instanceof EPAbstractMap) {
      return false;
    }
    return true;
  }
Exemple #6
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);
   }
 }