use of com.biglybt.ui.swt.views.utils.ManagerUtils.ArchiveCallback in project BiglyBT by BiglySoftware.
the class SBC_ArchivedDownloadsView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
List<Object> ds = tv.getSelectedDataSources();
final List<DownloadStub> dms = new ArrayList<>(ds.size());
for (Object o : ds) {
dms.add((DownloadStub) o);
}
boolean hasSelection = dms.size() > 0;
// Explore (or open containing folder)
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
final MenuItem itemExplore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemExplore, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"));
itemExplore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
for (DownloadStub download : dms) {
ManagerUtils.open(new File(download.getSavePath()), use_open_containing_folder);
}
}
});
itemExplore.setEnabled(hasSelection);
new MenuItem(menu, SWT.SEPARATOR);
final MenuItem itemRestore = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRestore, "MyTorrentsView.menu.restore");
itemRestore.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.restoreFromArchive(dms, false, null);
}
});
itemRestore.setEnabled(hasSelection);
final MenuItem itemRestoreAnd = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(itemRestoreAnd, "MyTorrentsView.menu.restore.and");
itemRestoreAnd.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event event) {
ManagerUtils.restoreFromArchive(dms, false, new ArchiveCallback() {
private List<DownloadManager> targets = new ArrayList<>();
@Override
public void success(final DownloadStub source, final DownloadStub target) {
DownloadManager dm = PluginCoreUtils.unwrap((Download) target);
if (dm != null) {
targets.add(dm);
}
}
@Override
public void completed() {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
if (targets.size() == 0) {
return;
}
final Menu menu = new Menu(table_parent);
DownloadManager[] dm_list = targets.toArray(new DownloadManager[dms.size()]);
TorrentUtil.fillTorrentMenu(menu, dm_list, CoreFactory.getSingleton(), true, 0, tv);
menu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
}
@Override
public void menuHidden(MenuEvent e) {
Utils.execSWTThreadLater(1, new Runnable() {
@Override
public void run() {
menu.dispose();
}
});
}
});
menu.setVisible(true);
}
});
}
});
}
});
itemRestoreAnd.setEnabled(hasSelection);
new MenuItem(menu, SWT.SEPARATOR);
}
Aggregations