// If allowed to drop only nodes or both, then we need to remove items from the list
// that also have their parents being dragged
ModelKeyProvider<? super M> kp = getWidget().getTreeStore().getKeyProvider();
// Start by looking for all selected non-leaf items
FastSet nonLeafKeys = new FastSet();
for (M item : selected) {
if (getWidget().isLeaf(item)) {
// While we're at it, if we're only allowed nodes, cancel if we see a leaf
if (treeGridSource == TreeSource.NODE) {
event.setCancelled(true);
return;
}
} else {
nonLeafKeys.add(kp.getKey(item));
}
}
// Walking backward (so we can remove as we go) through the list of all selected items, for
// each item, check if it has a parent already in the list.
// Clearly that parent is a non-leaf, so will be in the set we established in the last loop
for (int i = selected.size() - 1; i >= 0; i--) {
// TODO consider tracking these parents, and if they are part of another
// parent, adding them to the keyset
M parent = selected.get(i);
if (parent == null) { // EXTGWT-2692
selected.remove(i);
} else {
while ((parent = getWidget().getTreeStore().getParent(parent)) != null) {
// If we find that this item's parent is also selected, then we can skip this item
if (nonLeafKeys.contains(kp.getKey(parent))) {
selected.remove(i);
break;
}
}
}