Search in sources :

Example 1 with UIPluginViewToolBarListener

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

the class SBC_TagsOverview method toolBarItemActivated.

// @see com.biglybt.pif.ui.toolbar.UIToolBarActivationListener#toolBarItemActivated(ToolBarItem, long, java.lang.Object)
@Override
public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
    // Send to active view.  mostly works
    // except MyTorrentsSubView always takes focus after tag is selected..
    boolean isTableSelected = false;
    if (tv instanceof TableViewImpl) {
        isTableSelected = ((TableViewImpl) tv).isTableSelected();
    }
    if (!isTableSelected) {
        UISWTViewCore active_view = getActiveView();
        if (active_view != null) {
            UIPluginViewToolBarListener l = active_view.getToolBarListener();
            if (l != null && l.toolBarItemActivated(item, activationType, datasource)) {
                return true;
            }
        }
        return false;
    }
    if (tv == null || !tv.isVisible()) {
        return (false);
    }
    if (item.getID().equals("remove")) {
        Object[] datasources = tv.getSelectedDataSources().toArray();
        if (datasources.length > 0) {
            for (Object object : datasources) {
                if (object instanceof Tag) {
                    final Tag tag = (Tag) object;
                    if (tag.getTagType().getTagType() != TagType.TT_DOWNLOAD_MANUAL) {
                        continue;
                    }
                    MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { tag.getTagName(true) }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
                    mb.open(new UserPrompterResultListener() {

                        @Override
                        public void prompterClosed(int result) {
                            if (result == 0) {
                                tag.removeTag();
                            }
                        }
                    });
                }
            }
            return true;
        }
    }
    return false;
}
Also used : TableViewImpl(com.biglybt.ui.common.table.impl.TableViewImpl) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 2 with UIPluginViewToolBarListener

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

the class ToolBarView method triggerViewToolBar.

private boolean triggerViewToolBar(ToolBarItem item, long activationType, Object datasource) {
    if (DEBUG && !isVisible()) {
        Debug.out("Trying to triggerViewToolBar when toolbar is not visible");
        return false;
    }
    MultipleDocumentInterfaceSWT mdi = UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT();
    if (mdi != null) {
        MdiEntrySWT entry = mdi.getCurrentEntrySWT();
        UIToolBarEnablerBase[] enablers = entry.getToolbarEnablers();
        for (UIToolBarEnablerBase enabler : enablers) {
            if (enabler instanceof UIPluginViewToolBarListener) {
                if (((UIPluginViewToolBarListener) enabler).toolBarItemActivated(item, activationType, datasource)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 3 with UIPluginViewToolBarListener

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

the class ToolBarView method _refreshCoreToolBarItems.

public void _refreshCoreToolBarItems() {
    if (DEBUG && !isVisible()) {
        Debug.out("Trying to refresh core toolbar items when toolbar is not visible " + this + getMainSkinObject());
    }
    UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
    MultipleDocumentInterfaceSWT mdi = uiFunctionsSWT != null ? uiFunctionsSWT.getMDISWT() : null;
    if (mdi != null) {
        UIToolBarItem[] allToolBarItems = tbm.getAllToolBarItems();
        MdiEntrySWT entry = mdi.getCurrentEntrySWT();
        Map<String, Long> mapStates = new HashMap<>();
        if (entry != null) {
            UIToolBarEnablerBase[] enablers = entry.getToolbarEnablers();
            for (UIToolBarEnablerBase enabler : enablers) {
                if (enabler instanceof UIPluginViewToolBarListener) {
                    try {
                        ((UIPluginViewToolBarListener) enabler).refreshToolBarItems(mapStates);
                    } catch (Throwable e) {
                        // don't trust them plugins
                        Debug.out(e);
                    }
                }
            }
        }
        ISelectedContent[] currentContent = SelectedContentManager.getCurrentlySelectedContent();
        synchronized (dm_listener_map) {
            Map<DownloadManager, DownloadManagerListener> copy = new IdentityHashMap<>(dm_listener_map);
            for (ISelectedContent content : currentContent) {
                DownloadManager dm = content.getDownloadManager();
                if (dm != null) {
                    copy.remove(dm);
                    if (!dm_listener_map.containsKey(dm)) {
                        DownloadManagerListener l = new DownloadManagerListener() {

                            @Override
                            public void stateChanged(DownloadManager manager, int state) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void downloadComplete(DownloadManager manager) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void completionChanged(DownloadManager manager, boolean bCompleted) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void positionChanged(DownloadManager download, int oldPosition, int newPosition) {
                                refreshCoreToolBarItems();
                            }

                            @Override
                            public void filePriorityChanged(DownloadManager download, DiskManagerFileInfo file) {
                                refreshCoreToolBarItems();
                            }
                        };
                        dm.addListener(l, false);
                        dm_listener_map.put(dm, l);
                    // System.out.println( "Added " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
                    }
                }
            }
            for (Map.Entry<DownloadManager, DownloadManagerListener> e : copy.entrySet()) {
                DownloadManager dm = e.getKey();
                dm.removeListener(e.getValue());
                dm_listener_map.remove(dm);
            // System.out.println( "Removed " + dm.getDisplayName() + " - size=" + dm_listener_map.size());
            }
        }
        boolean has1Selection = currentContent.length == 1;
        boolean can_play = false;
        boolean can_stream = false;
        boolean stream_permitted = false;
        if (has1Selection) {
            if (!(currentContent[0] instanceof ISelectedVuzeFileContent)) {
                can_play = PlayUtils.canPlayDS(currentContent[0], currentContent[0].getFileIndex(), false);
                can_stream = PlayUtils.canStreamDS(currentContent[0], currentContent[0].getFileIndex(), false);
                if (can_stream) {
                    stream_permitted = PlayUtils.isStreamPermitted();
                }
            }
        }
        if (mapStates.containsKey("play")) {
            can_play |= (mapStates.get("play") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        if (mapStates.containsKey("stream")) {
            can_stream |= (mapStates.get("stream") & UIToolBarItem.STATE_ENABLED) > 0;
        }
        mapStates.put("play", can_play | can_stream ? UIToolBarItem.STATE_ENABLED : 0);
        UIToolBarItem pitem = tbm.getToolBarItem("play");
        if (pitem != null) {
            if (can_stream) {
                pitem.setImageID(stream_permitted ? "image.button.stream" : "image.button.pstream");
                pitem.setTextID(stream_permitted ? "iconBar.stream" : "iconBar.pstream");
            } else {
                pitem.setImageID("image.button.play");
                pitem.setTextID("iconBar.play");
            }
        }
        UIToolBarItem ssItem = tbm.getToolBarItem("startstop");
        if (ssItem != null) {
            boolean shouldStopGroup;
            if (currentContent.length == 0 && mapStates.containsKey("start") && (!mapStates.containsKey("stop") || (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) == 0) && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0) {
                shouldStopGroup = false;
            } else {
                shouldStopGroup = TorrentUtil.shouldStopGroup(currentContent);
            }
            ssItem.setTextID(shouldStopGroup ? "iconBar.stop" : "iconBar.start");
            ssItem.setImageID("image.toolbar.startstop." + (shouldStopGroup ? "stop" : "start"));
            if (currentContent.length == 0 && !mapStates.containsKey("startstop")) {
                boolean can_stop = mapStates.containsKey("stop") && (mapStates.get("stop") & UIToolBarItem.STATE_ENABLED) > 0;
                boolean can_start = mapStates.containsKey("start") && (mapStates.get("start") & UIToolBarItem.STATE_ENABLED) > 0;
                if (can_start && can_stop) {
                    can_stop = false;
                }
                if (can_start || can_stop) {
                    ssItem.setTextID(can_stop ? "iconBar.stop" : "iconBar.start");
                    ssItem.setImageID("image.toolbar.startstop." + (can_stop ? "stop" : "start"));
                    mapStates.put("startstop", UIToolBarItem.STATE_ENABLED);
                }
            }
        }
        Map<String, Long> fallBackStates = TorrentUtil.calculateToolbarStates(currentContent, null);
        for (String key : fallBackStates.keySet()) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, fallBackStates.get(key));
            }
        }
        final String[] TBKEYS = new String[] { "play", "run", "top", "up", "down", "bottom", "start", "stop", "startstop", "remove" };
        for (String key : TBKEYS) {
            if (!mapStates.containsKey(key)) {
                mapStates.put(key, 0L);
            }
        }
        for (int i = 0; i < allToolBarItems.length; i++) {
            UIToolBarItem toolBarItem = allToolBarItems[i];
            Long state = mapStates.get(toolBarItem.getID());
            if (state != null) {
                toolBarItem.setState(state);
            }
        }
    }
}
Also used : DownloadManagerListener(com.biglybt.core.download.DownloadManagerListener) DownloadManager(com.biglybt.core.download.DownloadManager) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) ISelectedVuzeFileContent(com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 4 with UIPluginViewToolBarListener

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

the class UISWTViewImpl method refreshToolBarItems.

@Override
public void refreshToolBarItems(Map<String, Long> list) {
    UIToolBarEnablerBase[] toolbarEnablers = getToolbarEnablers();
    for (UIToolBarEnablerBase tbEnablerBase : toolbarEnablers) {
        if (tbEnablerBase instanceof UIPluginViewToolBarListener) {
            UIPluginViewToolBarListener tbEnabler = (UIPluginViewToolBarListener) tbEnablerBase;
            tbEnabler.refreshToolBarItems(list);
        }
    }
}
Also used : UIToolBarEnablerBase(com.biglybt.pif.ui.toolbar.UIToolBarEnablerBase) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Example 5 with UIPluginViewToolBarListener

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

the class MyTorrentsSuperView method toolBarItemActivated.

@Override
public boolean toolBarItemActivated(ToolBarItem item, long activationType, Object datasource) {
    UIPluginViewToolBarListener currentView = getActiveToolbarListener();
    if (currentView != null) {
        if (currentView.toolBarItemActivated(item, activationType, datasource)) {
            return true;
        }
    }
    MyTorrentsView currentView2 = getCurrentView();
    if (currentView2 != currentView && currentView2 != null) {
        if (currentView2.toolBarItemActivated(item, activationType, datasource)) {
            return true;
        }
    }
    return false;
}
Also used : UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener)

Aggregations

UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)6 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)3 MdiEntrySWT (com.biglybt.ui.swt.mdi.MdiEntrySWT)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerListener (com.biglybt.core.download.DownloadManagerListener)1 UIToolBarEnablerBase (com.biglybt.pif.ui.toolbar.UIToolBarEnablerBase)1 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)1 TableViewImpl (com.biglybt.ui.common.table.impl.TableViewImpl)1 MdiEntry (com.biglybt.ui.mdi.MdiEntry)1 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)1 ISelectedVuzeFileContent (com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent)1 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)1 UISWTViewCore (com.biglybt.ui.swt.pifimpl.UISWTViewCore)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 SWTSkinObject (com.biglybt.ui.swt.skin.SWTSkinObject)1