Search in sources :

Example 1 with MdiEntrySWT

use of com.biglybt.ui.swt.mdi.MdiEntrySWT in project BiglyBT by BiglySoftware.

the class SideBar method showEntry.

@Override
public void showEntry(MdiEntry newEntry) {
    if (tree.isDisposed()) {
        return;
    }
    if (newEntry == null || !newEntry.isSelectable()) {
        return;
    }
    final SideBarEntrySWT oldEntry = (SideBarEntrySWT) currentEntry;
    // System.out.println("showEntry " + newEntry.getId() + "; was " + (oldEntry == null ? "null" : oldEntry.getId()) + " via " + Debug.getCompressedStackTrace());
    if (currentEntry == newEntry) {
        triggerSelectionListener(newEntry, newEntry);
        return;
    }
    // show new
    currentEntry = (MdiEntrySWT) newEntry;
    if (oldEntry != null && oldEntry != newEntry) {
        oldEntry.redraw();
    }
    if (currentEntry != null) {
        ((BaseMdiEntry) currentEntry).show();
    }
    // hide old
    if (oldEntry != null && oldEntry != newEntry) {
        oldEntry.hide();
        oldEntry.redraw();
    }
    // as this code isn't thread safe there is a chance we end up with multiple entries visible
    // (well actually it happens fairly frequently) - this results in other views being rendered
    // during switching which is nasty - hide anything that shouldn't be visible for the moment
    MdiEntrySWT[] entries = getEntriesSWT();
    for (MdiEntrySWT entry : entries) {
        if (entry == null) {
            continue;
        }
        if (entry != currentEntry) {
            SWTSkinObject obj = ((SideBarEntrySWT) entry).getSkinObjectMaster();
            if (obj != null && obj.isVisible()) {
                entry.hide();
                entry.redraw();
            }
        }
    }
    newEntry.redraw();
    triggerSelectionListener(newEntry, oldEntry);
}
Also used : PluginUISWTSkinObject(com.biglybt.ui.swt.pif.PluginUISWTSkinObject) BaseMdiEntry(com.biglybt.ui.swt.mdi.BaseMdiEntry) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT)

Example 2 with MdiEntrySWT

use of com.biglybt.ui.swt.mdi.MdiEntrySWT 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 MdiEntrySWT

use of com.biglybt.ui.swt.mdi.MdiEntrySWT 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 MdiEntrySWT

use of com.biglybt.ui.swt.mdi.MdiEntrySWT in project BiglyBT by BiglySoftware.

the class TableViewSWT_TabsCommon method triggerTabViewsDataSourceChanged.

public void triggerTabViewsDataSourceChanged(TableView<?> tv) {
    if (tabbedMDI == null || tabbedMDI.isDisposed()) {
        return;
    }
    MdiEntry[] entries = tabbedMDI.getEntries();
    if (entries == null || entries.length == 0) {
        return;
    }
    Object[] ds = tv.getSelectedDataSources(true);
    for (MdiEntry entry : entries) {
        if (entry instanceof MdiEntrySWT) {
            triggerTabViewDataSourceChanged((MdiEntrySWT) entry, tv, ds);
        }
    }
}
Also used : MdiEntry(com.biglybt.ui.mdi.MdiEntry) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT)

Example 5 with MdiEntrySWT

use of com.biglybt.ui.swt.mdi.MdiEntrySWT in project BiglyBT by BiglySoftware.

the class TableViewPainted method isVisible.

/* (non-Javadoc)
	 * @see com.biglybt.ui.swt.views.table.TableViewSWT#isVisible()
	 */
@Override
public boolean isVisible() {
    if (!Utils.isThisThreadSWT()) {
        return isVisible;
    }
    boolean wasVisible = isVisible;
    isVisible = cTable != null && !cTable.isDisposed() && cTable.isVisible() && !shell.getMinimized();
    if (isVisible != wasVisible) {
        visibleRowsChanged();
        MdiEntrySWT view = tvTabsCommon == null ? null : tvTabsCommon.getActiveSubView();
        if (isVisible) {
            loopFactor = 0;
            if (view != null) {
                view.getMDI().showEntry(view);
            }
        } else {
            if (view != null) {
                view.triggerEvent(UISWTViewEvent.TYPE_FOCUSLOST, null);
            }
        }
    }
    return isVisible;
}
Also used : MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT)

Aggregations

MdiEntrySWT (com.biglybt.ui.swt.mdi.MdiEntrySWT)10 MultipleDocumentInterfaceSWT (com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT)4 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 ISelectedVuzeFileContent (com.biglybt.ui.selectedcontent.ISelectedVuzeFileContent)2 UIFunctionsSWT (com.biglybt.ui.swt.UIFunctionsSWT)2 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)1 DownloadManagerListener (com.biglybt.core.download.DownloadManagerListener)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)1 UIPluginView (com.biglybt.pif.ui.UIPluginView)1 TableColumn (com.biglybt.pif.ui.tables.TableColumn)1 TableView (com.biglybt.ui.common.table.TableView)1 MdiEntry (com.biglybt.ui.mdi.MdiEntry)1 BaseMdiEntry (com.biglybt.ui.swt.mdi.BaseMdiEntry)1 PluginUISWTSkinObject (com.biglybt.ui.swt.pif.PluginUISWTSkinObject)1 UISWTInstance (com.biglybt.ui.swt.pif.UISWTInstance)1