|| itemId.equals(itemIdOver)) {
return; // no move happened
}
// IndexedContainer goodies... (hint: don't use it in real apps)
IndexedContainer containerDataSource = (IndexedContainer) table
.getContainerDataSource();
int newIndex = containerDataSource.indexOfId(itemIdOver) - 1;
// always add after
newIndex++;
if (newIndex < 0) {
newIndex = 0;
}
Object idAfter = containerDataSource.getIdByIndex(newIndex);
Collection<?> selections = (Collection<?>) table.getValue();
if (selections != null && selections.contains(itemId)) {
// dragged a selected item, if multiple rows selected, drag
// them too (functionality similar to apple mail)
for (Object object : selections) {
moveAfter(containerDataSource, object, idAfter);
}
} else {
// move just the dragged row, not considering selection at
// all
moveAfter(containerDataSource, itemId, idAfter);
}
}
private void moveAfter(IndexedContainer containerDataSource,
Object itemId, Object idAfter) {
try {
IndexedContainer clone = null;
clone = (IndexedContainer) containerDataSource.clone();
containerDataSource.removeItem(itemId);
Item newItem = containerDataSource.addItemAfter(idAfter,
itemId);
Item item = clone.getItem(itemId);
for (Object propId : item.getItemPropertyIds()) {
newItem.getItemProperty(propId).setValue(
item.getItemProperty(propId).getValue());
}