Search in sources :

Example 1 with ArchiveCallback

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);
}
Also used : DownloadStubListener(com.biglybt.pif.download.DownloadStubListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) MenuListener(org.eclipse.swt.events.MenuListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) Listener(org.eclipse.swt.widgets.Listener) MenuListener(org.eclipse.swt.events.MenuListener) ArchiveCallback(com.biglybt.ui.swt.views.utils.ManagerUtils.ArchiveCallback) MenuItem(org.eclipse.swt.widgets.MenuItem) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadStub(com.biglybt.pif.download.DownloadStub) MenuEvent(org.eclipse.swt.events.MenuEvent) Event(org.eclipse.swt.widgets.Event) DownloadStubEvent(com.biglybt.pif.download.DownloadStubEvent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) Menu(org.eclipse.swt.widgets.Menu) File(java.io.File) DownloadStubFile(com.biglybt.pif.download.DownloadStub.DownloadStubFile) MenuEvent(org.eclipse.swt.events.MenuEvent)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadStub (com.biglybt.pif.download.DownloadStub)1 DownloadStubFile (com.biglybt.pif.download.DownloadStub.DownloadStubFile)1 DownloadStubEvent (com.biglybt.pif.download.DownloadStubEvent)1 DownloadStubListener (com.biglybt.pif.download.DownloadStubListener)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)1 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)1 TableViewSWTMenuFillListener (com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener)1 ArchiveCallback (com.biglybt.ui.swt.views.utils.ManagerUtils.ArchiveCallback)1 File (java.io.File)1 MenuEvent (org.eclipse.swt.events.MenuEvent)1 MenuListener (org.eclipse.swt.events.MenuListener)1 Event (org.eclipse.swt.widgets.Event)1 Listener (org.eclipse.swt.widgets.Listener)1 Menu (org.eclipse.swt.widgets.Menu)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1