Search in sources :

Example 11 with MenuItemListener

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

the class SBC_ActivityTableView method setupSidebarEntry.

public static void setupSidebarEntry(final MultipleDocumentInterface mdi) {
    // Put TitleInfo in another class
    final ViewTitleInfo titleInfoActivityView = new ViewTitleInfo() {

        boolean had_unviewed = false;

        @Override
        public Object getTitleInfoProperty(int propertyID) {
            if (propertyID == TITLE_INDICATOR_TEXT) {
                int num_unread = 0;
                int num_unviewed = 0;
                List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
                for (ActivitiesEntry entry : allEntries) {
                    if (!entry.isRead()) {
                        num_unread++;
                    }
                    if (!entry.getViewed()) {
                        num_unviewed++;
                    }
                }
                if (num_unread == 0) {
                    num_unviewed = 0;
                }
                boolean has_unviewed = num_unviewed > 0;
                if (has_unviewed != had_unviewed) {
                    if (has_unviewed) {
                        MdiEntry parent = mdi.getEntry(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE);
                        if (parent != null && !parent.isExpanded()) {
                            parent.setExpanded(true);
                        }
                    }
                    had_unviewed = has_unviewed;
                }
                if (num_unviewed > 0) {
                    return (String.valueOf(num_unviewed) + (num_unread == 0 ? "" : (":" + num_unread)));
                } else if (num_unread > 0) {
                    return (String.valueOf(num_unread));
                }
                return null;
            } else if (propertyID == TITLE_IMAGEID) {
                return "image.sidebar.activity";
            } else if (propertyID == TITLE_INDICATOR_COLOR) {
                boolean has_unread = false;
                boolean has_unviewed = false;
                List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
                for (ActivitiesEntry entry : allEntries) {
                    if (!entry.isRead()) {
                        has_unread = true;
                    }
                    if (!entry.getViewed()) {
                        has_unviewed = true;
                    }
                }
                if (has_unread && has_unviewed) {
                    return (COLOR_UNVIEWED_ENTRIES);
                }
            }
            return null;
        }
    };
    activitiesListener = new ActivitiesListener() {

        @Override
        public void vuzeNewsEntryChanged(ActivitiesEntry entry) {
            refresh();
        }

        @Override
        public void vuzeNewsEntriesRemoved(ActivitiesEntry[] entries) {
            refresh();
        }

        @Override
        public void vuzeNewsEntriesAdded(ActivitiesEntry[] entries) {
            refresh();
        }

        private void refresh() {
            ViewTitleInfoManager.refreshTitleInfo(titleInfoActivityView);
            if (mdi_entry != null) {
                mdi_entry.redraw();
            }
        }
    };
    ActivitiesManager.addListener(activitiesListener);
    MdiEntryCreationListener creationListener = new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_VUZE, MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "activity", "{sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES + "}", titleInfoActivityView, null, false, null);
            return (mdi_entry);
        }
    };
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, creationListener);
    mdi.registerEntry("activities", creationListener);
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    UIManager uim = pi.getUIManager();
    MenuManager menuManager = uim.getMenuManager();
    final MenuItem menuItem = menuManager.addMenuItem("sidebar." + MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES, "v3.activity.button.readall");
    menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    menuItem.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            List<ActivitiesEntry> allEntries = ActivitiesManager.getAllEntries();
            for (ActivitiesEntry entry : allEntries) {
                entry.setRead(true);
            }
        }
    });
    mdi.addListener(new MdiListener() {

        @Override
        public void mdiEntrySelected(MdiEntry newEntry, MdiEntry oldEntry) {
        }

        @Override
        public void mdiDisposed(MultipleDocumentInterface mdi) {
            if (activitiesListener != null) {
                ActivitiesManager.removeListener(activitiesListener);
                activitiesListener = null;
            }
            menuItem.remove();
        }
    });
}
Also used : ActivitiesListener(com.biglybt.activities.ActivitiesListener) MdiListener(com.biglybt.ui.mdi.MdiListener) MdiEntryCreationListener(com.biglybt.ui.mdi.MdiEntryCreationListener) PluginInterface(com.biglybt.pif.PluginInterface) UIManager(com.biglybt.pif.ui.UIManager) MenuItem(com.biglybt.pif.ui.menus.MenuItem) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) MdiEntry(com.biglybt.ui.mdi.MdiEntry) MenuManager(com.biglybt.pif.ui.menus.MenuManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) ArrayList(java.util.ArrayList) List(java.util.List) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)

Example 12 with MenuItemListener

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

the class PMSWTImpl method initialise.

@Override
public void initialise(final PluginInterface pi, final BooleanParameter icon_enable) {
    final NetworkAdmin na = NetworkAdmin.getSingleton();
    na.addPropertyChangeListener(new NetworkAdminPropertyChangeListener() {

        @Override
        public void propertyChanged(String property) {
            if (property == NetworkAdmin.PR_NETWORK_INTERFACES) {
                updateLocalAddresses(na);
            }
        }
    });
    updateLocalAddresses(na);
    pi.getUIManager().addUIListener(new UIManagerListener() {

        @Override
        public void UIAttached(final UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = true;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null) {
                    uiUpdaterListener = new UIUpdaterListener() {

                        @Override
                        public void updateComplete(int count) {
                            last_update_count = count;
                            updateStatus(true);
                        }
                    };
                    uif.getUIUpdater().addListener(uiUpdaterListener);
                }
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        ImageLoader imageLoader = ImageLoader.getInstance();
                        icon_idle = imageLoader.getImage("pair_sb_idle");
                        icon_green = imageLoader.getImage("pair_sb_green");
                        icon_red = imageLoader.getImage("pair_sb_red");
                        UISWTInstance ui_instance = (UISWTInstance) instance;
                        status = ui_instance.createStatusEntry();
                        last_tooltip_text = MessageText.getString("pairing.ui.icon.tip");
                        Utils.setTT(status, last_tooltip_text);
                        status.setImageEnabled(true);
                        status.setImage(icon_idle);
                        last_image = icon_idle;
                        boolean is_visible = icon_enable.getValue();
                        status.setVisible(is_visible);
                        if (is_visible) {
                            updateStatus(false);
                        }
                        final MenuItem mi_show = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "pairing.ui.icon.show");
                        mi_show.setStyle(MenuItem.STYLE_CHECK);
                        mi_show.setData(Boolean.valueOf(is_visible));
                        mi_show.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                icon_enable.setValue(false);
                            }
                        });
                        iconEnableListener = new ParameterListener() {

                            @Override
                            public void parameterChanged(Parameter param) {
                                boolean is_visible = icon_enable.getValue();
                                status.setVisible(is_visible);
                                mi_show.setData(Boolean.valueOf(is_visible));
                                if (is_visible) {
                                    updateStatus(false);
                                }
                            }
                        };
                        icon_enable.addListener(iconEnableListener);
                        MenuItem mi_pairing = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.pairing");
                        mi_pairing.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif == null) {
                                    Debug.out("UIFunctions not available, can't open remote pairing window");
                                } else {
                                    uif.openRemotePairingWindow();
                                }
                            }
                        });
                        MenuItem mi_sep = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "");
                        mi_sep.setStyle(MenuItem.STYLE_SEPARATOR);
                        MenuItem mi_options = pi.getUIManager().getMenuManager().addMenuItem(status.getMenuContext(), "MainWindow.menu.view.configuration");
                        mi_options.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        });
                        UISWTStatusEntryListener click_listener = new UISWTStatusEntryListener() {

                            @Override
                            public void entryClicked(UISWTStatusEntry entry) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, PairingManager.CONFIG_SECTION_ID);
                                }
                            }
                        };
                        status.setListener(click_listener);
                    }
                });
            }
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance instanceof UISWTInstance) {
                ui_attached = false;
                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                if (uif != null && uiUpdaterListener != null) {
                    uif.getUIUpdater().removeListener(uiUpdaterListener);
                    uiUpdaterListener = null;
                }
                if (status != null) {
                    // menu items get destroyed with this call
                    status.destroy();
                    status = null;
                }
                if (icon_enable != null && iconEnableListener != null) {
                    icon_enable.removeListener(iconEnableListener);
                    iconEnableListener = null;
                }
            }
        }
    });
}
Also used : UIUpdaterListener(com.biglybt.ui.common.updater.UIUpdater.UIUpdaterListener) UISWTStatusEntryListener(com.biglybt.ui.swt.pif.UISWTStatusEntryListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) NetworkAdminPropertyChangeListener(com.biglybt.core.networkmanager.admin.NetworkAdminPropertyChangeListener) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) UIFunctions(com.biglybt.ui.UIFunctions) UISWTStatusEntry(com.biglybt.ui.swt.pif.UISWTStatusEntry) ParameterListener(com.biglybt.pif.ui.config.ParameterListener) BooleanParameter(com.biglybt.pif.ui.config.BooleanParameter) Parameter(com.biglybt.pif.ui.config.Parameter) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) UIInstance(com.biglybt.pif.ui.UIInstance)

Example 13 with MenuItemListener

use of com.biglybt.pif.ui.menus.MenuItemListener 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 MenuItemListener

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

the class MainMDISetup method setupSideBar.

public static void setupSideBar(final MultipleDocumentInterfaceSWT mdi) {
    mdi.setDefaultEntryID(SideBar.SIDEBAR_SECTION_LIBRARY);
    if (Utils.isAZ2UI()) {
        setupSidebarClassic(mdi);
    } else {
        setupSidebarVuzeUI(mdi);
    }
    SBC_TorrentDetailsView.TorrentDetailMdiEntry.register(mdi);
    configBetaEnabledListener = new ParameterListener() {

        @Override
        public void parameterChanged(String parameterName) {
            boolean enabled = COConfigurationManager.getBooleanParameter("Beta Programme Enabled");
            if (enabled) {
                boolean closed = COConfigurationManager.getBooleanParameter("Beta Programme Sidebar Closed");
                if (!closed) {
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_BETAPROGRAM, false);
                }
            }
        }
    };
    COConfigurationManager.addAndFireParameterListener("Beta Programme Enabled", configBetaEnabledListener);
    // Note: We don't use ViewManagerSWT because it adds a menu item, and we
    // manually do that for StatsView and others
    // ViewManagerSWT vi = ViewManagerSWT.getInstance();
    // vi.registerView(VIEW_MAIN,
    // new UISWTViewBuilderCore(StatsView.VIEW_ID, null, StatsView.class)
    // .setParentEntryID(SIDEBAR_HEADER_PLUGINS));
    mdi.registerEntry(StatsView.VIEW_ID, id -> {
        MdiEntry entry = mdi.createEntry(new UISWTViewBuilderCore(id, null, StatsView.class).setParentEntryID(MultipleDocumentInterface.SIDEBAR_HEADER_PLUGINS), true);
        entry.setImageLeftID("image.sidebar.stats2");
        return (entry);
    });
    mdi.registerEntry(SIDEBAR_SECTION_ALLPEERS, id -> {
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, PeersSuperView.class);
        builder.setParentEntryID(SIDEBAR_HEADER_TRANSFERS);
        builder.setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, SIDEBAR_SECTION_ALLPEERS));
        MdiEntry entry = mdi.createEntry(builder, true);
        PeerControlScheduler scheduler = PeerControlSchedulerFactory.getSingleton(0);
        ViewTitleInfo title_info = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int propertyID) {
                if (propertyID == TITLE_INDICATOR_TEXT) {
                    int[] counts = scheduler.getPeerCount();
                    return (counts[0] + " | " + counts[1]);
                }
                return (null);
            }
        };
        entry.setViewTitleInfo(title_info);
        entry.setImageLeftID("image.sidebar.allpeers");
        final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:allpeers", 1 * 1000, new TimerEventPerformer() {

            private int last_count1 = -1;

            private int last_count2 = -1;

            @Override
            public void perform(TimerEvent event) {
                int[] counts = scheduler.getPeerCount();
                int c1 = counts[0];
                int c2 = counts[1];
                if (c1 != last_count1 || c2 != last_count2) {
                    last_count1 = c1;
                    last_count2 = c2;
                    entry.redraw();
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                    entry.redraw();
                }
            }
        });
        entry.addListener(new MdiCloseListener() {

            @Override
            public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                timer.cancel();
            }
        });
        return (entry);
    });
    mdi.registerEntry(SIDEBAR_SECTION_ALLPIECES, id -> {
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, PiecesSuperView.class);
        builder.setParentEntryID(SIDEBAR_HEADER_TRANSFERS);
        builder.setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, SIDEBAR_SECTION_ALLPIECES));
        MdiEntrySWT entry = mdi.createEntry(builder, true);
        PeerControlScheduler scheduler = PeerControlSchedulerFactory.getSingleton(0);
        ViewTitleInfo title_info = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int propertyID) {
                if (propertyID == TITLE_INDICATOR_TEXT) {
                    int[] counts = scheduler.getPieceCount();
                    UISWTViewEventListener listener = entry.getEventListener();
                    if (listener instanceof PiecesViewBase) {
                        int count = ((PiecesViewBase) listener).getUploadingPieceCount();
                        if (count >= 0) {
                            counts[1] = count;
                        }
                    }
                    return (counts[0] + " | " + counts[1]);
                }
                return (null);
            }
        };
        entry.setViewTitleInfo(title_info);
        entry.setImageLeftID("image.sidebar.allpieces");
        final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:allpieces", 1 * 1000, new TimerEventPerformer() {

            private int last_count1 = -1;

            private int last_count2 = -1;

            @Override
            public void perform(TimerEvent event) {
                int[] counts = scheduler.getPieceCount();
                UISWTViewEventListener listener = entry.getEventListener();
                if (listener instanceof PiecesViewBase) {
                    int count = ((PiecesViewBase) listener).getUploadingPieceCount();
                    if (count >= 0) {
                        counts[1] = count;
                    }
                }
                int c1 = counts[0];
                int c2 = counts[1];
                if (c1 != last_count1 || c2 != last_count2) {
                    last_count1 = c1;
                    last_count2 = c2;
                    entry.redraw();
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                    entry.redraw();
                }
            }
        });
        entry.addListener(new MdiCloseListener() {

            @Override
            public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                timer.cancel();
            }
        });
        return (entry);
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_LOGGER, id -> {
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, LoggerView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS);
        return mdi.createEntry(builder, true);
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, id, "tagsview", "{tags.view.heading}", null, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_TAGS));
            entry.setImageLeftID("image.sidebar.tag-overview");
            entry.setDefaultExpanded(true);
            TagManager tm = TagManagerFactory.getTagManager();
            ViewTitleInfo2 title_info = new ViewTitleInfo2() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = 0;
                        for (TagType tt : tm.getTagTypes()) {
                            num += tt.getTagCount();
                        }
                        return (String.valueOf(num));
                    }
                    return (null);
                }

                public void titleInfoLinked(MultipleDocumentInterface mdi, MdiEntry mdiEntry) {
                }

                public MdiEntry getLinkedMdiEntry() {
                    return (entry);
                }
            };
            entry.setViewTitleInfo(title_info);
            TagTypeListener ttl = new TagTypeListener() {

                public void tagTypeChanged(TagType tag_type) {
                }

                public void tagEventOccurred(TagEvent event) {
                    int type = event.getEventType();
                    if (type == TagEvent.ET_TAG_ADDED || type == TagEvent.ET_TAG_REMOVED) {
                        ViewTitleInfoManager.refreshTitleInfo(title_info);
                    }
                }
            };
            TagManagerListener tml = new TagManagerListener() {

                public void tagTypeAdded(TagManager manager, TagType tag_type) {
                    tag_type.addTagTypeListener(ttl, false);
                }

                public void tagTypeRemoved(TagManager manager, TagType tag_type) {
                }
            };
            tm.addTagManagerListener(tml, true);
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    tm.removeTagManagerListener(tml);
                    for (TagType tt : tm.getTagTypes()) {
                        tt.removeTagTypeListener(ttl);
                    }
                }
            });
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            MdiEntry entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS, id, "tagdiscoveryview", "{mdi.entry.tagdiscovery}", null, null, true, null);
            entry.setImageLeftID("image.sidebar.tag-overview");
            return entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    BuddyPluginBeta bp = BuddyPluginUtils.getBetaPlugin();
                    if (bp == null) {
                        return (null);
                    }
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = 0;
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                num++;
                            }
                        }
                        if (num > 0) {
                            return (String.valueOf(num));
                        } else {
                            return (null);
                        }
                    } else if (propertyID == TITLE_INDICATOR_COLOR) {
                        for (ChatInstance chat : bp.getChats()) {
                            if (chat.getMessageOutstanding()) {
                                if (chat.hasUnseenMessageWithNick()) {
                                    return (SBC_ChatOverview.COLOR_MESSAGE_WITH_NICK);
                                }
                            }
                        }
                    }
                    return null;
                }
            };
            MdiEntry mdi_entry = mdi.createEntryFromSkinRef(MultipleDocumentInterface.SIDEBAR_HEADER_DISCOVERY, MultipleDocumentInterface.SIDEBAR_SECTION_CHAT, "chatsview", "{mdi.entry.chatsoverview}", title_info, null, true, MultipleDocumentInterface.SIDEBAR_SECTION_SUBSCRIPTIONS);
            mdi_entry.setImageLeftID("image.sidebar.chat-overview");
            final TimerEventPeriodic timer = SimpleTimer.addPeriodicEvent("sb:chatup", 5 * 1000, new TimerEventPerformer() {

                private String last_text;

                private int[] last_colour;

                @Override
                public void perform(TimerEvent event) {
                    String text = (String) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT);
                    int[] colour = (int[]) title_info.getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_COLOR);
                    boolean changed = text != last_text && (text == null || last_text == null || !text.equals(last_text));
                    if (!changed) {
                        changed = colour != last_colour && (colour == null || last_colour == null || !Arrays.equals(colour, last_colour));
                    }
                    if (changed) {
                        last_text = text;
                        last_colour = colour;
                        mdi_entry.redraw();
                    }
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                }
            });
            mdi_entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    timer.cancel();
                }
            });
            return mdi_entry;
        }
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final com.biglybt.pif.download.DownloadManager download_manager = PluginInitializer.getDefaultInterface().getDownloadManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        int num = download_manager.getDownloadStubCount();
                        return (String.valueOf(num));
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS, "archivedlsview", "{mdi.entry.archiveddownloadsview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS));
            entry.setImageLeftID("image.sidebar.archive");
            final DownloadStubListener stub_listener = new DownloadStubListener() {

                @Override
                public void downloadStubEventOccurred(DownloadStubEvent event) {
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                    entry.redraw();
                }
            };
            download_manager.addDownloadStubListener(stub_listener, false);
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    download_manager.removeDownloadStubListener(stub_listener);
                }
            });
            entry.addListener(new MdiEntryDropListener() {

                @Override
                public boolean mdiEntryDrop(MdiEntry entry, Object data) {
                    if (data instanceof String) {
                        String str = (String) data;
                        if (str.startsWith("DownloadManager\n")) {
                            String[] bits = str.split("\n");
                            com.biglybt.pif.download.DownloadManager dm = PluginInitializer.getDefaultInterface().getDownloadManager();
                            List<Download> downloads = new ArrayList<>();
                            boolean failed = false;
                            for (int i = 1; i < bits.length; i++) {
                                byte[] hash = Base32.decode(bits[i]);
                                try {
                                    Download download = dm.getDownload(hash);
                                    if (download.canStubbify()) {
                                        downloads.add(download);
                                    } else {
                                        failed = true;
                                    }
                                } catch (Throwable e) {
                                }
                            }
                            final boolean f_failed = failed;
                            ManagerUtils.moveToArchive(downloads, new ManagerUtils.ArchiveCallback() {

                                boolean error = f_failed;

                                @Override
                                public void failed(DownloadStub original, Throwable e) {
                                    error = true;
                                }

                                @Override
                                public void completed() {
                                    if (error) {
                                        String title = MessageText.getString("archive.failed.title");
                                        String text = MessageText.getString("archive.failed.text");
                                        MessageBoxShell prompter = new MessageBoxShell(title, text, new String[] { MessageText.getString("Button.ok") }, 0);
                                        prompter.setAutoCloseInMS(0);
                                        prompter.open(null);
                                    }
                                }
                            });
                        }
                        return (true);
                    }
                    return false;
                }
            });
            return entry;
        }
    });
    // download history
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            final DownloadHistoryManager history_manager = (DownloadHistoryManager) CoreFactory.getSingleton().getGlobalManager().getDownloadHistoryManager();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        if (history_manager == null) {
                            return (null);
                        } else if (history_manager.isEnabled()) {
                            int num = history_manager.getHistoryCount();
                            return (String.valueOf(num));
                        } else {
                            return (MessageText.getString("label.disabled"));
                        }
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY, "downloadhistoryview", "{mdi.entry.downloadhistoryview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY));
            entry.setImageLeftID("image.sidebar.logview");
            if (history_manager != null) {
                final DownloadHistoryListener history_listener = new DownloadHistoryListener() {

                    @Override
                    public void downloadHistoryEventOccurred(DownloadHistoryEvent event) {
                        ViewTitleInfoManager.refreshTitleInfo(title_info);
                    }
                };
                history_manager.addListener(history_listener, false);
                entry.addListener(new MdiCloseListener() {

                    @Override
                    public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                        history_manager.removeListener(history_listener);
                    }
                });
            }
            return entry;
        }
    });
    // all trackers
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS, new MdiEntryCreationListener() {

        @Override
        public MdiEntry createMDiEntry(String id) {
            AllTrackers all_trackers = AllTrackersManager.getAllTrackers();
            final ViewTitleInfo title_info = new ViewTitleInfo() {

                @Override
                public Object getTitleInfoProperty(int propertyID) {
                    if (propertyID == TITLE_INDICATOR_TEXT) {
                        return (String.valueOf(all_trackers.getTrackerCount()));
                    }
                    return null;
                }
            };
            MdiEntry entry = mdi.createEntryFromSkinRef(SIDEBAR_HEADER_TRANSFERS, MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS, "alltrackersview", "{mdi.entry.alltrackersview}", title_info, null, true, SB_Transfers.getSectionPosition(mdi, MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS));
            entry.setImageLeftID("image.sidebar.alltrackers");
            AllTrackersListener at_listener = new AllTrackersListener() {

                @Override
                public void trackerEventOccurred(AllTrackersEvent event) {
                    int type = event.getEventType();
                    if (type == AllTrackersEvent.ET_TRACKER_ADDED || type == AllTrackersEvent.ET_TRACKER_REMOVED) {
                        ViewTitleInfoManager.refreshTitleInfo(title_info);
                    }
                }
            };
            all_trackers.addListener(at_listener, false);
            entry.addListener(new MdiCloseListener() {

                @Override
                public void mdiEntryClosed(MdiEntry entry, boolean userClosed) {
                    all_trackers.removeListener(at_listener);
                }
            });
            return entry;
        }
    });
    // torrent options
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_OPTIONS, id -> {
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, TorrentOptionsView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
        MdiEntry entry = mdi.createEntry(builder, true);
        entry.setImageLeftID("image.sidebar.torrentoptions");
        return entry;
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, id -> {
        final ShareManager sm;
        {
            ShareManager temp;
            try {
                temp = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getShareManager();
            } catch (Throwable e) {
                temp = null;
            }
            sm = temp;
        }
        ViewTitleInfo title_info = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int propertyID) {
                if (propertyID == TITLE_INDICATOR_TEXT) {
                    return (sm == null ? null : String.valueOf(sm.getShareCount()));
                }
                return null;
            }
        };
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, MySharesView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
        MdiEntry entry = mdi.createEntry(builder, true);
        entry.setViewTitleInfo(title_info);
        entry.setImageLeftID("image.sidebar.myshares");
        if (sm != null) {
            shareManagerListener2 = new ShareManagerListener() {

                public void resourceAdded(ShareResource resource) {
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                    entry.redraw();
                }

                public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
                }

                public void resourceDeleted(ShareResource resource) {
                    ViewTitleInfoManager.refreshTitleInfo(title_info);
                    entry.redraw();
                }

                public void reportProgress(int percent_complete) {
                }

                public void reportCurrentTask(String task_description) {
                }
            };
            sm.addListener(shareManagerListener2);
        }
        return entry;
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, id -> {
        TRHost trackerHost = CoreFactory.getSingleton().getTrackerHost();
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, MyTrackerView.class).setParentEntryID(SIDEBAR_HEADER_TRANSFERS).setPreferredAfterID(SB_Transfers.getSectionPosition(mdi, id));
        MdiEntry entry = mdi.createEntry(builder, true);
        entry.setImageLeftID("image.sidebar.mytracker");
        ViewTitleInfo title_info = new ViewTitleInfo() {

            @Override
            public Object getTitleInfoProperty(int propertyID) {
                if (propertyID == TITLE_INDICATOR_TEXT) {
                    return (String.valueOf(trackerHost.getTorrentCount()));
                }
                return null;
            }
        };
        entry.setViewTitleInfo(title_info);
        trackerHostListener2 = new TRHostListener() {

            @Override
            public void torrentRemoved(TRHostTorrent t) {
                ViewTitleInfoManager.refreshTitleInfo(title_info);
                entry.redraw();
            }

            @Override
            public void torrentChanged(TRHostTorrent t) {
            }

            @Override
            public void torrentAdded(TRHostTorrent t) {
                ViewTitleInfoManager.refreshTitleInfo(title_info);
                entry.redraw();
            }

            @Override
            public boolean handleExternalRequest(InetSocketAddress client_address, String user, String url, URL absolute_url, String header, InputStream is, OutputStream os, AsyncController async) throws IOException {
                return false;
            }
        };
        trackerHost.addListener(trackerHostListener2);
        return entry;
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CLIENT_STATS, id -> {
        UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, ClientStatsView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS);
        MdiEntry entry = mdi.createEntry(builder, true);
        entry.setImageLeftID("image.sidebar.clientstats");
        return entry;
    });
    mdi.registerEntry(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, (mdi1, id, datasource, params) -> {
        String section = (datasource instanceof String) ? ((String) datasource) : null;
        if (Utils.isAZ2UI() || COConfigurationManager.getBooleanParameter("Show Options In Side Bar")) {
            UISWTViewBuilderCore builder = new UISWTViewBuilderCore(id, null, ConfigView.class).setParentEntryID(SIDEBAR_HEADER_PLUGINS).setInitialDatasource(section);
            MdiEntry entry = mdi.createEntry(builder, true);
            entry.setImageLeftID("image.sidebar.cog");
            return entry;
        }
        ConfigShell.getInstance().open(section);
        return null;
    });
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    try {
        if (!COConfigurationManager.getBooleanParameter("my.shares.view.auto.open.done", false)) {
            final ShareManager share_manager = pi.getShareManager();
            if (share_manager.getShares().length > 0) {
            // stop showing this by default
            // mdi.showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES);
            } else {
                shareManagerListener = new ShareManagerListener() {

                    boolean done = false;

                    @Override
                    public void resourceModified(ShareResource old_resource, ShareResource new_resource) {
                    }

                    @Override
                    public void resourceDeleted(ShareResource resource) {
                    }

                    @Override
                    public void resourceAdded(ShareResource resource) {
                        if (done) {
                            return;
                        }
                        done = true;
                        share_manager.removeListener(this);
                        COConfigurationManager.setParameter("my.shares.view.auto.open.done", true);
                        mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_SHARES, false);
                    }

                    @Override
                    public void reportProgress(int percent_complete) {
                    }

                    @Override
                    public void reportCurrentTask(String task_description) {
                    }
                };
                share_manager.addListener(shareManagerListener);
            }
        }
    } catch (Throwable t) {
    }
    try {
        if (!COConfigurationManager.getBooleanParameter("my.tracker.view.auto.open.done", false)) {
            // Load Tracker View on first host of file
            TRHost trackerHost = CoreFactory.getSingleton().getTrackerHost();
            trackerHostListener = new TRHostListener() {

                boolean done = false;

                @Override
                public void torrentRemoved(TRHostTorrent t) {
                }

                @Override
                public void torrentChanged(TRHostTorrent t) {
                }

                @Override
                public void torrentAdded(TRHostTorrent t) {
                    if (done) {
                        return;
                    }
                    done = true;
                    trackerHost.removeListener(this);
                    COConfigurationManager.setParameter("my.tracker.view.auto.open.done", true);
                    mdi.loadEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_MY_TRACKER, false);
                }

                @Override
                public boolean handleExternalRequest(InetSocketAddress client_address, String user, String url, URL absolute_url, String header, InputStream is, OutputStream os, AsyncController async) throws IOException {
                    return false;
                }
            };
            trackerHost.addListener(trackerHostListener);
        }
    } catch (Throwable t) {
    }
    UIManager uim = pi.getUIManager();
    if (uim != null) {
        MenuItem menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tags.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAGS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "tag.discovery.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TAG_DISCOVERY);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "chats.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CHAT);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "archivedlsview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ARCHIVED_DOWNLOADS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "downloadhistoryview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_DOWNLOAD_HISTORY);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "alltrackersview.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ALL_TRACKERS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "MainWindow.menu.view.allpeers");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPEERS);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "MainWindow.menu.view.allpieces");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ALLPIECES);
            }
        });
        menuItem = uim.getMenuManager().addMenuItem(MenuManager.MENU_MENUBAR, "diskops.view.heading");
        menuItem.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        menuItem.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_DISK_OPS);
            }
        });
    }
// System.out.println("Activate sidebar " + startTab + " took "
// + (SystemTime.getCurrentTime() - startTime) + "ms");
// startTime = SystemTime.getCurrentTime();
}
Also used : DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) UIManager(com.biglybt.pif.ui.UIManager) com.biglybt.pif.download(com.biglybt.pif.download) AllTrackersEvent(com.biglybt.core.tracker.AllTrackersManager.AllTrackersEvent) UISWTViewBuilderCore(com.biglybt.ui.swt.pifimpl.UISWTViewBuilderCore) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) MultipleDocumentInterface(com.biglybt.ui.mdi.MultipleDocumentInterface) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) TagType(com.biglybt.core.tag.TagType) TagManagerListener(com.biglybt.core.tag.TagManagerListener) TRHost(com.biglybt.core.tracker.host.TRHost) DownloadHistoryListener(com.biglybt.core.history.DownloadHistoryListener) ViewTitleInfo(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo) ManagerUtils(com.biglybt.ui.swt.views.utils.ManagerUtils) URL(java.net.URL) DownloadHistoryEvent(com.biglybt.core.history.DownloadHistoryEvent) BuddyPluginBeta(com.biglybt.plugin.net.buddy.BuddyPluginBeta) AllTrackers(com.biglybt.core.tracker.AllTrackersManager.AllTrackers) InputStream(java.io.InputStream) PluginInterface(com.biglybt.pif.PluginInterface) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) MenuItem(com.biglybt.pif.ui.menus.MenuItem) IOException(java.io.IOException) TRHostListener(com.biglybt.core.tracker.host.TRHostListener) TagManager(com.biglybt.core.tag.TagManager) AllTrackersListener(com.biglybt.core.tracker.AllTrackersManager.AllTrackersListener) TagTypeListener(com.biglybt.core.tag.TagTypeListener) ParameterListener(com.biglybt.core.config.ParameterListener) ViewTitleInfo2(com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo2) ClientStatsView(com.biglybt.ui.swt.views.clientstats.ClientStatsView)

Example 15 with MenuItemListener

use of com.biglybt.pif.ui.menus.MenuItemListener 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 getResourceKey() {
            return ("menu.discuss.searchtemplates");
        }

        @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)

Aggregations

MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)22 MenuItem (com.biglybt.pif.ui.menus.MenuItem)19 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)7 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)7 PluginInterface (com.biglybt.pif.PluginInterface)5 UIInstance (com.biglybt.pif.ui.UIInstance)5 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)5 ParameterListener (com.biglybt.core.config.ParameterListener)4 UIManager (com.biglybt.pif.ui.UIManager)4 UIFunctions (com.biglybt.ui.UIFunctions)4 InputStream (java.io.InputStream)4 InetSocketAddress (java.net.InetSocketAddress)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DownloadHistoryEvent (com.biglybt.core.history.DownloadHistoryEvent)3 DownloadHistoryListener (com.biglybt.core.history.DownloadHistoryListener)3 DownloadHistoryManager (com.biglybt.core.history.DownloadHistoryManager)3 Tag (com.biglybt.core.tag.Tag)3