Search in sources :

Example 11 with MenuItemFillListener

use of com.biglybt.pif.ui.menus.MenuItemFillListener in project BiglyBT by BiglySoftware.

the class BuddyPlugin method initialize.

@Override
public void initialize(final PluginInterface _plugin_interface) {
    plugin_interface = _plugin_interface;
    ta_category = plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
    az2_handler = new BuddyPluginAZ2(this);
    sec_man = plugin_interface.getUtilities().getSecurityManager();
    logger = plugin_interface.getLogger().getChannel("Friends");
    logger.setDiagnostic();
    final LocaleUtilities lu = plugin_interface.getUtilities().getLocaleUtilities();
    lu.addListener(new LocaleListener() {

        @Override
        public void localeChanged(Locale l) {
            updateLocale(lu);
        }
    });
    updateLocale(lu);
    BasicPluginConfigModel config = plugin_interface.getUIManager().createBasicPluginConfigModel("Views.plugins." + VIEW_ID + ".title");
    // enabled
    classic_enabled_param = config.addBooleanParameter2("azbuddy.enabled", "azbuddy.enabled", false);
    // nickname
    nick_name_param = config.addStringParameter2("azbuddy.nickname", "azbuddy.nickname", "");
    nick_name_param.setGenerateIntermediateEvents(false);
    nick_name_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            updateNickName(nick_name_param.getValue());
        }
    });
    // online status
    String[] os_values = STATUS_VALUES;
    String[] os_labels = STATUS_STRINGS;
    online_status_param = config.addStringListParameter2("azbuddy.online_status", "azbuddy.online_status", os_values, os_labels, os_values[0]);
    online_status_param.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            int status = Integer.parseInt(online_status_param.getValue());
            updateOnlineStatus(status);
        }
    });
    // If we add this then use proper message texts in the STATUS_STRINGS
    online_status_param.setVisible(SUPPORT_ONLINE_STATUS);
    // protocol speed
    final IntParameter protocol_speed = config.addIntParameter2("azbuddy.protocolspeed", "azbuddy.protocolspeed", 32);
    protocol_speed.setMinimumRequiredUserMode(Parameter.MODE_ADVANCED);
    ConnectionManager cman = plugin_interface.getConnectionManager();
    int inbound_limit = protocol_speed.getValue() * 1024;
    inbound_limiter = cman.createRateLimiter("buddy_up", inbound_limit);
    outbound_limiter = cman.createRateLimiter("buddy_down", 0);
    protocol_speed.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            inbound_limiter.setRateLimitBytesPerSecond(protocol_speed.getValue() * 1024);
        }
    });
    // chat notifications
    enable_chat_notifications = config.addBooleanParameter2("azbuddy.enable_chat_notif", "azbuddy.enable_chat_notif", true);
    // default published tags or cats
    cat_pub = config.addStringParameter2("azbuddy.enable_cat_pub", "azbuddy.enable_cat_pub", "");
    cat_pub.setGenerateIntermediateEvents(false);
    setPublicTagsOrCategories(cat_pub.getValue(), false);
    final BooleanParameter tracker_enable = config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true);
    final BooleanParameter tracker_so_enable = config.addBooleanParameter2("azbuddy.tracker.seeding.only.enabled", "azbuddy.tracker.seeding.only.enabled", false);
    final BooleanParameter buddies_lan_local = config.addBooleanParameter2("azbuddy.tracker.con.lan.local", "azbuddy.tracker.con.lan.local", true);
    buddies_lan_local.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            lan_local_peers = buddies_lan_local.getValue();
        }
    });
    lan_local_peers = buddies_lan_local.getValue();
    cat_pub.addListener(new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            setPublicTagsOrCategories(cat_pub.getValue(), false);
        }
    });
    config.createGroup("label.friends", new Parameter[] { classic_enabled_param, nick_name_param, online_status_param, protocol_speed, enable_chat_notifications, cat_pub, tracker_enable, tracker_so_enable, buddies_lan_local });
    // decentralised stuff
    beta_enabled_param = config.addBooleanParameter2("azbuddy.dchat.decentralized.enabled", "azbuddy.dchat.decentralized.enabled", true);
    config.createGroup("azbuddy.dchat.decentralized", new Parameter[] { beta_enabled_param });
    // config end
    beta_plugin = new BuddyPluginBeta(plugin_interface, this, beta_enabled_param);
    final TableContextMenuItem menu_item_itorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, "azbuddy.contextmenu");
    final TableContextMenuItem menu_item_ctorrents = plugin_interface.getUIManager().getTableManager().addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, "azbuddy.contextmenu");
    menu_item_itorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_itorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
    menu_item_ctorrents.setStyle(TableContextMenuItem.STYLE_MENU);
    menu_item_ctorrents.setHeaderCategory(MenuItem.HEADER_SOCIAL);
    MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object _target) {
            menu.removeAllChildItems();
            if (!(isClassicEnabled() && isAvailable())) {
                menu.setEnabled(false);
                return;
            }
            final List<Torrent> torrents = new ArrayList<>();
            if (_target instanceof TableRow) {
                addDownload(torrents, (TableRow) _target);
            } else {
                TableRow[] rows = (TableRow[]) _target;
                for (TableRow row : rows) {
                    addDownload(torrents, row);
                }
            }
            if (torrents.size() == 0) {
                menu.setEnabled(false);
            } else {
                List<BuddyPluginBuddy> buddies = getBuddies();
                boolean incomplete = ((TableContextMenuItem) menu).getTableID() == TableManager.TABLE_MYTORRENTS_INCOMPLETE;
                TableContextMenuItem parent = incomplete ? menu_item_itorrents : menu_item_ctorrents;
                for (int i = 0; i < buddies.size(); i++) {
                    final BuddyPluginBuddy buddy = (BuddyPluginBuddy) buddies.get(i);
                    boolean online = buddy.isOnline(true);
                    TableContextMenuItem item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(parent, "!" + buddy.getName() + (online ? "" : (" - " + MessageText.getString("label.disconnected"))) + "!");
                    item.addMultiListener(new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            for (Torrent torrent : torrents) {
                                az2_handler.sendAZ2Torrent(torrent, buddy);
                            }
                        }
                    });
                    item.setEnabled(online);
                }
                menu.setEnabled(true);
            }
        }

        protected void addDownload(List<Torrent> torrents, TableRow row) {
            Object obj = row.getDataSource();
            Download download;
            if (obj instanceof Download) {
                download = (Download) obj;
            } else {
                DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                try {
                    download = file.getDownload();
                } catch (DownloadException e) {
                    Debug.printStackTrace(e);
                    return;
                }
            }
            Torrent torrent = download.getTorrent();
            if (torrent != null && !TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
                torrents.add(torrent);
            }
        }
    };
    menu_item_itorrents.addFillListener(menu_fill_listener);
    menu_item_ctorrents.addFillListener(menu_fill_listener);
    buddy_tracker = new BuddyPluginTracker(this, tracker_enable, tracker_so_enable);
    plugin_interface.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                try {
                    synchronized (swt_ui_waiters) {
                        swt_ui = (BuddyPluginViewInterface) Class.forName("com.biglybt.plugin.net.buddy.swt.BuddyPluginView").getConstructor(new Class[] { BuddyPlugin.class, UIInstance.class, String.class }).newInstance(new Object[] { BuddyPlugin.this, instance, VIEW_ID });
                        for (Runnable r : swt_ui_waiters) {
                            try {
                                r.run();
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                        swt_ui_waiters.clear();
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
            setupDisablePrompt(instance);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT) && swt_ui != null) {
                swt_ui.destroy();
                swt_ui = null;
            }
        }
    });
    ParameterListener enabled_listener = new ParameterListener() {

        @Override
        public void parameterChanged(Parameter param) {
            boolean classic_enabled = classic_enabled_param.getValue();
            nick_name_param.setEnabled(classic_enabled);
            online_status_param.setEnabled(classic_enabled);
            protocol_speed.setEnabled(classic_enabled);
            enable_chat_notifications.setEnabled(classic_enabled);
            cat_pub.setEnabled(classic_enabled);
            tracker_enable.setEnabled(classic_enabled);
            tracker_so_enable.setEnabled(tracker_enable.getValue());
            if (param != null) {
                setClassicEnabledInternal(classic_enabled);
                fireEnabledStateChanged();
            }
        }
    };
    enabled_listener.parameterChanged(null);
    classic_enabled_param.addListener(enabled_listener);
    beta_enabled_param.addListener(enabled_listener);
    tracker_enable.addListener(enabled_listener);
    loadConfig();
    registerMessageHandler();
    plugin_interface.addListener(new PluginListener() {

        @Override
        public void initializationComplete() {
            final DelayedTask dt = plugin_interface.getUtilities().createDelayedTask(new Runnable() {

                @Override
                public void run() {
                    new AEThread2("BuddyPlugin:init", true) {

                        @Override
                        public void run() {
                            startup();
                            beta_plugin.startup();
                            initialization_complete.set(true);
                        }
                    }.start();
                }
            });
            dt.queue();
        }

        @Override
        public void closedownInitiated() {
            saveConfig(true);
            closedown();
            beta_plugin.closedown();
        }

        @Override
        public void closedownComplete() {
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) PluginListener(com.biglybt.pif.PluginListener) ConnectionManager(com.biglybt.pif.network.ConnectionManager) DownloadException(com.biglybt.pif.download.DownloadException) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) BuddyPluginTracker(com.biglybt.plugin.net.buddy.tracker.BuddyPluginTracker) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) TableRow(com.biglybt.pif.ui.tables.TableRow) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) BasicPluginConfigModel(com.biglybt.pif.ui.model.BasicPluginConfigModel)

Example 12 with MenuItemFillListener

use of com.biglybt.pif.ui.menus.MenuItemFillListener in project BiglyBT by BiglySoftware.

the class SearchUtils method addMenus.

public static void addMenus(final MenuManager menuManager) {
    final com.biglybt.pif.ui.menus.MenuItem template_menu = menuManager.addMenuItem("sidebar.Search", "Search.menu.engines");
    template_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    template_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
    template_menu.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
            template_menu.removeAllChildItems();
            Engine[] engines = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngines(true, false);
            Arrays.sort(engines, new Comparator<Engine>() {

                @Override
                public int compare(Engine o1, Engine o2) {
                    return (o1.getName().compareToIgnoreCase(o2.getName()));
                }
            });
            com.biglybt.pif.ui.menus.MenuItem import_menu = menuManager.addMenuItem(template_menu, "menu.import.json.from.clipboard");
            import_menu.addListener(new MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                    importFromClipboard();
                }
            });
            com.biglybt.pif.ui.menus.MenuItem sep = menuManager.addMenuItem(template_menu, "!sep!");
            sep.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
            for (int i = 0; i < engines.length; i++) {
                final Engine engine = engines[i];
                com.biglybt.pif.ui.menus.MenuItem engine_menu = menuManager.addMenuItem(template_menu, "!" + engine.getName() + "!");
                engine_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU);
                if (!(engine instanceof PluginEngine)) {
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "MyTorrentsView.menu.exportmenu");
                    mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            final Shell shell = Utils.findAnyShell();
                            shell.getDisplay().asyncExec(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    FileDialog dialog = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.SAVE);
                                    dialog.setFilterPath(TorrentOpener.getFilterPathData());
                                    dialog.setText(MessageText.getString("metasearch.export.select.template.file"));
                                    dialog.setFilterExtensions(VuzeFileHandler.getVuzeFileFilterExtensions());
                                    dialog.setFilterNames(VuzeFileHandler.getVuzeFileFilterExtensions());
                                    String path = TorrentOpener.setFilterPathData(dialog.open());
                                    if (path != null) {
                                        if (!VuzeFileHandler.isAcceptedVuzeFileName(path)) {
                                            path = VuzeFileHandler.getVuzeFileName(path);
                                        }
                                        try {
                                            engine.exportToVuzeFile(new File(path));
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            });
                        }
                    });
                    com.biglybt.pif.ui.menus.MenuItem copy_mi = menuManager.addMenuItem(engine_menu, "menu.export.json.to.clipboard");
                    copy_mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            final Shell shell = Utils.findAnyShell();
                            shell.getDisplay().asyncExec(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    try {
                                        ClipboardCopy.copyToClipBoard(engine.exportToVuzeFile().exportToJSON());
                                    } catch (Throwable e) {
                                        Debug.out(e);
                                    }
                                }
                            });
                        }
                    });
                    final Subscription subs = engine.getSubscription();
                    if (subs != null) {
                        com.biglybt.pif.ui.menus.MenuItem copy_uri = menuManager.addMenuItem(engine_menu, "label.copy.uri.to.clip");
                        copy_uri.addListener(new MenuItemListener() {

                            @Override
                            public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                final Shell shell = Utils.findAnyShell();
                                shell.getDisplay().asyncExec(new AERunnable() {

                                    @Override
                                    public void runSupport() {
                                        try {
                                            ClipboardCopy.copyToClipBoard(subs.getURI());
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                });
                            }
                        });
                    }
                    if (engine instanceof WebEngine) {
                        final WebEngine we = (WebEngine) engine;
                        if (we.isNeedsAuth()) {
                            String cookies = we.getCookies();
                            if (cookies != null && cookies.length() > 0) {
                                mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.resetauth");
                                mi.addListener(new MenuItemListener() {

                                    @Override
                                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                                        we.setCookies(null);
                                    }
                                });
                            }
                        }
                    }
                }
                if (!(engine instanceof PluginEngine)) {
                    if (engine_menu.getItems().length > 0) {
                        com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep");
                        mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                    }
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Button.remove");
                    mi.addListener(new MenuItemListener() {

                        @Override
                        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                            engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
                        }
                    });
                    mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
                    mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                }
                if (engine_menu.getItems().length > 0) {
                    com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.sep2");
                    mi.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_SEPARATOR);
                }
                com.biglybt.pif.ui.menus.MenuItem mi = menuManager.addMenuItem(engine_menu, "Subscription.menu.properties");
                mi.addListener(new MenuItemListener() {

                    @Override
                    public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
                        showProperties(engine);
                    }
                });
            }
        }
    });
    com.biglybt.pif.ui.menus.MenuItem chat_menu = menuManager.addMenuItem("sidebar.Search", "label.chat");
    chat_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    MenuBuildUtils.addChatMenu(menuManager, chat_menu, new MenuBuildUtils.ChatKeyResolver() {

        @Override
        public String getChatKey(Object object) {
            return ("Search Templates");
        }
    });
    com.biglybt.pif.ui.menus.MenuItem export_menu = menuManager.addMenuItem("sidebar.Search", "search.export.all");
    export_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    export_menu.setStyle(com.biglybt.pif.ui.menus.MenuItem.STYLE_PUSH);
    export_menu.addListener(new MenuItemListener() {

        @Override
        public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object target) {
            exportAll();
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) MenuItem(org.eclipse.swt.widgets.MenuItem) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) Shell(org.eclipse.swt.widgets.Shell) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Subscription(com.biglybt.core.subs.Subscription) FileDialog(org.eclipse.swt.widgets.FileDialog) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 13 with MenuItemFillListener

use of com.biglybt.pif.ui.menus.MenuItemFillListener in project BiglyBT by BiglySoftware.

the class ColumnDateSizer method init.

private void init() {
    final TableContextMenuItem menuShowTime = addContextMenuItem("TableColumn.menu.date_added.time", MENU_STYLE_HEADER);
    menuShowTime.setStyle(TableContextMenuItem.STYLE_CHECK);
    menuShowTime.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(showTime);
        }
    });
    menuShowTime.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            showTime = !showTime;
            setUserData("showTime", new Long(showTime ? 1 : 0));
            maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
            maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
            curFormat = -1;
            recalcWidth(new Date(), null);
            if (curFormat < 0) {
                curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
            }
        }
    });
    configDateFormatListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            tableFormatOverride = COConfigurationManager.getStringParameter("Table.column.dateformat", "");
            if (tableFormatOverride == null) {
                tableFormatOverride = "";
            }
            curFormat = -1;
            if (tableFormatOverride.length() == 0) {
                recalcWidth(new Date(), null);
                if (curFormat < 0) {
                    curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
                }
                menuShowTime.setVisible(true);
            } else {
                invalidateCells();
                menuShowTime.setVisible(false);
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Table.column.dateformat", configDateFormatListener);
    cdf = ViewUtils.addCustomDateFormat(this);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ParameterListener(com.biglybt.core.config.ParameterListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Date(java.util.Date)

Example 14 with MenuItemFillListener

use of com.biglybt.pif.ui.menus.MenuItemFillListener in project BiglyBT by BiglySoftware.

the class MenuBuildUtils method addChatMenu.

public static MenuItem addChatMenu(final MenuManager menu_manager, final MenuItem chat_item, final ChatKeyResolver chat_key_resolver) {
    chat_item.setStyle(MenuItem.STYLE_MENU);
    chat_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.removeAllChildItems();
            {
                MenuItem chat_pub = menu_manager.addMenuItem(chat_item, "label.public");
                chat_pub.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Object[] rows = (Object[]) target;
                        if (rows.length > 0) {
                            final AtomicInteger count = new AtomicInteger(rows.length);
                            pub_chat_pending.set(true);
                            for (Object obj : rows) {
                                String chat_key = chat_key_resolver.getChatKey(obj);
                                if (chat_key != null) {
                                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                                        @Override
                                        public void complete(ChatInstance chat) {
                                            if (count.decrementAndGet() == 0) {
                                                pub_chat_pending.set(false);
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
                if (pub_chat_pending.get()) {
                    chat_pub.setEnabled(false);
                    chat_pub.setText(chat_pub.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
            if (BuddyPluginUtils.isBetaChatAnonAvailable()) {
                MenuItem chat_priv = menu_manager.addMenuItem(chat_item, "label.anon");
                chat_priv.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Object[] rows = (Object[]) target;
                        if (rows.length > 0) {
                            final AtomicInteger count = new AtomicInteger(rows.length);
                            anon_chat_pending.set(true);
                            for (Object obj : rows) {
                                String chat_key = chat_key_resolver.getChatKey(obj);
                                if (chat_key != null) {
                                    BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, chat_key, new BuddyPluginUtils.CreateChatCallback() {

                                        @Override
                                        public void complete(ChatInstance chat) {
                                            if (count.decrementAndGet() == 0) {
                                                anon_chat_pending.set(false);
                                            }
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
                if (anon_chat_pending.get()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            } else {
                MenuItem chat_priv = menu_manager.addMenuItem(chat_item, "label.anon");
                chat_priv.setText(MessageText.getString("label.anon") + "...");
                chat_priv.addMultiListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        I2PHelpers.installI2PHelper(null, null, null);
                    }
                });
                if (I2PHelpers.isInstallingI2PHelper()) {
                    chat_priv.setEnabled(false);
                    chat_priv.setText(chat_priv.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
                }
            }
        }
    });
    return (chat_item);
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) BuddyPluginUtils(com.biglybt.plugin.net.buddy.BuddyPluginUtils)

Aggregations

MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)14 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)12 MenuItem (com.biglybt.pif.ui.menus.MenuItem)11 MenuManager (com.biglybt.pif.ui.menus.MenuManager)6 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)6 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)4 PluginInterface (com.biglybt.pif.PluginInterface)4 UIManager (com.biglybt.pif.ui.UIManager)4 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)3 UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)3 Download (com.biglybt.pif.download.Download)3 Engine (com.biglybt.core.metasearch.Engine)2 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)2 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)2 PluginManager (com.biglybt.pif.PluginManager)2 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)2 TableRow (com.biglybt.pif.ui.tables.TableRow)2 PluginUISWTSkinObject (com.biglybt.ui.swt.pif.PluginUISWTSkinObject)2 SkinnedDialog (com.biglybt.ui.swt.views.skin.SkinnedDialog)2 File (java.io.File)2