Search in sources :

Example 1 with UIToolBarActivationListener

use of com.biglybt.pif.ui.toolbar.UIToolBarActivationListener in project BiglyBT by BiglySoftware.

the class TorrentUtil method init.

public static synchronized void init() {
    if (initialised) {
        return;
    }
    initialised = true;
    for (String id : TU_ITEMS) {
        String key = "IconBar.visible." + id;
        if (!COConfigurationManager.hasParameter(key, false)) {
            COConfigurationManager.setParameter(key, false);
        }
    }
    UIManager ui_manager = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getUIManager();
    ui_manager.addUIListener(new UIManagerListener() {

        private List<UIToolBarItem> items = new ArrayList<>();

        @Override
        public void UIAttached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    UIToolBarItem refresh_item = tbm.createToolBarItem(TU_ITEM_RECHECK);
                    refresh_item.setGroupID(TU_GROUP);
                    refresh_item.setImageID("recheck");
                    refresh_item.setToolTipID("MyTorrentsView.menu.recheck");
                    refresh_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                if (dm.canForceRecheck()) {
                                    dm.forceRecheck();
                                }
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, refresh_item);
                    // check files exist
                    UIToolBarItem cfe_item = tbm.createToolBarItem(TU_ITEM_CHECK_FILES);
                    cfe_item.setGroupID(TU_GROUP);
                    cfe_item.setImageID("filesexist");
                    cfe_item.setToolTipID("MyTorrentsView.menu.checkfilesexist");
                    cfe_item.setDefaultActivationListener(new UIToolBarActivationListener() {

                        @Override
                        public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
                            List<DownloadManager> dms = getDMs(datasource);
                            for (DownloadManager dm : dms) {
                                dm.filesExist(true);
                            }
                            return (true);
                        }
                    });
                    addItem(tbm, cfe_item);
                }
            }
        }

        private List<DownloadManager> getDMs(Object ds) {
            List<DownloadManager> result = new ArrayList<>();
            if (ds instanceof Download) {
                result.add(PluginCoreUtils.unwrap((Download) ds));
            } else if (ds instanceof Object[]) {
                Object[] objs = (Object[]) ds;
                for (Object obj : objs) {
                    if (obj instanceof Download) {
                        result.add(PluginCoreUtils.unwrap((Download) obj));
                    }
                }
            }
            return (result);
        }

        private void addItem(UIToolBarManager tbm, UIToolBarItem item) {
            items.add(item);
            tbm.addToolBarItem(item);
        }

        @Override
        public void UIDetached(UIInstance instance) {
            if (instance.getUIType().equals(UIInstance.UIT_SWT)) {
                UIToolBarManager tbm = instance.getToolBarManager();
                if (tbm != null) {
                    for (UIToolBarItem item : items) {
                        tbm.removeToolBarItem(item.getID());
                    }
                }
                items.clear();
            }
        }
    });
}
Also used : UIManager(com.biglybt.pif.ui.UIManager) DownloadManager(com.biglybt.core.download.DownloadManager) ToolBarItem(com.biglybt.ui.common.ToolBarItem) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIToolBarManager(com.biglybt.pif.ui.toolbar.UIToolBarManager) List(java.util.List) UIToolBarItem(com.biglybt.pif.ui.toolbar.UIToolBarItem) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) UIToolBarActivationListener(com.biglybt.pif.ui.toolbar.UIToolBarActivationListener) Download(com.biglybt.pif.download.Download) UIInstance(com.biglybt.pif.ui.UIInstance)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)1 Download (com.biglybt.pif.download.Download)1 UIInstance (com.biglybt.pif.ui.UIInstance)1 UIManager (com.biglybt.pif.ui.UIManager)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 UIToolBarActivationListener (com.biglybt.pif.ui.toolbar.UIToolBarActivationListener)1 UIToolBarItem (com.biglybt.pif.ui.toolbar.UIToolBarItem)1 UIToolBarManager (com.biglybt.pif.ui.toolbar.UIToolBarManager)1 ToolBarItem (com.biglybt.ui.common.ToolBarItem)1 List (java.util.List)1