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();
}
}
});
}
Aggregations