use of com.revolsys.util.Reorderable in project com.revolsys.open by revolsys.
the class ListReorderableTransferHandler method importData.
@Override
public boolean importData(final TransferHandler.TransferSupport info) {
final JList target = (JList) info.getComponent();
final JList.DropLocation dropLocation = (JList.DropLocation) info.getDropLocation();
int dropIndex = dropLocation.getIndex();
final ListModel model = this.list.getModel();
final int max = model.getSize();
if (dropIndex < 0 || dropIndex > max) {
dropIndex = max;
}
target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
try {
final Transferable transferable = info.getTransferable();
final int[] indices = (int[]) transferable.getTransferData(this.localObjectFlavor);
if (indices.length > 0) {
final Reorderable reorderable = (Reorderable) model;
int currentIndex = dropIndex;
int count = 0;
for (int index : indices) {
if (count > 0) {
if (currentIndex > index) {
index -= count;
}
}
count++;
if (index == currentIndex) {
currentIndex++;
} else {
reorderable.reorder(index, currentIndex);
if (index > currentIndex) {
currentIndex++;
}
}
}
final ListSelectionModel selectionModel = target.getSelectionModel();
selectionModel.clearSelection();
selectionModel.addSelectionInterval(currentIndex - indices.length, currentIndex - 1);
return true;
}
} catch (final Throwable e) {
Logs.error(this, "Unexpected error", e);
}
return false;
}
use of com.revolsys.util.Reorderable in project com.revolsys.open by revolsys.
the class TableRowTransferHandler method importData.
@Override
public boolean importData(final TransferHandler.TransferSupport info) {
final JTable target = (JTable) info.getComponent();
final JTable.DropLocation dropLocation = (JTable.DropLocation) info.getDropLocation();
int index = dropLocation.getRow();
final TableModel model = this.table.getModel();
final int max = model.getRowCount();
if (index < 0 || index > max) {
index = max;
}
target.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
try {
final Transferable transferable = info.getTransferable();
final Integer rowFrom = (Integer) transferable.getTransferData(this.localObjectFlavor);
if (rowFrom != -1 && rowFrom != index) {
((Reorderable) model).reorder(rowFrom, index);
if (index > rowFrom) {
index--;
}
target.getSelectionModel().addSelectionInterval(index, index);
return true;
}
} catch (final Exception e) {
Logs.error(this, "Unexpected error", e);
}
return false;
}
Aggregations