diff --git a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/action/MoveNodeAction.java b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/action/MoveNodeAction.java index 1933ad5..d53d93d 100644 --- a/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/action/MoveNodeAction.java +++ b/magnolia-ui-contentapp/src/main/java/info/magnolia/ui/contentapp/movedialog/action/MoveNodeAction.java @@ -47,6 +47,8 @@ import info.magnolia.ui.workbench.tree.MoveHandler; import info.magnolia.ui.workbench.tree.MoveLocation; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import javax.inject.Named; @@ -127,4 +129,17 @@ return getDefinition().getFailureMessage(); } + // Needs to be overridden for reverting the order for the MoveLocation.AFTER operation. + @Override + protected List getSortedItems(Comparator comparator) { + List sortedItems = super.getSortedItems(comparator); + // As in the method executeOnItem(JcrItemAdapter item) for each item singly the info.magnolia.jcr.util.NodeUtil.moveNodeAfter(Node, Node) is called for placing it after the target item, this reverts the order of the items implicit. + // The first item (1) is movedAfter the target, then the next item (2) is moved after the target -> the resulting order is target/[2, 1] and not the correct order of target/[1, 2] + // Therefore the items order must be reverted before executing the moveAfter logic on every item in the list. + if (getDefinition().getMoveLocation() == MoveLocation.AFTER) { + Collections.reverse(sortedItems); + } + return sortedItems; + } + }