private void moveSelectedTracklistingItems(final JList list, final int direction) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
DiscogsDefaultListModel listModel = (DiscogsDefaultListModel) list.getModel();
ListSelectionModel lsm = list.getSelectionModel();
int indexStart = list.getSelectedIndices()[0];
int indexEnd = list.getSelectedIndices()[list.getSelectedIndices().length - 1];
int indexObj;
Object obj;
if (direction < 0) {
indexObj = indexStart - 1;
obj = listModel.getEx(indexObj);
listModel.remove(indexObj);
if (listModel.size() == indexEnd) {
listModel.addElement(obj);
}
else {
listModel.add(indexEnd, obj);
}
lsm.setSelectionInterval(indexStart - 1, indexEnd - 1);
}
else if (direction > 0) {
indexObj = indexEnd + 1;
obj = listModel.getEx(indexObj);
listModel.remove(indexObj);
listModel.add(indexStart, obj);
lsm.setSelectionInterval(indexStart + 1, indexEnd + 1);
}
}
});
}