int location = getCurrentLocation();
if (m_dragCategory) {
Assert.instanceOf(CategoryInfo.class, target);
Assert.isTrue(location == LOCATION_BEFORE || location == LOCATION_AFTER);
// prepare next category
CategoryInfo nextCategory;
{
List<CategoryInfo> categories = DeviceManager.getCategories();
int index = categories.indexOf(target);
if (location == LOCATION_BEFORE) {
nextCategory = categories.get(index);
} else {
nextCategory = GenericsUtils.getNextOrNull(categories, index);
}
}
// add commands
for (Object element : m_dragElements) {
CategoryInfo category = (CategoryInfo) element;
commands_add(new CategoryMoveCommand(category, nextCategory));
}
} else if (target instanceof CategoryInfo) {
Assert.isTrue(location == LOCATION_ON);
CategoryInfo targetCategory = (CategoryInfo) target;
for (Object element : m_dragElements) {
DeviceInfo device = (DeviceInfo) element;
commands_add(new DeviceMoveCommand(device, targetCategory, null));
}
} else {
DeviceInfo targetDevice = (DeviceInfo) target;
CategoryInfo targetCategory = targetDevice.getCategory();
// prepare next device
DeviceInfo nextDevice;
{
List<DeviceInfo> entries = targetCategory.getDevices();
int index = entries.indexOf(targetDevice);
if (location == LOCATION_BEFORE) {
nextDevice = entries.get(index);
} else {
nextDevice = GenericsUtils.getNextOrNull(entries, index);