Search in sources :

Example 71 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class LocaleUtilSWT method selectDecoder.

@Override
public LocaleUtilDecoderCandidate selectDecoder(LocaleUtil locale_util, Object decision_owner, List<LocaleUtilDecoderCandidate> candidates, boolean forceAsk) throws LocaleUtilEncodingException {
    if (!forceAsk) {
        if (decision_owner != remembered_on_behalf_of) {
            remembered_on_behalf_of = decision_owner;
            rememberedDecoder = null;
        }
        if (rememberEncodingDecision && rememberedDecoder != null) {
            for (LocaleUtilDecoderCandidate candidate : candidates) {
                if (candidate.getValue() != null && rememberedDecoder == candidate.getDecoder()) {
                    return (candidate);
                }
            }
        }
    }
    LocaleUtilDecoderCandidate default_candidate = candidates.get(0);
    String defaultString = default_candidate.getValue();
    ArrayList choosableCandidates = new ArrayList();
    if (defaultString != null) {
        choosableCandidates.add(default_candidate);
    }
    LocaleUtilDecoder[] general_decoders = locale_util.getGeneralDecoders();
    for (int j = 0; j < general_decoders.length; j++) {
        for (LocaleUtilDecoderCandidate candidate : candidates) {
            if (candidate.getValue() == null || candidate.getDecoder() == null)
                continue;
            if (general_decoders[j] != null && general_decoders[j].getName().equals(candidate.getDecoder().getName())) {
                if (!choosableCandidates.contains(candidate)) {
                    choosableCandidates.add(candidate);
                    break;
                }
            }
        }
    }
    for (LocaleUtilDecoderCandidate candidate : candidates) {
        if (candidate.getValue() == null || candidate.getDecoder() == null)
            continue;
        if (!choosableCandidates.contains(candidate)) {
            choosableCandidates.add(candidate);
        }
    }
    final LocaleUtilDecoderCandidate[] candidatesToChoose = (LocaleUtilDecoderCandidate[]) choosableCandidates.toArray(new LocaleUtilDecoderCandidate[0]);
    final LocaleUtilDecoderCandidate[] selected_candidate = { null };
    // Run Synchronously, since we want the results
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            try {
                showChoosableEncodingWindow(Utils.findAnyShell(false), candidatesToChoose, selected_candidate);
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    }, false);
    if (selected_candidate[0] == null) {
        throw (new LocaleUtilEncodingException(true));
    } else {
        return (selected_candidate[0]);
    }
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) ArrayList(java.util.ArrayList)

Example 72 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class TorrentInfoView method dataSourceChanged.

private void dataSourceChanged(Object newDataSource) {
    DownloadManager[] dms = DataSourceUtils.getDMs(newDataSource);
    if (dms.length != 1) {
        download_manager = null;
    } else {
        download_manager = dms[0];
    }
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (parent != null && !parent.isDisposed()) {
                initialize(parent);
            }
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 73 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class TranscodeProviderVuze method update.

protected void update(PluginInterface pi) {
    plugin_interface = pi;
    try {
        plugin_interface.getIPC().invoke("addProfileListChangedListener", new Object[] { new AERunnable() {

            @Override
            public void runSupport() {
                resetProfiles();
            }
        } });
    } catch (IPCException e) {
    }
    resetProfiles();
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) IPCException(com.biglybt.pif.ipc.IPCException)

Example 74 with AERunnable

use of com.biglybt.core.util.AERunnable 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)

Example 75 with AERunnable

use of com.biglybt.core.util.AERunnable in project BiglyBT by BiglySoftware.

the class SearchUtils method addMenus.

public static void addMenus(Menu engine_menu, final Engine engine, boolean separator_required) {
    if (separator_required) {
        new MenuItem(engine_menu, SWT.SEPARATOR);
        separator_required = false;
    }
    if (!(engine instanceof PluginEngine)) {
        MenuItem export_json = new MenuItem(engine_menu, SWT.PUSH);
        Messages.setLanguageText(export_json, "menu.export.json.to.clipboard");
        export_json.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                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) {
            MenuItem export_uri = new MenuItem(engine_menu, SWT.PUSH);
            Messages.setLanguageText(export_uri, "label.copy.uri.to.clip");
            export_uri.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    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);
                            }
                        }
                    });
                }
            });
        }
        new MenuItem(engine_menu, SWT.SEPARATOR);
        MenuItem remove_item = new MenuItem(engine_menu, SWT.PUSH);
        Messages.setLanguageText(remove_item, "Button.remove");
        Utils.setMenuItemImage(remove_item, "delete");
        remove_item.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                engine.setSelectionState(Engine.SEL_STATE_FORCE_DESELECTED);
            }
        });
        separator_required = true;
    }
    if (separator_required) {
        new MenuItem(engine_menu, SWT.SEPARATOR);
        separator_required = false;
    }
    MenuItem show_props = new MenuItem(engine_menu, SWT.PUSH);
    Messages.setLanguageText(show_props, "Subscription.menu.properties");
    show_props.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showProperties(engine);
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Shell(org.eclipse.swt.widgets.Shell) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) Subscription(com.biglybt.core.subs.Subscription)

Aggregations

AERunnable (com.biglybt.core.util.AERunnable)92 GridLayout (org.eclipse.swt.layout.GridLayout)12 DownloadManager (com.biglybt.core.download.DownloadManager)11 Image (org.eclipse.swt.graphics.Image)10 ArrayList (java.util.ArrayList)9 GridData (org.eclipse.swt.layout.GridData)9 CoreRunningListener (com.biglybt.core.CoreRunningListener)7 File (java.io.File)7 PEPeer (com.biglybt.core.peer.PEPeer)6 Shell (org.eclipse.swt.widgets.Shell)6 Core (com.biglybt.core.Core)5 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)5 Point (org.eclipse.swt.graphics.Point)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 Subscription (com.biglybt.core.subs.Subscription)3 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3 MouseAdapter (org.eclipse.swt.events.MouseAdapter)3 MouseEvent (org.eclipse.swt.events.MouseEvent)3