final ListModel lm = list.getModel();
if (!(lm instanceof ChangeListModel)) {
return false;
}
final ChangeListModel listModel = (ChangeListModel) lm;
final DataFlavor flavor = new ListMoveDataFlavor(listModel);
if (!info.isDataFlavorSupported(flavor)) {
return false;
}
final Transferable transferable = info.getTransferable();
try {
final ListMoveTransferData data =
(ListMoveTransferData) transferable.getTransferData(flavor);
// get the initial insertion index
final JList.DropLocation dropLocation = list.getDropLocation();
int insertAt = dropLocation.getIndex();
// get the indices sorted (we use them in reverse order, below)
final int[] indices = data.getIndices();
PolicyModel p = (PolicyModel) lm.getElementAt(indices[0]);
Arrays.sort(indices);
// remove old elements from model, store them on stack
final Stack<Object> elements = new Stack<Object>();
int shift = 0;
for (int i = indices.length - 1; i >= 0; i--) {
final int index = indices[i];
if (index < insertAt) {
shift--;
}
elements.push(listModel.remove(index));
}
insertAt += shift;
// insert stored elements from stack to model
final ListSelectionModel sm = list.getSelectionModel();
try {
sm.setValueIsAdjusting(true);
sm.clearSelection();
final int anchor = insertAt;
while (!elements.isEmpty()) {
listModel.insertElementAt(elements.pop(), insertAt);
sm.addSelectionInterval(insertAt, insertAt++);
}
final int lead = insertAt - 1;
if (!sm.isSelectionEmpty()) {
sm.setAnchorSelectionIndex(anchor);
sm.setLeadSelectionIndex(lead);
}
} finally {
// richtige Selection setzen
list.setSelectedValue(p, true);
int index = list.getSelectedIndex();
sm.setSelectionInterval(index, index);
sm.setValueIsAdjusting(false);
// Ränge neu ordnen
List<PolicyModel> policies = new ArrayList();
for (int i = 0; i < listModel.size(); i++) {
policies.add((PolicyModel) listModel.get(i));
}
PolicyUtilities.setPolicyRanks(policies, true);
}
return true;
} catch (UnsupportedFlavorException ex) {