Search in sources :

Example 1 with TableSelectedRowsListener

use of com.biglybt.ui.swt.views.table.TableSelectedRowsListener in project BiglyBT by BiglySoftware.

the class TrackerView method fillMenu.

@Override
public void fillMenu(String sColumnName, Menu menu) {
    final Object[] sources = tv.getSelectedDataSources().toArray();
    boolean found_tracker = false;
    boolean found_dht_tracker = false;
    boolean update_ok = false;
    boolean delete_ok = false;
    for (Object o : sources) {
        TrackerPeerSource ps = (TrackerPeerSource) o;
        if (ps.getType() == TrackerPeerSource.TP_TRACKER) {
            found_tracker = true;
        }
        if (ps.getType() == TrackerPeerSource.TP_DHT) {
            found_dht_tracker = true;
        }
        int state = ps.getStatus();
        if ((state == TrackerPeerSource.ST_ONLINE || state == TrackerPeerSource.ST_QUEUED || state == TrackerPeerSource.ST_ERROR) && !ps.isUpdating() && ps.canManuallyUpdate()) {
            update_ok = true;
        }
        if (ps.canDelete()) {
            delete_ok = true;
        }
    }
    boolean needs_sep = false;
    if (found_tracker || found_dht_tracker) {
        final MenuItem update_item = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(update_item, "GeneralView.label.trackerurlupdate");
        update_item.setEnabled(update_ok);
        update_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {

            @Override
            public void run(TableRowCore row) {
                for (Object o : sources) {
                    TrackerPeerSource ps = (TrackerPeerSource) o;
                    if (ps.canManuallyUpdate()) {
                        ps.manualUpdate();
                    }
                }
            }
        });
        if (found_tracker) {
            final MenuItem edit_item = new MenuItem(menu, SWT.PUSH);
            Messages.setLanguageText(edit_item, "MyTorrentsView.menu.editTracker");
            edit_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {

                @Override
                public boolean run(TableRowCore[] rows) {
                    final TOTorrent torrent = manager.getTorrent();
                    if (torrent != null) {
                        Utils.execSWTThread(new Runnable() {

                            @Override
                            public void run() {
                                List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
                                new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {

                                    @Override
                                    public void trackersChanged(String str, String str2, List<List<String>> _group) {
                                        TorrentUtils.listToAnnounceGroups(_group, torrent);
                                        try {
                                            TorrentUtils.writeToFile(torrent);
                                        } catch (Throwable e2) {
                                            Debug.printStackTrace(e2);
                                        }
                                        TRTrackerAnnouncer tc = manager.getTrackerClient();
                                        if (tc != null) {
                                            tc.resetTrackerUrl(true);
                                        }
                                    }
                                }, true, true);
                            }
                        });
                    }
                    return (true);
                }
            });
            TOTorrent torrent = manager.getTorrent();
            edit_item.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
        }
        needs_sep = true;
    }
    if (delete_ok) {
        final MenuItem delete_item = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(delete_item, "Button.remove");
        Utils.setMenuItemImage(delete_item, "delete");
        delete_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {

            @Override
            public void run(TableRowCore row) {
                for (Object o : sources) {
                    TrackerPeerSource ps = (TrackerPeerSource) o;
                    if (ps.canDelete()) {
                        ps.delete();
                    }
                }
            }
        });
        needs_sep = true;
    }
    if (needs_sep) {
        new MenuItem(menu, SWT.SEPARATOR);
    }
}
Also used : TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuItem(org.eclipse.swt.widgets.MenuItem) MultiTrackerEditor(com.biglybt.ui.swt.maketorrent.MultiTrackerEditor) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) AERunnable(com.biglybt.core.util.AERunnable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with TableSelectedRowsListener

use of com.biglybt.ui.swt.views.table.TableSelectedRowsListener in project BiglyBT by BiglySoftware.

the class TorrentMenuFancy method addPluginItem.

private void addPluginItem(Composite detailArea, final com.biglybt.pif.ui.menus.MenuItem item) {
    // menuWillBeShown listeners might change the visibility, so run before check
    MenuItemImpl menuImpl = ((MenuItemImpl) item);
    menuImpl.invokeMenuWillBeShownListeners(getTarget(item));
    if (!item.isVisible()) {
        if (DEBUG_MENU) {
            System.out.println("Menu Not Visible: " + item.getText() + ": " + item.getMenuID());
        }
        return;
    }
    Graphic graphic = item.getGraphic();
    FancyRowInfo row;
    if (DEBUG_MENU) {
        System.out.println("Menu " + item.getText() + ": " + item.getMenuID());
    }
    if (item.getStyle() == com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU) {
        row = createMenuRow(detailArea, item.getResourceKey(), null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                if (dms.length != 0) {
                    MenuBuilder submenuBuilder = ((MenuItemImpl) item).getSubmenuBuilder();
                    if (submenuBuilder != null) {
                        try {
                            item.removeAllChildItems();
                            submenuBuilder.buildSubmenu(item, getTarget(item));
                        } catch (Throwable t) {
                            Debug.out(t);
                        }
                    }
                    MenuBuildUtils.addPluginMenuItems(item.getItems(), menu, false, true, new MenuBuildUtils.PluginMenuController() {

                        @Override
                        public Listener makeSelectionListener(final com.biglybt.pif.ui.menus.MenuItem plugin_menu_item) {
                            return new TableSelectedRowsListener(tv, false) {

                                @Override
                                public boolean run(TableRowCore[] rows) {
                                    if (rows.length != 0) {
                                        ((MenuItemImpl) plugin_menu_item).invokeListenersMulti(getTarget(item));
                                    }
                                    return true;
                                }
                            };
                        }

                        @Override
                        public void notifyFillListeners(com.biglybt.pif.ui.menus.MenuItem menu_item) {
                            ((MenuItemImpl) menu_item).invokeMenuWillBeShownListeners(getTarget(item));
                        }

                        // @see com.biglybt.ui.swt.MenuBuildUtils.PluginMenuController#buildSubmenu(com.biglybt.pif.ui.menus.MenuItem)
                        @Override
                        public void buildSubmenu(com.biglybt.pif.ui.menus.MenuItem parent) {
                            com.biglybt.pif.ui.menus.MenuBuilder submenuBuilder = ((MenuItemImpl) parent).getSubmenuBuilder();
                            if (submenuBuilder != null) {
                                try {
                                    parent.removeAllChildItems();
                                    submenuBuilder.buildSubmenu(parent, getTarget(item));
                                } catch (Throwable t) {
                                    Debug.out(t);
                                }
                            }
                        }
                    });
                }
            }
        });
    } else {
        row = createRow(detailArea, item.getResourceKey(), null, new TableSelectedRowsListener(tv, false) {

            @Override
            public boolean run(TableRowCore[] rows) {
                if (rows.length != 0) {
                    ((MenuItemImpl) item).invokeListenersMulti(getTarget(item));
                }
                return true;
            }
        });
    }
    row.setEnabled(item.isEnabled());
    if (graphic instanceof UISWTGraphic) {
        row.getIconLabel().setImage(((UISWTGraphic) graphic).getImage());
    } else if (graphic instanceof GraphicURI) {
        ImageLoader.getInstance().setLabelImage(row.getIconLabel(), ((GraphicURI) graphic).getURI().toString());
    }
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuBuilder(com.biglybt.pif.ui.menus.MenuBuilder) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GraphicURI(com.biglybt.pif.ui.GraphicURI) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic)

Example 3 with TableSelectedRowsListener

use of com.biglybt.ui.swt.views.table.TableSelectedRowsListener in project BiglyBT by BiglySoftware.

the class SBC_TagDiscovery method fillMenu.

// @see com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener#fillMenu(java.lang.String, org.eclipse.swt.widgets.Menu)
@Override
public void fillMenu(String sColumnName, Menu menu) {
    List<Object> ds = tv.getSelectedDataSources();
    final MenuItem menuTagIt = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(menuTagIt, "TagDiscoveriesView.menu.tagit");
    menuTagIt.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {

        @Override
        public void run(TableRowCore row) {
            TagDiscovery tagDiscovery = (TagDiscovery) row.getDataSource(true);
            TagManager tm = TagManagerFactory.getTagManager();
            TagType manual_tt = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
            Tag tag = manual_tt.getTag(tagDiscovery.getName(), true);
            if (tag == null) {
                try {
                    tag = manual_tt.createTag(tagDiscovery.getName(), true);
                    tag.setPublic(true);
                    tag.setGroup("Discovery");
                    tag.setVisible(true);
                } catch (TagException e) {
                    return;
                }
            }
            byte[] hash = tagDiscovery.getHash();
            DownloadManager dm = CoreFactory.getSingleton().getGlobalManager().getDownloadManager(new HashWrapper(hash));
            tag.addTaggable(dm);
            String key = Base32.encode(hash) + tag.getTagName(true);
            mapTagDiscoveries.remove(key);
            tv.removeDataSource(tagDiscovery);
            ViewTitleInfoManager.refreshTitleInfo(SBC_TagDiscovery.this);
        }
    });
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)3 DownloadManager (com.biglybt.core.download.DownloadManager)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 AERunnable (com.biglybt.core.util.AERunnable)1 Graphic (com.biglybt.pif.ui.Graphic)1 GraphicURI (com.biglybt.pif.ui.GraphicURI)1 MenuBuilder (com.biglybt.pif.ui.menus.MenuBuilder)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemImpl (com.biglybt.pifimpl.local.ui.menus.MenuItemImpl)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 MultiTrackerEditor (com.biglybt.ui.swt.maketorrent.MultiTrackerEditor)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MenuItem (org.eclipse.swt.widgets.MenuItem)1