Transferable transferable = info.getTransferable();
//source and destination are equals or the handler accepts different components
try{
JList.DropLocation dropLocation = (JList.DropLocation)info.getDropLocation();
int index = dropLocation.getIndex();
VisualListModel destModel = ((VisualListModel)((JVisualSelectionList)info.getComponent()).getModel());
TransferableData transferredData = (TransferableData)transferable.getTransferData(DnDSupportUtility.VISUAL_LIST_FLAVOR);
if(transferredData!=null){
VisualPageListItem[] dataList = transferredData.getDataList();
if(dataList!=null && dataList.length>0){
//drop at the end
if(index==-1){
addIndex = destModel.getSize();
}else{
//check limits
int listSize = destModel.getSize();
if(index>listSize || index<0){
addIndex=listSize;
}else{
addIndex = index;
}
}
retVal = true;
}
if(retVal){
Collection<VisualPageListItem> items = Arrays.asList(dataList);
//if moving to another component
if(info.getSourceDropActions()==COPY){
Vector<VisualPageListItem> newList = new Vector<VisualPageListItem>(items.size());
for(VisualPageListItem currItem : items){
newList.add((VisualPageListItem) currItem.clone());
}
items = newList;
}
destModel.addAllElements(addIndex, items);
}
}
}catch(Exception e){
retVal = false;
log.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),"Error during drag and drop."), e);