IFolder parentFolder = null;
boolean requireSave = false;
boolean on = (location == ViewerDropAdapter.LOCATION_ON);
IFolderChild position = dropTarget != null ? (IFolderChild) dropTarget : null;
/* Fix invalid Position */
if (on && dropTarget instanceof IFolder)
position = null;
Boolean after = (location == ViewerDropAdapter.LOCATION_AFTER);
if (position == null)
after = null;
/* Target is a Folder */
if (dropTarget instanceof IFolder) {
IFolder dropFolder = (IFolder) dropTarget;
/* Target is the exact Folder */
if (on)
parentFolder = (IFolder) dropTarget;
/* Target is below or above of the Folder */
else
parentFolder = dropFolder.getParent();
}
/* Target is a Mark */
else if (dropTarget instanceof IMark) {
IMark dropMark = (IMark) dropTarget;
parentFolder = dropMark.getParent();
}
/* Require a Parent-Folder */
if (parentFolder == null)
return;
/* Separate into Reparented FolderChildren and Re-Orders */
List<IFolderChild> childReordering = null;
List<ReparentInfo<IFolderChild, IFolder>> reparenting = null;
/* For each dragged Object */
for (Object object : draggedObjects) {
/* Dragged Folder or Mark */
if (object instanceof IFolder || object instanceof IMark) {
IFolderChild draggedFolderChild = (IFolderChild) object;
/* Reparenting to new Parent */
if (!draggedFolderChild.getParent().equals(parentFolder)) {
if (reparenting == null)
reparenting = new ArrayList<ReparentInfo<IFolderChild, IFolder>>(draggedObjects.size());
ReparentInfo<IFolderChild, IFolder> reparentInfo = ReparentInfo.create(draggedFolderChild, parentFolder, position, after);
reparenting.add(reparentInfo);