Search in sources :

Example 6 with MenuItemFillListener

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

the class SubscriptionManagerUI method createMenus.

protected static void createMenus(final MenuManager menu_manager, final MenuCreator menu_creator, final Subscription[] all_subs) {
    if (all_subs.length > 1) {
        MenuItem menuItem = menu_creator.createMenu("menu.set.parent");
        menuItem.addMultiListener(new SubsMenuItemListener() {

            @Override
            public void selected(final Subscription[] subs) {
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                if (subs.length == 1) {
                    entry.setPreenteredText(subs[0].getParent(), false);
                }
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(true);
                entry.setLocalisedTitle(MessageText.getString("label.set.parent"));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() == 0) {
                            input = null;
                        }
                        for (Subscription sub : subs) {
                            sub.setParent(input);
                        }
                    }
                });
            }
        });
        return;
    }
    final Subscription subs = all_subs[0];
    boolean is_search_template = subs.isSearchTemplate();
    if (!is_search_template) {
        MenuItem menuItem = menu_creator.createMenu("Subscription.menu.forcecheck");
        menuItem.setText(MessageText.getString("Subscription.menu.forcecheck"));
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                try {
                    subs.getManager().getScheduler().downloadAsync(subs, true);
                } catch (SubscriptionException e) {
                    Debug.out(e);
                }
            }
        });
        menuItem = menu_creator.createMenu("Subscription.menu.clearall");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                subs.getHistory().markAllResultsRead();
                menu_creator.refreshView();
            }
        });
        menuItem = menu_creator.createMenu("Subscription.menu.dirtyall");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                subs.getHistory().markAllResultsUnread();
                menu_creator.refreshView();
            }
        });
        menuItem = menu_creator.createMenu("Subscription.menu.deleteall");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                subs.getHistory().deleteAllResults();
                menu_creator.refreshView();
            }
        });
        menuItem = menu_creator.createMenu("Subscription.menu.reset");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                subs.getHistory().reset();
                try {
                    subs.getEngine().reset();
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
                try {
                    subs.getManager().getScheduler().downloadAsync(subs, true);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        });
        try {
            Engine engine = subs.getEngine();
            if (engine instanceof WebEngine) {
                if (((WebEngine) engine).isNeedsAuth()) {
                    menuItem = menu_creator.createMenu("Subscription.menu.resetauth");
                    menuItem.addListener(new SubsMenuItemListener() {

                        @Override
                        public void selected(Subscription subs) {
                            try {
                                Engine engine = subs.getEngine();
                                if (engine instanceof WebEngine) {
                                    ((WebEngine) engine).setCookies(null);
                                }
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                            try {
                                subs.getManager().getScheduler().downloadAsync(subs, true);
                            } catch (Throwable e) {
                                Debug.out(e);
                            }
                        }
                    });
                    menuItem = menu_creator.createMenu("Subscription.menu.setcookies");
                    menuItem.addListener(new SubsMenuItemListener() {

                        @Override
                        public void selected(final Subscription subs) {
                            try {
                                Engine engine = subs.getEngine();
                                if (engine instanceof WebEngine) {
                                    final WebEngine we = (WebEngine) engine;
                                    UISWTInputReceiver entry = new SimpleTextEntryWindow();
                                    String[] req = we.getRequiredCookies();
                                    String req_str = "";
                                    for (String r : req) {
                                        req_str += (req_str.length() == 0 ? "" : ";") + r + "=?";
                                    }
                                    entry.setPreenteredText(req_str, true);
                                    entry.maintainWhitespace(false);
                                    entry.allowEmptyInput(false);
                                    entry.setTitle("general.enter.cookies");
                                    entry.prompt(new UIInputReceiverListener() {

                                        @Override
                                        public void UIInputReceiverClosed(UIInputReceiver entry) {
                                            if (!entry.hasSubmittedInput()) {
                                                return;
                                            }
                                            try {
                                                String input = entry.getSubmittedInput().trim();
                                                if (input.length() > 0) {
                                                    we.setCookies(input);
                                                    subs.getManager().getScheduler().downloadAsync(subs, true);
                                                }
                                            } catch (Throwable e) {
                                                Debug.printStackTrace(e);
                                            }
                                        }
                                    });
                                }
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    });
                }
            }
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
        // sep
        menu_creator.createMenu("s1").setStyle(MenuItem.STYLE_SEPARATOR);
        // category
        menuItem = menu_creator.createMenu("MyTorrentsView.menu.setCategory");
        menuItem.setStyle(MenuItem.STYLE_MENU);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                addCategorySubMenu(menu_manager, menu, subs);
            }
        });
        // tag
        menuItem = menu_creator.createMenu("label.tag");
        menuItem.setStyle(MenuItem.STYLE_MENU);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                addTagSubMenu(menu_manager, menu, subs);
            }
        });
        // parent
        menuItem = menu_creator.createMenu("menu.set.parent");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(final Subscription subs) {
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.setPreenteredText(subs.getParent(), false);
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(true);
                entry.setLocalisedTitle(MessageText.getString("label.set.parent", new String[] { subs.getName() }));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() == 0) {
                            input = null;
                        }
                        subs.setParent(input);
                    }
                });
            }
        });
        // view options
        menuItem = menu_creator.createMenu("menu.view.options");
        menuItem.setStyle(MenuItem.STYLE_MENU);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.removeAllChildItems();
                int vo = subs.getViewOptions();
                MenuItem m = menu_manager.addMenuItem(menu, "label.full");
                m.setStyle(MenuItem.STYLE_RADIO);
                m.setData(Boolean.valueOf(vo == Subscription.VO_FULL));
                m.addListener(new SubsMenuItemListener() {

                    @Override
                    public void selected(final Subscription subs) {
                        subs.setViewOptions(Subscription.VO_FULL);
                    }
                });
                m = menu_manager.addMenuItem(menu, "label.no.header");
                m.setStyle(MenuItem.STYLE_RADIO);
                m.setData(Boolean.valueOf(vo == Subscription.VO_HIDE_HEADER));
                m.addListener(new SubsMenuItemListener() {

                    @Override
                    public void selected(final Subscription subs) {
                        subs.setViewOptions(Subscription.VO_HIDE_HEADER);
                    }
                });
            }
        });
        // chat
        final String key = SubscriptionUtils.getSubscriptionChatKey(subs);
        if (key != null) {
            menuItem = menu_creator.createMenu("label.chat");
            menuItem.setHeaderCategory(MenuItem.HEADER_SOCIAL);
            MenuBuildUtils.addChatMenu(menu_manager, menuItem, new MenuBuildUtils.ChatKeyResolver() {

                @Override
                public String getChatKey(Object object) {
                    return (key);
                }
            });
        }
        if (subs.isUpdateable()) {
            menuItem = menu_creator.createMenu("MyTorrentsView.menu.rename");
            menuItem.addListener(new SubsMenuItemListener() {

                @Override
                public void selected(final Subscription subs) {
                    UISWTInputReceiver entry = new SimpleTextEntryWindow();
                    entry.setPreenteredText(subs.getName(), false);
                    entry.maintainWhitespace(false);
                    entry.allowEmptyInput(false);
                    entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { subs.getName() }));
                    entry.prompt(new UIInputReceiverListener() {

                        @Override
                        public void UIInputReceiverClosed(UIInputReceiver entry) {
                            if (!entry.hasSubmittedInput()) {
                                return;
                            }
                            String input = entry.getSubmittedInput().trim();
                            if (input.length() > 0) {
                                try {
                                    subs.setName(input);
                                } catch (Throwable e) {
                                    Debug.printStackTrace(e);
                                }
                            }
                        }
                    });
                }
            });
        }
        menuItem = menu_creator.createMenu("Subscription.menu.upgrade");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                subs.resetHighestVersion();
            }
        });
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.setVisible(subs.getHighestVersion() > subs.getVersion());
            }
        });
    }
    MenuItem menuItem = menu_creator.createMenu("label.copy.uri.to.clip");
    menuItem.addListener(new SubsMenuItemListener() {

        @Override
        public void selected(Subscription subs) {
            ClipboardCopy.copyToClipBoard(subs.getURI());
        }
    });
    menuItem = menu_creator.createMenu("Subscription.menu.export");
    menuItem.addListener(new SubsMenuItemListener() {

        @Override
        public void selected(Subscription subs) {
            export(subs);
        }
    });
    // sep
    menu_creator.createMenu("s2").setStyle(MenuItem.STYLE_SEPARATOR);
    if (!is_search_template) {
        try {
            Engine engine = subs.getEngine();
            if (engine instanceof WebEngine) {
                menuItem = menu_creator.createMenu("menu.change.url");
                menuItem.addListener(new SubsMenuItemListener() {

                    @Override
                    public void selected(final Subscription subs) {
                        UISWTInputReceiver entry = new SimpleTextEntryWindow();
                        try {
                            WebEngine web_engine = (WebEngine) subs.getEngine();
                            entry.setPreenteredText(web_engine.getSearchUrl(true), false);
                            entry.maintainWhitespace(false);
                            entry.allowEmptyInput(false);
                            entry.setLocalisedTitle(MessageText.getString("change.url.msg.title", new String[] { subs.getName() }));
                            entry.setMessage("change.url.msg.desc");
                            entry.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver entry) {
                                    if (!entry.hasSubmittedInput()) {
                                        return;
                                    }
                                    String input = entry.getSubmittedInput().trim();
                                    if (input.length() > 0) {
                                        try {
                                            WebEngine web_engine = (WebEngine) subs.getEngine();
                                            web_engine.setSearchUrl(input);
                                            subs.cloneWithNewEngine(web_engine);
                                        } catch (Throwable e) {
                                            Debug.out(e);
                                        }
                                    }
                                }
                            });
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
        // public
        menuItem = menu_creator.createMenu("subs.prop.is_public");
        menuItem.setStyle(MenuItem.STYLE_CHECK);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.setData(subs.isPublic());
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                try {
                    subs.setPublic(!subs.isPublic());
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        });
        // enabled
        menuItem = menu_creator.createMenu("subs.prop.enabled");
        menuItem.setStyle(MenuItem.STYLE_CHECK);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.setData(subs.getHistory().isEnabled());
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                try {
                    subs.getHistory().setEnabled(!subs.getHistory().isEnabled());
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        });
        if (subs.isAutoDownloadSupported()) {
            // auto-dl
            menuItem = menu_creator.createMenu("subs.prop.is_auto");
            menuItem.setStyle(MenuItem.STYLE_CHECK);
            menuItem.addFillListener(new MenuItemFillListener() {

                @Override
                public void menuWillBeShown(MenuItem menu, Object data) {
                    menu.setData(subs.getHistory().isAutoDownload());
                }
            });
            menuItem.addListener(new SubsMenuItemListener() {

                @Override
                public void selected(Subscription subs) {
                    try {
                        subs.getHistory().setAutoDownload(!subs.getHistory().isAutoDownload());
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
        // refresh period
        menuItem = menu_creator.createMenu("subs.prop.update_period");
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                int check_freq = subs.getHistory().getCheckFrequencyMins();
                String text = MessageText.getString("subs.prop.update_period");
                if (check_freq != Integer.MAX_VALUE) {
                    text += " (" + check_freq + " " + MessageText.getString("ConfigView.text.minutes") + ")";
                }
                menu.setText(text + "...");
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(final Subscription subs) {
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                int check_freq = subs.getHistory().getCheckFrequencyMins();
                entry.setPreenteredText(check_freq == Integer.MAX_VALUE ? "" : String.valueOf(check_freq), false);
                entry.setLocalisedTitle(MessageText.getString("subscriptions.enter.freq"));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() > 0) {
                            try {
                                subs.getHistory().setCheckFrequencyMins(Integer.parseInt(input));
                            } catch (Throwable e) {
                            }
                        }
                    }
                });
            }
        });
        // dl is anon
        menuItem = menu_creator.createMenu("subs.prop.is_dl_anon");
        menuItem.setStyle(MenuItem.STYLE_CHECK);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.setData(subs.getHistory().getDownloadNetworks() != null);
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                try {
                    boolean is_anon = subs.getHistory().getDownloadNetworks() != null;
                    subs.getHistory().setDownloadNetworks(is_anon ? null : AENetworkClassifier.AT_NON_PUBLIC);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        });
        // post notification
        menuItem = menu_creator.createMenu("subs.noti.post");
        menuItem.setStyle(MenuItem.STYLE_CHECK);
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.setData(subs.getHistory().getNotificationPostEnabled());
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(Subscription subs) {
                try {
                    subs.getHistory().setNotificationPostEnabled(!subs.getHistory().getNotificationPostEnabled());
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        });
        // max results
        menuItem = menu_creator.createMenu("label.set.max.results");
        menuItem.addFillListener(new MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                int max_results = subs.getHistory().getMaxNonDeletedResults();
                if (max_results < 0) {
                    SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
                    max_results = subs_man.getMaxNonDeletedResults();
                }
                String max_results_str = (max_results == 0 ? MessageText.getString("ConfigView.unlimited") : String.valueOf(max_results));
                String text = MessageText.getString("label.set.max.results");
                text += " (" + max_results_str + ")";
                menu.setText(text + "...");
            }
        });
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(final Subscription subs) {
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(true);
                int max_results = subs.getHistory().getMaxNonDeletedResults();
                if (max_results < 0) {
                    SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
                    max_results = subs_man.getMaxNonDeletedResults();
                }
                if (max_results > 0) {
                    entry.setPreenteredText(String.valueOf(max_results), false);
                }
                entry.setLocalisedTitle(MessageText.getString("subscriptions.enter.max.results"));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        try {
                            subs.getHistory().setMaxNonDeletedResults(input.length() == 0 ? -1 : Math.abs(Integer.parseInt(input)));
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
            }
        });
        // rename
        menuItem = menu_creator.createMenu("MyTorrentsView.menu.rename");
        menuItem.addListener(new SubsMenuItemListener() {

            @Override
            public void selected(final Subscription subs) {
                UISWTInputReceiver entry = new SimpleTextEntryWindow();
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                entry.setPreenteredText(subs.getName(), false);
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { subs.getName() }));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() > 0) {
                            subs.setLocalName(input);
                        }
                    }
                });
            }
        });
    }
    menuItem = menu_creator.createMenu("Subscription.menu.remove");
    Utils.setMenuItemImage(menuItem, "delete");
    menuItem.addListener(new SubsMenuItemListener() {

        @Override
        public void selected(Subscription subs) {
            removeWithConfirm(subs);
        }
    });
    menu_creator.createMenu("s3").setStyle(MenuItem.STYLE_SEPARATOR);
    menuItem = menu_creator.createMenu("Subscription.menu.properties");
    menuItem.addListener(new SubsMenuItemListener() {

        @Override
        public void selected(Subscription subs) {
            showProperties(subs);
        }
    });
}
Also used : MenuItem(com.biglybt.pif.ui.menus.MenuItem) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine)

Example 7 with MenuItemFillListener

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

the class MenuItemImpl method invokeMenuWillBeShownListeners.

public void invokeMenuWillBeShownListeners(Object target) {
    for (Iterator iter = fill_listeners.iterator(); iter.hasNext(); ) {
        try {
            MenuItemFillListener l = (MenuItemFillListener) iter.next();
            l.menuWillBeShown(this, target);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) Iterator(java.util.Iterator)

Example 8 with MenuItemFillListener

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

the class DeviceManagerUI method setupEntry.

private void setupEntry(deviceItem new_di, final Device device, String parent) {
    synchronized (DeviceManagerUI.this) {
        if (new_di.isDestroyed()) {
            return;
        }
        deviceView view = new deviceView(parent, device);
        new_di.setView(view);
        String key = parent + "/" + device.getID() + ":" + nextSidebarID();
        final MdiEntry entry;
        int device_type = device.getType();
        if (device_type == Device.DT_MEDIA_RENDERER) {
            entry = mdi.createEntryFromSkinRef(parent, key, "devicerendererview", device.getName(), view, null, false, null);
        } else {
            entry = mdi.createEntryFromEventListener(parent, view, key, false, device, null);
            entry.setExpanded(true);
        }
        entry.setDatasource(device);
        entry.setLogID(parent + "-" + device.getName());
        entry.addListener(new MdiCloseListener() {

            @Override
            public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                if (device != null) {
                    device.setTransientProperty(DEVICE_IVIEW_KEY, null);
                }
            }
        });
        new_di.setMdiEntry(entry);
        setStatus(device, new_di);
        if (device instanceof TranscodeTarget) {
            entry.addListener(new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object payload) {
                    return handleDrop((TranscodeTarget) device, payload);
                }
            });
        }
        final MenuManager menu_manager = ui_manager.getMenuManager();
        boolean need_sep = false;
        if (device instanceof TranscodeTarget) {
            need_sep = true;
            MenuItem explore_menu_item = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.exploreTranscodes");
            explore_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            explore_menu_item.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    ManagerUtils.open(((TranscodeTarget) device).getWorkingDirectory());
                }
            });
        }
        if (device instanceof DeviceMediaRenderer) {
            need_sep = true;
            // filter view
            final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
            if (renderer.canFilterFilesView()) {
                MenuItem filterfiles_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.only.show");
                filterfiles_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                filterfiles_menu_item.setStyle(MenuItem.STYLE_CHECK);
                filterfiles_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getFilterFilesView()));
                    }
                });
                filterfiles_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setFilterFilesView((Boolean) menu.getData());
                    }
                });
            }
            if (renderer.canShowCategories()) {
                MenuItem showcat_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.show.cat");
                showcat_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                showcat_menu_item.setStyle(MenuItem.STYLE_CHECK);
                showcat_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getShowCategories()));
                    }
                });
                showcat_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setShowCategories((Boolean) menu.getData());
                    }
                });
            }
            if (!DISABLED_TRANSCODING) {
                MenuItem alwayscache_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.always.cache");
                alwayscache_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                alwayscache_menu_item.setStyle(MenuItem.STYLE_CHECK);
                alwayscache_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAlwaysCacheFiles()));
                    }
                });
                alwayscache_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAlwaysCacheFiles((Boolean) menu.getData());
                    }
                });
            }
        }
        if (need_sep) {
            MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "1");
            menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
            menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        }
        need_sep = false;
        if (device instanceof DeviceMediaRenderer) {
            final DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
            if (renderer.canCopyToFolder()) {
                need_sep = true;
                MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy");
                autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autocopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoCopyToFolder()));
                    }
                });
                autocopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoCopyToFolder((Boolean) menu.getData());
                    }
                });
                final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
                mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
                mancopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        try {
                            renderer.manualCopy();
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
                mancopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean enabled = false;
                        if (!renderer.getAutoCopyToFolder()) {
                            File target = renderer.getCopyToFolder();
                            if (target != null && target.exists()) {
                                enabled = renderer.getCopyToFolderPending() > 0;
                            }
                        }
                        mancopy_menu_item.setEnabled(enabled);
                    }
                });
                MenuItem setcopyto_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.setcopyto");
                setcopyto_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                setcopyto_menu_item.setStyle(MenuItem.STYLE_PUSH);
                setcopyto_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        Shell shell = Utils.findAnyShell();
                        DirectoryDialog dd = new DirectoryDialog(shell);
                        File existing = renderer.getCopyToFolder();
                        if (existing != null) {
                            dd.setFilterPath(existing.getAbsolutePath());
                        }
                        dd.setText(MessageText.getString("devices.xcode.setcopyto.title"));
                        String path = dd.open();
                        if (path != null) {
                            renderer.setCopyToFolder(new File(path));
                        }
                    }
                });
            }
            if (renderer.canCopyToDevice()) {
                need_sep = true;
                MenuItem autocopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoCopy.device");
                autocopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autocopy_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autocopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoCopyToDevice()));
                    }
                });
                autocopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoCopyToDevice((Boolean) menu.getData());
                    }
                });
                final MenuItem mancopy_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.mancopy");
                mancopy_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                mancopy_menu_item.setStyle(MenuItem.STYLE_PUSH);
                mancopy_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        try {
                            renderer.manualCopy();
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                });
                mancopy_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean enabled = false;
                        if (!renderer.getAutoCopyToDevice()) {
                            enabled = renderer.getCopyToDevicePending() > 0;
                        }
                        mancopy_menu_item.setEnabled(enabled);
                    }
                });
            }
            if (renderer.canAutoStartDevice()) {
                need_sep = true;
                MenuItem autostart_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.autoStart");
                autostart_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                autostart_menu_item.setStyle(MenuItem.STYLE_CHECK);
                autostart_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu.setData(Boolean.valueOf(renderer.getAutoStartDevice()));
                    }
                });
                autostart_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setAutoStartDevice((Boolean) menu.getData());
                    }
                });
            }
            if (renderer.canAssociate()) {
                need_sep = true;
                final MenuItem menu_associate = menu_manager.addMenuItem("sidebar." + key, "devices.associate");
                menu_associate.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_associate.setStyle(MenuItem.STYLE_MENU);
                menu_associate.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        menu_associate.removeAllChildItems();
                        if (renderer.isAlive()) {
                            InetAddress a = renderer.getAddress();
                            String address = a == null ? "" : a.getHostAddress();
                            MenuItem menu_none = menu_manager.addMenuItem(menu_associate, "!" + MessageText.getString("devices.associate.already") + ": " + address + "!");
                            menu_none.setEnabled(false);
                            menu_associate.setEnabled(true);
                        } else {
                            UnassociatedDevice[] unassoc = device_manager.getUnassociatedDevices();
                            if (unassoc.length == 0) {
                                menu_associate.setEnabled(false);
                            } else {
                                menu_associate.setEnabled(true);
                                for (final UnassociatedDevice un : unassoc) {
                                    MenuItem menu_un = menu_manager.addMenuItem(menu_associate, "!" + un.getAddress().getHostAddress() + ": " + un.getDescription() + "!");
                                    menu_un.addListener(new MenuItemListener() {

                                        @Override
                                        public void selected(MenuItem menu, Object target) {
                                            renderer.associate(un);
                                        }
                                    });
                                }
                            }
                        }
                    }
                });
            }
            if (renderer.canRestrictAccess()) {
                need_sep = true;
                final MenuItem menu_ra = menu_manager.addMenuItem("sidebar." + key, "devices.restrict_access");
                menu_ra.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_ra.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        if (target instanceof MdiEntry) {
                            UISWTInputReceiver entry = (UISWTInputReceiver) swt_ui.getInputReceiver();
                            entry.setMessage("devices.restrict_access.msg");
                            entry.setPreenteredText(renderer.getAccessRestriction(), false);
                            entry.maintainWhitespace(false);
                            entry.allowEmptyInput(true);
                            entry.setLocalisedTitle(MessageText.getString("devices.restrict_access.prompt", new String[] { device.getName() }));
                            entry.prompt(new UIInputReceiverListener() {

                                @Override
                                public void UIInputReceiverClosed(UIInputReceiver entry) {
                                    if (!entry.hasSubmittedInput()) {
                                        return;
                                    }
                                    String input = entry.getSubmittedInput().trim();
                                    renderer.setAccessRestriction(input);
                                }
                            });
                        }
                    }
                });
            }
            final TranscodeProfile[] transcodeProfiles = renderer.getTranscodeProfiles();
            if (transcodeProfiles.length > 0) {
                Arrays.sort(transcodeProfiles, new Comparator<TranscodeProfile>() {

                    @Override
                    public int compare(TranscodeProfile o1, TranscodeProfile o2) {
                        int i1 = o1.getIconIndex();
                        int i2 = o2.getIconIndex();
                        if (i1 == i2) {
                            return o1.getName().compareToIgnoreCase(o2.getName());
                        } else {
                            return (i1 - i2);
                        }
                    }
                });
                need_sep = true;
                MenuItem menu_default_profile = menu_manager.addMenuItem("sidebar." + key, "v3.menu.device.defaultprofile");
                menu_default_profile.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                menu_default_profile.setStyle(MenuItem.STYLE_MENU);
                MenuItem menu_profile_never = menu_manager.addMenuItem(menu_default_profile, "v3.menu.device.defaultprofile.never");
                menu_profile_never.setStyle(MenuItem.STYLE_CHECK);
                menu_profile_never.setData(Boolean.TRUE);
                menu_profile_never.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setTranscodeRequirement(((Boolean) menu.getData()) ? TranscodeTarget.TRANSCODE_NEVER : TranscodeTarget.TRANSCODE_WHEN_REQUIRED);
                    }
                });
                menu_profile_never.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        boolean never = renderer.getTranscodeRequirement() == TranscodeTarget.TRANSCODE_NEVER;
                        menu.setData(never);
                    }
                });
                MenuItem menu_profile_none = menu_manager.addMenuItem(menu_default_profile, "option.askeverytime");
                menu_profile_none.setStyle(MenuItem.STYLE_RADIO);
                menu_profile_none.setData(Boolean.FALSE);
                menu_profile_none.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setDefaultTranscodeProfile(null);
                    }
                });
                menu_profile_none.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        if (transcodeProfiles.length <= 1) {
                            menu.setData(Boolean.FALSE);
                            menu.setEnabled(false);
                        } else {
                            TranscodeProfile profile = null;
                            try {
                                profile = renderer.getDefaultTranscodeProfile();
                            } catch (TranscodeException e) {
                            }
                            menu.setData((profile == null) ? Boolean.TRUE : Boolean.FALSE);
                            menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
                        }
                    }
                });
                for (final TranscodeProfile profile : transcodeProfiles) {
                    MenuItem menuItem = menu_manager.addMenuItem(menu_default_profile, "!" + profile.getName() + "!");
                    menuItem.setStyle(MenuItem.STYLE_RADIO);
                    menuItem.setData(Boolean.FALSE);
                    menuItem.addListener(new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            renderer.setDefaultTranscodeProfile(profile);
                        }
                    });
                    menuItem.addFillListener(new MenuItemFillListener() {

                        @Override
                        public void menuWillBeShown(MenuItem menu, Object data) {
                            if (transcodeProfiles.length <= 1) {
                                menu.setData(Boolean.TRUE);
                                menu.setEnabled(false);
                            } else {
                                TranscodeProfile dprofile = null;
                                try {
                                    dprofile = renderer.getDefaultTranscodeProfile();
                                } catch (TranscodeException e) {
                                }
                                menu.setData((profile.equals(dprofile)) ? Boolean.TRUE : Boolean.FALSE);
                                menu.setEnabled(renderer.getTranscodeRequirement() != TranscodeTarget.TRANSCODE_NEVER);
                            }
                        }
                    });
                }
            }
            if (true) {
                need_sep = true;
                final MenuItem rss_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.rsspub");
                rss_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                rss_menu_item.setStyle(MenuItem.STYLE_CHECK);
                rss_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
                        menu.setData(Boolean.valueOf(device_manager.isRSSPublishEnabled() && renderer.isRSSPublishEnabled()));
                    }
                });
                rss_menu_item.addListener(new MenuItemListener() {

                    @Override
                    public void selected(MenuItem menu, Object target) {
                        renderer.setRSSPublishEnabled((Boolean) menu.getData());
                    }
                });
                rss_menu_item.setEnabled(device_manager.isRSSPublishEnabled());
            }
            if (true) {
                need_sep = true;
                final MenuItem aswt_menu_item = menu_manager.addMenuItem("sidebar." + key, "devices.xcode.tagshare");
                aswt_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                aswt_menu_item.setStyle(MenuItem.STYLE_MENU);
                aswt_menu_item.addFillListener(new MenuItemFillListener() {

                    @Override
                    public void menuWillBeShown(MenuItem menu, Object data) {
                        addTagSubMenu(menu_manager, menu, renderer);
                    }
                });
            }
        }
        if (device.isBrowsable()) {
            need_sep = true;
            MenuItem browse_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.browse");
            browse_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            browse_menu_item.setStyle(MenuItem.STYLE_MENU);
            browse_menu_item.addFillListener(will_browse_listener);
        }
        if (need_sep) {
            MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "s2");
            menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
        }
        // rename
        MenuItem rename_menu_item = menu_manager.addMenuItem("sidebar." + key, "MyTorrentsView.menu.rename");
        rename_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        rename_menu_item.addListener(rename_listener);
        if (device.isExportable()) {
            MenuItem export_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.export");
            export_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            export_item.addListener(export_listener);
        }
        // hide
        MenuItem hide_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.hide");
        hide_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        hide_menu_item.addListener(hide_listener);
        // tag
        MenuItem tag_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.tag");
        tag_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        tag_menu_item.setStyle(MenuItem.STYLE_CHECK);
        tag_menu_item.addFillListener(will_tag_listener);
        tag_menu_item.addListener(tag_listener);
        // remove
        MenuItem remove_menu_item = menu_manager.addMenuItem("sidebar." + key, "MySharesView.menu.remove");
        remove_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        remove_menu_item.addFillListener(will_remove_listener);
        remove_menu_item.addListener(remove_listener);
        // sep
        MenuItem menu_item_sep = menu_manager.addMenuItem("sidebar." + key, "s3");
        menu_item_sep.setStyle(MenuItem.STYLE_SEPARATOR);
        menu_item_sep.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        final URL wiki_url = device.getWikiURL();
        if (wiki_url != null) {
            MenuItem wiki_menu_item = menu_manager.addMenuItem("sidebar." + key, "device.wiki");
            wiki_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            wiki_menu_item.addListener(new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    Utils.launch(wiki_url.toExternalForm());
                }
            });
        }
        // props
        MenuItem menu_item = menu_manager.addMenuItem("sidebar." + key, "Subscription.menu.properties");
        menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menu_item.addListener(properties_listener);
    }
}
Also used : DiskManagerFileInfoURL(com.biglybt.core.download.DiskManagerFileInfoURL) URL(java.net.URL) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Point(org.eclipse.swt.graphics.Point) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) File(java.io.File) DiskManagerFileInfoFile(com.biglybt.core.download.DiskManagerFileInfoFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) InetAddress(java.net.InetAddress)

Example 9 with MenuItemFillListener

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

the class DeviceManagerUI method setupMenuListeners.

protected void setupMenuListeners() {
    properties_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Device device = (Device) info.getDatasource();
                showProperties(device);
            }
        }
    };
    hide_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Device device = (Device) info.getDatasource();
                device.setHidden(true);
            }
        }
    };
    will_tag_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object targets) {
            Object[] rows;
            if (targets instanceof Object[]) {
                rows = (Object[]) targets;
            } else {
                rows = new Object[] { targets };
            }
            if (rows.length > 0 && rows[0] instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) rows[0];
                Device device = (Device) info.getDatasource();
                menu.setData(device.isTagged());
            } else {
                menu.setEnabled(false);
            }
        }
    };
    tag_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Device device = (Device) info.getDatasource();
                device.setTagged(!device.isTagged());
            }
        }
    };
    rename_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                final Device device = (Device) info.getDatasource();
                UISWTInputReceiver entry = (UISWTInputReceiver) swt_ui.getInputReceiver();
                entry.setPreenteredText(device.getName(), false);
                entry.maintainWhitespace(false);
                entry.allowEmptyInput(false);
                entry.setLocalisedTitle(MessageText.getString("label.rename", new String[] { device.getName() }));
                entry.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver entry) {
                        if (!entry.hasSubmittedInput()) {
                            return;
                        }
                        String input = entry.getSubmittedInput().trim();
                        if (input.length() > 0) {
                            device.setName(input, false);
                        }
                    }
                });
            }
        }
    };
    export_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Device device = (Device) info.getDatasource();
                export(device);
            }
        }
    };
    will_remove_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object targets) {
            Object[] rows;
            if (targets instanceof Object[]) {
                rows = (Object[]) targets;
            } else {
                rows = new Object[] { targets };
            }
            if (rows.length > 0 && rows[0] instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) rows[0];
                Device device = (Device) info.getDatasource();
                menu.setEnabled(device.canRemove());
            } else {
                menu.setEnabled(false);
            }
        }
    };
    remove_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Device device = (Device) info.getDatasource();
                device.remove();
            }
        }
    };
    will_browse_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object targets) {
            menu.removeAllChildItems();
            boolean enabled = false;
            Object[] rows;
            if (targets instanceof Object[]) {
                rows = (Object[]) targets;
            } else {
                rows = new Object[] { targets };
            }
            if (rows.length > 0 && rows[0] instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) rows[0];
                Device device = (Device) info.getDatasource();
                Device.browseLocation[] locs = device.getBrowseLocations();
                enabled = locs != null && locs.length > 0;
                if (enabled) {
                    MenuManager menuManager = ui_manager.getMenuManager();
                    for (final Device.browseLocation loc : locs) {
                        MenuItem loc_menu = menuManager.addMenuItem(menu, loc.getName());
                        loc_menu.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                Utils.launch(loc.getURL().toExternalForm());
                            }
                        });
                    }
                }
            }
            menu.setEnabled(enabled);
        }
    };
    show_listener = new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            if (target instanceof MdiEntry) {
                MdiEntry info = (MdiEntry) target;
                Object ds = info.getDatasource();
                if (ds instanceof Device) {
                    // shouldn't get here really as its hidden :)
                    Device device = (Device) ds;
                    device.setHidden(true);
                } else {
                    int category_type = ds == null ? Device.DT_UNKNOWN : (Integer) ds;
                    Device[] devices = device_manager.getDevices();
                    for (Device device : devices) {
                        if (category_type == Device.DT_UNKNOWN || device.getType() == category_type && device.isHidden()) {
                            device.setHidden(false);
                        }
                    }
                }
            }
        }
    };
    show_fill_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object targets) {
            boolean enabled = false;
            Object[] rows;
            if (targets instanceof Object[]) {
                rows = (Object[]) targets;
            } else {
                rows = new Object[] { targets };
            }
            for (Object row : rows) {
                if (row instanceof MdiEntry) {
                    MdiEntry info = (MdiEntry) row;
                    Object ds = info.getDatasource();
                    if (ds instanceof Device) {
                    } else {
                        int category_type = ds == null ? Device.DT_UNKNOWN : (Integer) ds;
                        Device[] devices = device_manager.getDevices();
                        for (Device device : devices) {
                            if (category_type == Device.DT_UNKNOWN || device.getType() == category_type && device.isHidden()) {
                                if (device.isHidden()) {
                                    enabled = true;
                                }
                            }
                        }
                    }
                }
            }
            menu.setEnabled(enabled);
        }
    };
}
Also used : UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener)

Example 10 with MenuItemFillListener

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

the class TabbedMDI method addMenus.

private void addMenus(TabbedEntry entry, String id) {
    PluginManager pm = CoreFactory.getSingleton().getPluginManager();
    PluginInterface pi = pm.getDefaultPluginInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    {
        if (!Utils.isAZ2UI()) {
            com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.add.to.dashboard");
            menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
            menuItem.addFillListener(new MenuItemFillListener() {

                @Override
                public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    // pick up the right target - due to the confusion of multiple tab instances registering
                    // the same menu entries the original registerer may well not be the one that should receive the event,
                    // rather the one specified in the event is
                    TabbedEntry target = entry;
                    if (data instanceof Object[]) {
                        Object[] odata = (Object[]) data;
                        if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                            target = (TabbedEntry) odata[0];
                        }
                    }
                    menu.setVisible(target.canBuildStandAlone());
                }
            });
            menuItem.addListener(new MenuItemListener() {

                @Override
                public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                    TabbedEntry target = entry;
                    if (data instanceof Object[]) {
                        Object[] odata = (Object[]) data;
                        if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                            target = (TabbedEntry) odata[0];
                        }
                    } else if (data instanceof TabbedEntry) {
                        target = (TabbedEntry) data;
                    }
                    MainMDISetup.getSb_dashboard().addItem(target);
                }
            });
        }
    }
    {
        com.biglybt.pif.ui.menus.MenuItem menuItem = menuManager.addMenuItem(id + "._end_", "menu.pop.out");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

            @Override
            public void menuWillBeShown(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                TabbedEntry target = entry;
                if (data instanceof Object[]) {
                    Object[] odata = (Object[]) data;
                    if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                        target = (TabbedEntry) odata[0];
                    }
                }
                menu.setVisible(target.canBuildStandAlone());
            }
        });
        menuItem.addListener(new com.biglybt.pif.ui.menus.MenuItemListener() {

            @Override
            public void selected(com.biglybt.pif.ui.menus.MenuItem menu, Object data) {
                TabbedEntry target = entry;
                if (data instanceof Object[]) {
                    Object[] odata = (Object[]) data;
                    if (odata.length == 1 && odata[0] instanceof TabbedEntry) {
                        target = (TabbedEntry) odata[0];
                    }
                } else if (data instanceof TabbedEntry) {
                    target = (TabbedEntry) data;
                }
                SkinnedDialog skinnedDialog = new SkinnedDialog("skin3_dlg_sidebar_popout", "shell", // standalone
                null, SWT.RESIZE | SWT.MAX | SWT.DIALOG_TRIM);
                SWTSkin skin = skinnedDialog.getSkin();
                SWTSkinObjectContainer cont = target.buildStandAlone((SWTSkinObjectContainer) skin.getSkinObject("content-area"));
                if (cont != null) {
                    Object ds = target.getDatasource();
                    if (ds instanceof Object[]) {
                        Object[] temp = (Object[]) ds;
                        if (temp.length > 0) {
                            ds = temp[0];
                        }
                    }
                    String ds_str = "";
                    if (ds instanceof Download) {
                        ds_str = ((Download) ds).getName();
                    } else if (ds instanceof DownloadManager) {
                        ds_str = ((DownloadManager) ds).getDisplayName();
                    }
                    skinnedDialog.setTitle(target.getTitle() + (ds_str.length() == 0 ? "" : (" - " + ds_str)));
                    skinnedDialog.open();
                } else {
                    skinnedDialog.close();
                }
            }
        });
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) PluginManager(com.biglybt.pif.PluginManager) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SkinnedDialog(com.biglybt.ui.swt.views.skin.SkinnedDialog) Download(com.biglybt.pif.download.Download)

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