Search in sources :

Example 6 with MenuItem

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

the class BuddyPluginView method checkBetaInit.

private void checkBetaInit() {
    if (plugin.isBetaEnabled() && plugin.getBeta().isAvailable()) {
        synchronized (this) {
            if (beta_init_done) {
                return;
            }
            beta_init_done = true;
        }
        MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
        MenuItem chat_item = menu_manager.addMenuItem(MenuManager.MENU_DOWNLOAD_CONTEXT, "label.chat");
        chat_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        chat_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        final MenuItem mi_chat = MenuBuildUtils.addChatMenu(menu_manager, chat_item, new MenuBuildUtils.ChatKeyResolver() {

            @Override
            public String getResourceKey() {
                return ("menu.discuss.download");
            }

            @Override
            public String getChatKey(Object object) {
                return (BuddyPluginUtils.getChatKey((Download) object));
            }

            @Override
            public boolean canShareMessage() {
                return (true);
            }

            @Override
            public void shareMessage(Object target, ChatInstance chat) {
                if (target instanceof Download) {
                    Download dl = (Download) target;
                    chat.sendMessage(dl);
                } else {
                    Download[] dls = (Download[]) target;
                    for (Download dl : dls) {
                        chat.sendMessage(dl);
                    }
                }
            }
        });
        addBetaSubviews(true);
        beta_status = ui_instance.createStatusEntry();
        beta_status.setImageEnabled(true);
        beta_status.setVisible(true);
        updateIdleTT(false);
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                bs_chat_gray = imageLoader.getImage("dchat_gray");
                bs_chat_gray_text = imageLoader.getImage("dchat_gray_text");
                bs_chat_green = imageLoader.getImage("dchat_green");
                bs_chat_red = imageLoader.getImage("dchat_red");
                bs_chat_swarm_merge = imageLoader.getImage("dchat_swarm_merge");
                setBetaStatus(bs_chat_gray);
                mi_chat.setGraphic(ui_instance.createGraphic(bs_chat_gray));
            }
        });
        beta_status.setListener(new UISWTStatusEntryListener() {

            @Override
            public void entryClicked(UISWTStatusEntry entry) {
                Set<ChatInstance> current_instances = menu_latest_instances;
                // might be a lot of chats, just pick first 10
                int rem = 10;
                for (ChatInstance chat : current_instances) {
                    if (chat.getMessageOutstanding()) {
                        try {
                            openChat(chat.getClone());
                            rem--;
                            if (rem == 0) {
                                break;
                            }
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        });
        periodicEventMsgCheck = SimpleTimer.addPeriodicEvent("msgcheck", 30 * 1000, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                List<ChatInstance> chats = plugin.getBeta().getChats();
                Map<ChatInstance, ChatMessage> pending = new HashMap<>();
                synchronized (pending_msg_map) {
                    for (ChatInstance chat : chats) {
                        if (chat.isInvisible()) {
                            continue;
                        }
                        if (!chat_uis.containsKey(chat)) {
                            if (chat.isFavourite() || chat.isAutoNotify() || chat.isInteresting()) {
                                if (!chat.isStatistics()) {
                                    ChatMessage last_msg = chat.getLastMessageRequiringAttention();
                                    if (last_msg != null) {
                                        ChatMessage last_handled = (ChatMessage) chat.getUserData(CHAT_LM_KEY);
                                        long last_msg_time = last_msg.getTimeStamp();
                                        if (last_handled == null || last_msg_time > last_handled.getTimeStamp()) {
                                            chat.setUserData(CHAT_LM_KEY, last_msg);
                                            pending.put(chat, last_msg);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!pending.isEmpty()) {
                        betaMessagesPending(pending);
                    }
                    updateIdleTT(false);
                }
            }
        });
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) ChatMessage(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage) MenuItem(com.biglybt.pif.ui.menus.MenuItem) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Download(com.biglybt.pif.download.Download) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 7 with MenuItem

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

the class BuddyUIUtils method createChat.

public static void createChat(MenuManager menu_manager, MenuItem menu, boolean immediate, ChatCreationListener _listener) {
    ChatCreationListener listener = new ChatCreationListener() {

        Object lock = new Object();

        TimerEventPeriodic timer;

        public void chatCreated(Object target, String name) {
            _listener.chatCreated(target, name);
        }

        public void chatAvailable(Object target, ChatInstance chat) {
            synchronized (lock) {
                if (timer != null) {
                    return;
                }
                long start = SystemTime.getMonotonousTime();
                timer = SimpleTimer.addPeriodicEvent("availcheck", 1000, (ev) -> {
                    if (chat.isAvailable()) {
                        if (!chat.isDestroyed()) {
                            _listener.chatAvailable(target, chat);
                        }
                        synchronized (lock) {
                            timer.cancel();
                        }
                    }
                    if (SystemTime.getMonotonousTime() - start > 3 * 60 * 1000) {
                        Debug.out("Gave up waiting for " + chat.getNetAndKey() + " to become available");
                        synchronized (lock) {
                            timer.cancel();
                        }
                    }
                });
            }
        }
    };
    Runnable build = () -> {
        MenuItem mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.public") + "...!");
        mi.addMultiListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
                // if we don't do this then the fancy-menu will stay open...
                entryWindow.setParentShell(Utils.findAnyShell(true));
                entryWindow.prompt(new UIInputReceiverListener() {

                    @Override
                    public void UIInputReceiverClosed(UIInputReceiver receiver) {
                        if (!receiver.hasSubmittedInput()) {
                            return;
                        }
                        String key = receiver.getSubmittedInput().trim();
                        listener.chatCreated(target, AENetworkClassifier.AT_PUBLIC + ": " + key);
                        BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_PUBLIC, key, (chat) -> {
                            listener.chatAvailable(target, chat);
                        });
                    }
                });
            }
        });
        mi = menu_manager.addMenuItem(menu, "!" + MessageText.getString("label.anon") + "...!");
        mi.addMultiListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                if (BuddyPluginUtils.getBetaPlugin().isI2PAvailable()) {
                    SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("chat.view.enter.key.title", "chat.view.enter.key.msg");
                    // if we don't do this then the fancy-menu will stay open...
                    entryWindow.setParentShell(Utils.findAnyShell(true));
                    entryWindow.prompt(new UIInputReceiverListener() {

                        @Override
                        public void UIInputReceiverClosed(UIInputReceiver receiver) {
                            if (!receiver.hasSubmittedInput()) {
                                return;
                            }
                            String key = receiver.getSubmittedInput().trim();
                            listener.chatCreated(target, AENetworkClassifier.AT_I2P + ": " + key);
                            BuddyPluginUtils.createBetaChat(AENetworkClassifier.AT_I2P, key, (chat) -> {
                                if (chat != null) {
                                    listener.chatAvailable(target, chat);
                                }
                            });
                        }
                    });
                } else {
                    I2PHelpers.installI2PHelper(null, null, null);
                }
            }
        });
        if (I2PHelpers.isInstallingI2PHelper()) {
            mi.setEnabled(false);
            mi.setText(mi.getText() + " (" + MessageText.getString("PeersView.state.pending") + ")");
        }
    };
    if (immediate) {
        build.run();
    } else {
        menu.addFillListener(new com.biglybt.pif.ui.menus.MenuItemFillListener() {

            @Override
            public void menuWillBeShown(MenuItem menu, Object data) {
                menu.removeAllChildItems();
                build.run();
            }
        });
    }
}
Also used : TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) SystemTime(com.biglybt.core.util.SystemTime) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) TimerEventPeriodic(com.biglybt.core.util.TimerEventPeriodic) Messages(com.biglybt.ui.swt.Messages) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) MenuManager(com.biglybt.pif.ui.menus.MenuManager) I2PHelpers(com.biglybt.plugin.I2PHelpers) MessageText(com.biglybt.core.internat.MessageText) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) Debug(com.biglybt.core.util.Debug) Utils(com.biglybt.ui.swt.Utils) SimpleTimer(com.biglybt.core.util.SimpleTimer) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) SWT(org.eclipse.swt.SWT) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Menu(org.eclipse.swt.widgets.Menu) AENetworkClassifier(com.biglybt.core.util.AENetworkClassifier) BuddyPluginUtils(com.biglybt.plugin.net.buddy.BuddyPluginUtils) ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) MenuItem(com.biglybt.pif.ui.menus.MenuItem) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 8 with MenuItem

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

the class TorrentMenuFancy method buildTorrentCustomMenu_Content.

protected void buildTorrentCustomMenu_Content(final Composite detailArea, final DownloadManager[] dms) {
    // Run Data File
    if (hasSelection) {
        createRow(detailArea, "MyTorrentsView.menu.open", "run", new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.runDataSources(dms);
            }
        });
    }
    // Explore (or open containing folder)
    if (hasSelection) {
        final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
        createRow(detailArea, "MyTorrentsView.menu." + (use_open_containing_folder ? "open_parent_folder" : "explore"), null, new ListenerDMTask(dms, false) {

            @Override
            public void run(DownloadManager dm) {
                ManagerUtils.open(dm, use_open_containing_folder);
            }
        });
    }
    if (hasSelection) {
        createMenuRow(detailArea, "MyTorrentsView.menu.browse", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menuBrowse) {
                final MenuItem itemBrowsePublic = new MenuItem(menuBrowse, SWT.PUSH);
                itemBrowsePublic.setText(MessageText.getString("label.public") + "...");
                itemBrowsePublic.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

                    @Override
                    public void run(DownloadManager dm) {
                        ManagerUtils.browse(dm, false, true);
                    }
                });
                final MenuItem itemBrowseAnon = new MenuItem(menuBrowse, SWT.PUSH);
                itemBrowseAnon.setText(MessageText.getString("label.anon") + "...");
                itemBrowseAnon.addListener(SWT.Selection, new ListenerDMTask(dms, false) {

                    @Override
                    public void run(DownloadManager dm) {
                        ManagerUtils.browse(dm, true, true);
                    }
                });
                new MenuItem(menuBrowse, SWT.SEPARATOR);
                final MenuItem itemBrowseURL = new MenuItem(menuBrowse, SWT.PUSH);
                Messages.setLanguageText(itemBrowseURL, "label.copy.url.to.clip");
                itemBrowseURL.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        Utils.getOffOfSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                String url = ManagerUtils.browse(dms[0], true, false);
                                if (url != null) {
                                    ClipboardCopy.copyToClipBoard(url);
                                }
                            }
                        });
                    }
                });
                itemBrowseURL.setEnabled(dms.length == 1);
                new MenuItem(menuBrowse, SWT.SEPARATOR);
                final MenuItem itemBrowseDir = new MenuItem(menuBrowse, SWT.CHECK);
                Messages.setLanguageText(itemBrowseDir, "library.launch.web.in.browser.dir.list");
                itemBrowseDir.setSelection(COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowserDirList"));
                itemBrowseDir.addListener(SWT.Selection, new Listener() {

                    @Override
                    public void handleEvent(Event event) {
                        COConfigurationManager.setParameter("Library.LaunchWebsiteInBrowserDirList", itemBrowseDir.getSelection());
                    }
                });
            }
        });
    }
    // set thumbnail
    createRow(detailArea, "MyTorrentsView.menu.torrent.set.thumb", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager[] dms) {
            FileDialog fDialog = new FileDialog(parentShell, SWT.OPEN | SWT.MULTI);
            fDialog.setText(MessageText.getString("MainWindow.dialog.choose.thumb"));
            String path = fDialog.open();
            if (path == null)
                return;
            File file = new File(path);
            try {
                byte[] thumbnail = FileUtil.readFileAsByteArray(file);
                String name = file.getName();
                int pos = name.lastIndexOf(".");
                String ext;
                if (pos != -1) {
                    ext = name.substring(pos + 1);
                } else {
                    ext = "";
                }
                String type = HTTPUtils.guessContentTypeFromFileType(ext);
                for (DownloadManager dm : dms) {
                    try {
                        TOTorrent torrent = dm.getTorrent();
                        PlatformTorrentUtils.setContentThumbnail(torrent, thumbnail, type);
                    } catch (Throwable e) {
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    });
    boolean fileMove = true;
    boolean locateFiles = false;
    boolean exportFiles = true;
    boolean canSetMOC = dms.length > 0;
    boolean canClearMOC = false;
    for (int i = 0; i < dms.length; i++) {
        DownloadManager dm = dms[i];
        if (!dm.canMoveDataFiles()) {
            fileMove = false;
        }
        if (!dm.canExportDownload()) {
            exportFiles = false;
        }
        if (!dm.isDownloadComplete(false) || dm.getState() == DownloadManager.STATE_ERROR) {
            locateFiles = true;
        }
        boolean incomplete = !dm.isDownloadComplete(true);
        DownloadManagerState dm_state = dm.getDownloadState();
        String moc_dir = dm_state.getAttribute(DownloadManagerState.AT_MOVE_ON_COMPLETE_DIR);
        canSetMOC &= incomplete;
        canClearMOC |= (moc_dir != null && moc_dir.length() > 0);
    }
    if (fileMove) {
        createRow(detailArea, "MyTorrentsView.menu.movedata", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.moveDataFiles(parentShell, dms, false);
            }
        });
        int userMode = COConfigurationManager.getIntParameter("User Mode");
        if (userMode > 0) {
            createRow(detailArea, "MyTorrentsView.menu.movedata.batch", null, new ListenerDMTask(dms) {

                @Override
                public void run(DownloadManager[] dms) {
                    TorrentUtil.moveDataFiles(parentShell, dms, true);
                }
            });
        }
    }
    if (canSetMOC || canClearMOC) {
        boolean f_canSetMOC = canSetMOC;
        boolean f_canClearMOC = canClearMOC;
        createMenuRow(detailArea, "label.move.on.comp", null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu moc_menu) {
                MenuItem clear_item = new MenuItem(moc_menu, SWT.PUSH);
                Messages.setLanguageText(clear_item, "Button.clear");
                clear_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        TorrentUtil.clearMOC(dms);
                    }
                });
                clear_item.setEnabled(f_canClearMOC);
                MenuItem set_item = new MenuItem(moc_menu, SWT.PUSH);
                Messages.setLanguageText(set_item, "label.set");
                set_item.addListener(SWT.Selection, new ListenerDMTask(dms) {

                    @Override
                    public void run(DownloadManager[] dms) {
                        TorrentUtil.setMOC(parentShell, dms);
                    }
                });
                set_item.setEnabled(f_canSetMOC);
            }
        });
    }
    if (exportFiles) {
        createRow(detailArea, "MyTorrentsView.menu.exportdownload", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                TorrentUtil.exportDownloads(parentShell, dms);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.checkfilesexist", null, new ListenerDMTask(dms) {

        @Override
        public void run(DownloadManager dm) {
            dm.filesExist(true);
        }
    });
    if (locateFiles) {
        createRow(detailArea, "MyTorrentsView.menu.locatefiles", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.locateFiles(dms, parentShell);
            }
        });
    }
    if (dms.length == 1 && ManagerUtils.canFindMoreLikeThis()) {
        createRow(detailArea, "MyTorrentsView.menu.findmorelikethis", null, new ListenerDMTask(dms) {

            @Override
            public void run(DownloadManager[] dms) {
                ManagerUtils.findMoreLikeThis(dms[0], parentShell);
            }
        });
    }
    createRow(detailArea, "MyTorrentsView.menu.thisColumn.toClipboard", null, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String sToClipboard = "";
            if (column == null) {
                return;
            }
            String columnName = column.getName();
            if (columnName == null) {
                return;
            }
            TableRowCore[] rows = tv.getSelectedRows();
            for (TableRowCore row : rows) {
                if (row != rows[0]) {
                    sToClipboard += "\n";
                }
                TableCellCore cell = row.getTableCellCore(columnName);
                if (cell != null) {
                    sToClipboard += cell.getClipboardText();
                }
            }
            if (sToClipboard.length() == 0) {
                return;
            }
            new Clipboard(Display.getDefault()).setContents(new Object[] { sToClipboard }, new Transfer[] { TextTransfer.getInstance() });
        }
    });
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuItem(com.biglybt.pif.ui.menus.MenuItem) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) TableRowCore(com.biglybt.ui.common.table.TableRowCore) TOTorrent(com.biglybt.core.torrent.TOTorrent) TableCellCore(com.biglybt.ui.common.table.TableCellCore) Transfer(org.eclipse.swt.dnd.Transfer) TextTransfer(org.eclipse.swt.dnd.TextTransfer) Clipboard(org.eclipse.swt.dnd.Clipboard) File(java.io.File)

Example 9 with MenuItem

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

the class DeviceManagerUI method setupTranscodeMenus.

private void setupTranscodeMenus() {
    if (DISABLED_TRANSCODING) {
        return;
    }
    // top level menus
    final String[] tables = { TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, TableManager.TABLE_MYTORRENTS_COMPLETE_BIG, TableManager.TABLE_TORRENT_FILES, TableManager.TABLE_MYTORRENTS_UNOPENED, TableManager.TABLE_MYTORRENTS_UNOPENED_BIG, TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_ALL_SMALL };
    TableManager table_manager = plugin_interface.getUIManager().getTableManager();
    MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object _target) {
            final TableRow[] target;
            if (_target instanceof TableRow) {
                target = new TableRow[] { (TableRow) _target };
            } else {
                target = (TableRow[]) _target;
            }
            boolean enabled = target.length > 0;
            for (TableRow row : target) {
                Object obj = row.getDataSource();
                if (obj instanceof Download) {
                    Download download = (Download) obj;
                    if (download.getState() == Download.ST_ERROR) {
                        enabled = false;
                    }
                } else if (obj instanceof DiskManagerFileInfo) {
                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                    try {
                        if (file.getIndex() < 0 || file.getDownload().getState() == Download.ST_ERROR) {
                            enabled = false;
                        }
                    } catch (Throwable e) {
                        enabled = false;
                    }
                }
            }
            menu.setEnabled(enabled);
            menu.removeAllChildItems();
            if (enabled) {
                Device[] devices = device_manager.getDevices();
                int devices_added = 0;
                for (Device device : devices) {
                    if (device.isHidden()) {
                        continue;
                    }
                    if (device instanceof TranscodeTarget) {
                        devices_added++;
                        final TranscodeTarget renderer = (TranscodeTarget) device;
                        TranscodeProfile[] profiles = renderer.getTranscodeProfiles();
                        TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!" + device.getName() + (profiles.length == 0 ? " (No Profiles)" : "") + "!");
                        device_item.setStyle(MenuItem.STYLE_MENU);
                        if (profiles.length == 0) {
                            device_item.setEnabled(false);
                        } else {
                            Arrays.sort(profiles, 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);
                                    }
                                }
                            });
                            for (final TranscodeProfile profile : profiles) {
                                TableContextMenuItem profile_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(device_item, "!" + profile.getName() + "!");
                                profile_item.addMultiListener(new MenuItemListener() {

                                    @Override
                                    public void selected(MenuItem menu, Object x) {
                                        for (TableRow row : target) {
                                            Object obj = row.getDataSource();
                                            try {
                                                if (obj instanceof Download) {
                                                    Download download = (Download) obj;
                                                    addDownload(renderer, profile, -1, download);
                                                } else {
                                                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                                                    addFile(renderer, profile, -1, file);
                                                }
                                            } catch (Throwable e) {
                                                Debug.out(e);
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    }
                }
                if (devices_added == 0) {
                    TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!(No Devices)!");
                    device_item.setEnabled(false);
                }
            }
        }
    };
    // instead of forcing a loop like this
    for (String table : tables) {
        TableContextMenuItem menu = table_manager.addContextMenuItem(table, "devices.contextmenu.xcode");
        menu.setStyle(TableContextMenuItem.STYLE_MENU);
        menu.setHeaderCategory(MenuItem.HEADER_CONTENT);
        menu.addFillListener(menu_fill_listener);
        menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) UPnPDevice(com.biglybt.net.upnp.UPnPDevice) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Point(org.eclipse.swt.graphics.Point) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) TableRow(com.biglybt.pif.ui.tables.TableRow) TableManager(com.biglybt.pif.ui.tables.TableManager) Download(com.biglybt.pif.download.Download)

Example 10 with MenuItem

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

the class DeviceManagerUI method createOverallMenu.

private void createOverallMenu(final MenuManager menu_manager, String parentID) {
    MenuItem de_menu_item = menu_manager.addMenuItem(parentID, "device.search");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            search();
        }
    });
    // show generic
    de_menu_item = menu_manager.addMenuItem(parentID, "device.showGeneric");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            boolean is_hidden = COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true);
            menu.setData(!is_hidden);
            boolean enabled = false;
            if (is_hidden) {
                Device[] devices = device_manager.getDevices();
                for (Device d : devices) {
                    if (d.isHidden()) {
                        continue;
                    }
                    if (d instanceof DeviceMediaRenderer) {
                        DeviceMediaRenderer rend = (DeviceMediaRenderer) d;
                        if (rend.isNonSimple()) {
                            enabled = true;
                        }
                    }
                }
            } else {
                enabled = true;
            }
            menu.setEnabled(enabled);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_HIDE_REND_GENERIC, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_HIDE_REND_GENERIC, true));
        }
    });
    // show tagged
    de_menu_item = menu_manager.addMenuItem(parentID, "device.onlyShowTagged");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
            Device[] devices = device_manager.getDevices();
            boolean has_tagged = false;
            for (Device d : devices) {
                if (d.isTagged()) {
                    has_tagged = true;
                    break;
                }
            }
            menu.setEnabled(has_tagged);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, !COConfigurationManager.getBooleanParameter(CONFIG_VIEW_SHOW_ONLY_TAGGED, false));
        }
    });
    // show hidden
    de_menu_item = menu_manager.addMenuItem(parentID, "device.show");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.addListener(show_listener);
    de_menu_item.addFillListener(show_fill_listener);
    // simple
    de_menu_item = menu_manager.addMenuItem(parentID, "devices.sidebar.simple");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_CHECK);
    de_menu_item.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.setData(COConfigurationManager.getIntParameter(CONFIG_VIEW_TYPE, SBV_SIMPLE) == SBV_SIMPLE);
        }
    });
    de_menu_item.addListener(new MenuItemListener() {

        @Override
        public void selected(MenuItem menu, Object target) {
            COConfigurationManager.setParameter(CONFIG_VIEW_TYPE, ((Boolean) menu.getData()) ? SBV_SIMPLE : SBV_FULL);
        }
    });
    de_menu_item = menu_manager.addMenuItem(parentID, "sep");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
    // on complete do
    final MenuItem de_oxc_menu = menu_manager.addMenuItem(parentID, "devices.sidebar.onxcodecomplete");
    de_oxc_menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_oxc_menu.setStyle(MenuItem.STYLE_MENU);
    de_oxc_menu.addFillListener(new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object data) {
            menu.removeAllChildItems();
            final List<MenuItem> oxc_items = new ArrayList<>();
            final MenuItem oxc_nothing = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.nothing");
            oxc_items.add(oxc_nothing);
            oxc_nothing.setStyle(MenuItem.STYLE_CHECK);
            oxc_nothing.setData(oxc_action == OXC_NOTHING);
            final MenuItem oxc_close_vuze = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.closevuze");
            oxc_items.add(oxc_close_vuze);
            oxc_close_vuze.setStyle(MenuItem.STYLE_CHECK);
            oxc_close_vuze.setData(oxc_action == OXC_QUIT_VUZE);
            PlatformManager pm = PlatformManagerFactory.getPlatformManager();
            int sdt = pm.getShutdownTypes();
            final Map<MenuItem, String> oxc_pm_map = new HashMap<>();
            for (int type : PlatformManager.SD_ALL) {
                if ((sdt | type) != 0) {
                    String action = OXC_NOTHING;
                    if (type == PlatformManager.SD_SLEEP) {
                        action = OXC_SLEEP;
                    } else if (type == PlatformManager.SD_HIBERNATE) {
                        action = OXC_HIBERNATE;
                    } else if (type == PlatformManager.SD_SHUTDOWN) {
                        action = OXC_SHUTDOWN;
                    } else {
                        Debug.out("Unknown type: " + type);
                    }
                    MenuItem oxc_pm = menu_manager.addMenuItem(de_oxc_menu, "devices.sidebar.oxc.pm." + type);
                    oxc_items.add(oxc_pm);
                    oxc_pm.setStyle(MenuItem.STYLE_CHECK);
                    oxc_pm.setData(oxc_action == action);
                    oxc_pm_map.put(oxc_pm, action);
                }
            }
            MenuItemListener oxc_mil = new MenuItemListener() {

                @Override
                public void selected(MenuItem menu, Object target) {
                    if ((Boolean) menu.getData()) {
                        if (menu == oxc_nothing) {
                            setOXCState(OXC_NOTHING);
                        } else if (menu == oxc_close_vuze) {
                            setOXCState(OXC_QUIT_VUZE);
                        } else {
                            setOXCState(oxc_pm_map.get(menu));
                        }
                    }
                }
            };
            for (MenuItem mi : oxc_items) {
                mi.addListener(oxc_mil);
            }
        }
    });
    de_menu_item = menu_manager.addMenuItem(parentID, "sep2");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.setStyle(MenuItem.STYLE_SEPARATOR);
    // options
    de_menu_item = menu_manager.addMenuItem(parentID, "menu.device.options");
    de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    de_menu_item.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, CONFIG_SECTION_ID);
            }
        }
    });
    if (Constants.isCVSVersion()) {
        de_menu_item = menu_manager.addMenuItem(parentID, "!(CVS Only)Show FTUX!");
        de_menu_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        de_menu_item.addListener(new MenuItemListener() {

            @Override
            public void selected(MenuItem menu, Object target) {
                DevicesFTUX.showForDebug();
            }
        });
    }
}
Also used : PlatformManager(com.biglybt.platform.PlatformManager) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) UPnPDevice(com.biglybt.net.upnp.UPnPDevice) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UIFunctions(com.biglybt.ui.UIFunctions) List(java.util.List)

Aggregations

MenuItem (com.biglybt.pif.ui.menus.MenuItem)32 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)19 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)11 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)9 UIFunctions (com.biglybt.ui.UIFunctions)9 PluginInterface (com.biglybt.pif.PluginInterface)8 MenuManager (com.biglybt.pif.ui.menus.MenuManager)8 Download (com.biglybt.pif.download.Download)7 UIManager (com.biglybt.pif.ui.UIManager)7 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)7 List (java.util.List)7 UIInstance (com.biglybt.pif.ui.UIInstance)6 ViewTitleInfo (com.biglybt.ui.common.viewtitleinfo.ViewTitleInfo)6 MultipleDocumentInterface (com.biglybt.ui.mdi.MultipleDocumentInterface)6 ParameterListener (com.biglybt.core.config.ParameterListener)5 UnassociatedDevice (com.biglybt.core.devices.DeviceManager.UnassociatedDevice)5 URL (java.net.URL)5 DownloadManager (com.biglybt.core.download.DownloadManager)4 UPnPDevice (com.biglybt.net.upnp.UPnPDevice)4 UPnPRootDevice (com.biglybt.net.upnp.UPnPRootDevice)4