final IGuide sourceGuide = GlobalModel.SINGLETON.getSelectedGuide();
boolean isDraggingFinished = !(Boolean)evt.getNewValue();
if (isDraggingFinished && sourceGuide instanceof StandardGuide)
{
final DNDList source = DNDListContext.getSource();
IDNDObject object = DNDListContext.getObject();
int insertPosition = source.getInsertPosition();
final Object[] feedsI = object.getItems();
StandardGuide guide = (StandardGuide)sourceGuide;
if (feedsList.isDraggingInternal())
{
final GuideModel model = (GuideModel)feedsList.getModel();
// Dragging operation finished within the same list
final IFeed currentSelection = GlobalModel.SINGLETON.getSelectedFeed();
int index = insertPosition;
for (int i = 0; i < feedsI.length; i++)
{
IFeed feed = (IFeed)feedsI[feedsI.length - i - 1];
int currentIndex = model.indexOf(feed);
if (currentIndex < index) index--;
GlobalController.SINGLETON.moveFeed(feed, guide, guide, index);
}
// We call it in new EDT task as the model will be updated
// in the next event only, so we have to schedule ourselves
// after that update to get correct indexes.
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
int curSelNewIndex = model.indexOf(currentSelection);
boolean curSelIsOnTheList = false;
int[] newIndices = new int[feedsI.length];
for (int i = 0; i < feedsI.length; i++)
{
newIndices[i] = model.indexOf((IFeed)feedsI[i]);
curSelIsOnTheList |= newIndices[i] == curSelNewIndex;
}
ListSelectionModel selModel = source.getSelectionModel();
if (!curSelIsOnTheList)
{
selModel.setSelectionInterval(curSelNewIndex, curSelNewIndex);
} else
{
source.setSelectedIndices(newIndices);
}
selModel.setLeadSelectionIndex(curSelNewIndex);
// Return focus to the guide