boolean onlyDMs = true;
StringBuffer sb = new StringBuffer();
Object[] selectedDataSources = tv.getSelectedDataSources(true);
for (Object ds : selectedDataSources) {
if (ds instanceof DownloadManager) {
DownloadManager dm = (DownloadManager) ds;
TOTorrent torrent = dm.getTorrent();
if (torrent != null) {
try {
sb.append(torrent.getHashWrapper().toBase32String());
sb.append('\n');
} catch (TOTorrentException e) {
}
}
} else if (ds instanceof DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (DiskManagerFileInfo) ds;
DownloadManager dm = fileInfo.getDownloadManager();
TOTorrent torrent = dm.getTorrent();
if (torrent != null) {
try {
sb.append(torrent.getHashWrapper().toBase32String());
sb.append(';');
sb.append(fileInfo.getIndex());
sb.append('\n');
onlyDMs = false;
} catch (TOTorrentException e) {
}
}
}
}
eventData = (onlyDMs ? "DownloadManager\n" : "DiskManagerFileInfo\n") + sb.toString();
}
public void dragSetData(DragSourceEvent event) {
// System.out.println("DragSetData");
event.data = eventData;
}
});
}
dropTarget = tv.createDropTarget(DND.DROP_DEFAULT | DND.DROP_MOVE
| DND.DROP_COPY | DND.DROP_LINK | DND.DROP_TARGET_MOVE);
if (dropTarget != null) {
dropTarget.setTransfer(new Transfer[] { HTMLTransfer.getInstance(),
URLTransfer.getInstance(), FileTransfer.getInstance(),
TextTransfer.getInstance() });
dropTarget.addDropListener(new DropTargetAdapter() {
Point enterPoint = null;
public void dropAccept(DropTargetEvent event) {
event.currentDataType = URLTransfer.pickBestType(event.dataTypes,
event.currentDataType);
}
public void dragEnter(DropTargetEvent event) {
// no event.data on dragOver, use drag_drop_line_start to determine
// if ours
if (drag_drop_line_start < 0) {
if (event.detail != DND.DROP_COPY) {
if ((event.operations & DND.DROP_LINK) > 0)
event.detail = DND.DROP_LINK;
else if ((event.operations & DND.DROP_COPY) > 0)
event.detail = DND.DROP_COPY;
}
} else if (TextTransfer.getInstance().isSupportedType(
event.currentDataType)) {
event.detail = event.item == null ? DND.DROP_NONE : DND.DROP_MOVE;
event.feedback = DND.FEEDBACK_SCROLL;
enterPoint = new Point(event.x, event.y);
}
}
public void dragOver(DropTargetEvent event) {
if (drag_drop_line_start >= 0) {
if (drag_drop_rows.length > 0
&& !(drag_drop_rows[0].getDataSource(true) instanceof DownloadManager)) {
event.detail = DND.DROP_NONE;
return;
}
event.detail = event.item == null ? DND.DROP_NONE : DND.DROP_MOVE;
event.feedback = DND.FEEDBACK_SCROLL
| ((enterPoint != null && enterPoint.y > event.y)
? DND.FEEDBACK_INSERT_BEFORE : DND.FEEDBACK_INSERT_AFTER);
}
}
public void drop(DropTargetEvent event) {
if (!(event.data instanceof String)) {
TorrentOpener.openDroppedTorrents(event, true);
return;
}
String data = (String) event.data;
if (data.startsWith("DiskManagerFileInfo\n")) {
return;
}
if (!data.startsWith("DownloadManager\n")) {
TorrentOpener.openDroppedTorrents(event, true);
return;
}
event.detail = DND.DROP_NONE;
// Torrent file from shell dropped
if (drag_drop_line_start >= 0) { // event.data == null
event.detail = DND.DROP_NONE;
TableRowCore row = tv.getRow(event);
if (row == null)
return;
if (row.getParentRowCore() != null) {
row = row.getParentRowCore();
}
int drag_drop_line_end = row.getIndex();
if (drag_drop_line_end != drag_drop_line_start) {
DownloadManager dm = (DownloadManager) row.getDataSource(true);
moveRowsTo(drag_drop_rows, dm.getPosition());
event.detail = DND.DROP_MOVE;
}
drag_drop_line_start = -1;
drag_drop_rows = null;
}