Search in sources :

Example 1 with UISWTView

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

the class UISWTViewEventListenerHolder method eventOccurred.

@Override
public boolean eventOccurred(UISWTViewEvent event) {
    if (listener == null) {
        UISWTViewEventListener eventListener = null;
        synchronized (this) {
            int type = event.getType();
            if (type == UISWTViewEvent.TYPE_CREATE) {
                try {
                    eventListener = cla.newInstance();
                    UISWTView view = event.getView();
                    if (eventListener instanceof UISWTViewCoreEventListener) {
                        if (view instanceof UISWTViewCore) {
                            UISWTViewCore coreView = (UISWTViewCore) view;
                            coreView.setUseCoreDataSource(true);
                        }
                    }
                    if (mapSWTViewToEventListener == null) {
                        mapSWTViewToEventListener = new HashMap<>();
                    }
                    mapSWTViewToEventListener.put(view, eventListener);
                    if (datasource != null) {
                        if (view instanceof UISWTViewImpl) {
                            UISWTViewImpl swtView = (UISWTViewImpl) view;
                            swtView.triggerEventRaw(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, PluginCoreUtils.convert(datasource, ((UISWTViewImpl) view).useCoreDataSource()));
                        } else {
                            view.triggerEvent(UISWTViewEvent.TYPE_DATASOURCE_CHANGED, datasource);
                        }
                    }
                } catch (Exception e) {
                    Debug.out(e);
                    return false;
                }
            } else if (type == UISWTViewEvent.TYPE_DATASOURCE_CHANGED) {
                datasource = event.getData();
            }
            if (mapSWTViewToEventListener != null) {
                if (type == UISWTViewEvent.TYPE_DESTROY) {
                    eventListener = mapSWTViewToEventListener.remove(event.getView());
                } else {
                    eventListener = mapSWTViewToEventListener.get(event.getView());
                }
                Iterator<Map.Entry<UISWTView, UISWTViewEventListener>> it = mapSWTViewToEventListener.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry<UISWTView, UISWTViewEventListener> entry = it.next();
                    UISWTView v = entry.getKey();
                    if (v instanceof UISWTViewImpl) {
                        UISWTViewImpl impl = (UISWTViewImpl) v;
                        if (impl.isDisposed()) {
                            Debug.out("removing orphan from event holder: " + impl);
                            it.remove();
                        }
                    }
                }
            }
        }
        if (eventListener == null) {
            return false;
        }
        return eventListener.eventOccurred(event);
    } else if (event.getType() == UISWTViewEvent.TYPE_CREATE && (listener instanceof UISWTViewCoreEventListener)) {
        if (event.getView() instanceof UISWTViewCore) {
            UISWTViewCore coreView = (UISWTViewCore) event.getView();
            coreView.setUseCoreDataSource(true);
        }
    }
    return (listener.eventOccurred(event));
}
Also used : UISWTView(com.biglybt.ui.swt.pif.UISWTView) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with UISWTView

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

the class BaseMDI method fillMenu.

public void fillMenu(Menu menu, final MdiEntry entry, String menuID) {
    com.biglybt.pif.ui.menus.MenuItem[] menu_items;
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID);
    MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    if (entry != null) {
        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
        if (menu_items.length == 0) {
            if (entry instanceof UISWTView) {
                PluginInterface pi = ((UISWTView) entry).getPluginInterface();
                if (pi != null) {
                    final List<String> relevant_sections = new ArrayList<>();
                    List<ConfigSectionHolder> sections = ConfigSectionRepository.getInstance().getHolderList();
                    for (ConfigSectionHolder cs : sections) {
                        if (pi == cs.getPluginInterface()) {
                            relevant_sections.add(cs.configSectionGetName());
                        }
                    }
                    if (relevant_sections.size() > 0) {
                        MenuItem mi = pi.getUIManager().getMenuManager().addMenuItem(getMenuIdPrefix() + entry.getId(), "MainWindow.menu.view.configuration");
                        mi.setDisposeWithUIDetach(UIInstance.UIT_SWT);
                        mi.addListener(new MenuItemListener() {

                            @Override
                            public void selected(MenuItem menu, Object target) {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    for (String s : relevant_sections) {
                                        uif.getMDI().showEntryByID(SIDEBAR_SECTION_CONFIG, s);
                                    }
                                }
                            }
                        });
                        menu_items = MenuItemManager.getInstance().getAllAsArray(getMenuIdPrefix() + entry.getId());
                    }
                }
            }
        }
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
        MdiSWTMenuHackListener[] menuHackListeners = getMenuHackListeners();
        for (MdiSWTMenuHackListener l : menuHackListeners) {
            try {
                l.menuWillBeShown(entry, menu);
            } catch (Exception e) {
                Debug.out(e);
            }
        }
        if (currentEntry instanceof SideBarEntrySWT) {
            menuHackListeners = ((SideBarEntrySWT) entry).getMenuHackListeners();
            for (MdiSWTMenuHackListener l : menuHackListeners) {
                try {
                    l.menuWillBeShown(entry, menu);
                } catch (Exception e) {
                    Debug.out(e);
                }
            }
        }
    }
    menu_items = MenuItemManager.getInstance().getAllAsArray(menuID + "._end_");
    if (menu_items.length > 0) {
        MenuBuildUtils.addPluginMenuItems(menu_items, menu, false, true, new MenuBuildUtils.MenuItemPluginMenuControllerImpl(new Object[] { entry }));
    }
}
Also used : PluginInterface(com.biglybt.pif.PluginInterface) SideBarEntrySWT(com.biglybt.ui.swt.views.skin.sidebar.SideBarEntrySWT) ConfigSectionHolder(com.biglybt.pifimpl.local.ui.config.ConfigSectionHolder) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTView(com.biglybt.ui.swt.pif.UISWTView) UIFunctions(com.biglybt.ui.UIFunctions) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 3 with UISWTView

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

the class BuddyPluginView method addBetaSubviews.

private void addBetaSubviews(boolean enable) {
    String[] views = { TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, "TagsView" };
    if (enable) {
        taggableLifecycleAdapter = new TaggableLifecycleAdapter() {

            @Override
            public void taggableTagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }

            @Override
            public void taggableUntagged(TagType tag_type, Tag tag, Taggable taggable) {
                if (tag_type.getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                    DownloadManager dm = (DownloadManager) taggable;
                    for (BetaSubViewHolder h : beta_subviews.values()) {
                        h.tagsUpdated(dm);
                    }
                }
            }
        };
        TagManagerFactory.getTagManager().addTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
        UISWTViewEventListener listener = new UISWTViewEventListener() {

            @Override
            public boolean eventOccurred(UISWTViewEvent event) {
                UISWTView currentView = event.getView();
                switch(event.getType()) {
                    case UISWTViewEvent.TYPE_CREATE:
                        {
                            beta_subviews.put(currentView, new BetaSubViewHolder());
                            currentView.setDestroyOnDeactivate(false);
                            break;
                        }
                    case UISWTViewEvent.TYPE_INITIALIZE:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.initialise(event.getView(), (Composite) event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.setDataSource(event.getData());
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSGAINED:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.gotFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_FOCUSLOST:
                        {
                            BetaSubViewHolder subview = beta_subviews.get(currentView);
                            if (subview != null) {
                                subview.lostFocus();
                            }
                            break;
                        }
                    case UISWTViewEvent.TYPE_DESTROY:
                        {
                            BetaSubViewHolder subview = beta_subviews.remove(currentView);
                            if (subview != null) {
                                subview.destroy();
                            }
                            break;
                        }
                }
                return true;
            }
        };
        for (String table_id : views) {
            ui_instance.addView(table_id, "azbuddy.ui.menu.chat", listener);
        }
        TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
        TableCellRefreshListener msg_refresh_listener = new TableCellRefreshListener() {

            @Override
            public void refresh(TableCell _cell) {
                TableCellSWT cell = (TableCellSWT) _cell;
                Download dl = (Download) cell.getDataSource();
                if (dl == null) {
                    return;
                }
                List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                boolean is_pending = false;
                for (ChatInstance instance : instances) {
                    if (instance.getMessageOutstanding()) {
                        is_pending = true;
                    }
                }
                Image graphic;
                String tooltip;
                int sort_order;
                if (is_pending) {
                    graphic = bs_chat_gray_text;
                    tooltip = MessageText.getString("TableColumn.header.chat.msg.out");
                    sort_order = 1;
                } else {
                    graphic = null;
                    tooltip = MessageText.getString("label.no.messages");
                    sort_order = 0;
                }
                cell.setMarginHeight(0);
                cell.setGraphic(graphic);
                cell.setToolTip(tooltip);
                cell.setSortValue(sort_order);
                cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
            }
        };
        TableCellMouseListener msg_mouse_listener = new TableCellMouseListener() {

            @Override
            public void cellMouseTrigger(TableCellMouseEvent event) {
                if (event.eventType == TableCellMouseEvent.EVENT_MOUSEUP) {
                    TableCell cell = event.cell;
                    Download dl = (Download) cell.getDataSource();
                    if (dl != null) {
                        List<ChatInstance> instances = BuddyPluginUtils.peekChatInstances(dl);
                        for (ChatInstance instance : instances) {
                            if (instance.getMessageOutstanding()) {
                                try {
                                    BuddyPluginUtils.getBetaPlugin().showChat(instance);
                                } catch (Throwable e) {
                                    Debug.out(e);
                                }
                            }
                        }
                    }
                }
            }
        };
        columnMessagePending = new TableColumnCreationListener() {

            @Override
            public void tableColumnCreated(TableColumn result) {
                result.setAlignment(TableColumn.ALIGN_CENTER);
                result.setPosition(TableColumn.POSITION_LAST);
                result.setWidth(32);
                result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
                result.setType(TableColumn.TYPE_GRAPHIC);
                result.addCellRefreshListener(msg_refresh_listener);
                result.addCellMouseListener(msg_mouse_listener);
                result.setIconReference("dchat_gray", true);
                synchronized (columns) {
                    columns.add(result);
                }
            }
        };
        table_manager.registerColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
    } else {
        for (String table_id : views) {
            ui_instance.removeViews(table_id, "azbuddy.ui.menu.chat");
        }
        for (UISWTView entry : new ArrayList<>(beta_subviews.keySet())) {
            entry.closeView();
        }
        if (taggableLifecycleAdapter != null) {
            TagManagerFactory.getTagManager().removeTaggableLifecycleListener(Taggable.TT_DOWNLOAD, taggableLifecycleAdapter);
            taggableLifecycleAdapter = null;
        }
        beta_subviews.clear();
        if (columnMessagePending != null) {
            TableManager table_manager = plugin.getPluginInterface().getUIManager().getTableManager();
            table_manager.unregisterColumn(Download.class, "azbuddy.ui.column.msgpending", columnMessagePending);
            columnMessagePending = null;
            synchronized (columns) {
                columns.clear();
            }
        }
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TaggableLifecycleAdapter(com.biglybt.core.tag.TaggableLifecycleAdapter) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager) TableCellMouseListener(com.biglybt.pif.ui.tables.TableCellMouseListener) TableColumnCreationListener(com.biglybt.pif.ui.tables.TableColumnCreationListener) TableCell(com.biglybt.pif.ui.tables.TableCell) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) TableManager(com.biglybt.pif.ui.tables.TableManager) Download(com.biglybt.pif.download.Download) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) TableColumn(com.biglybt.pif.ui.tables.TableColumn) Point(org.eclipse.swt.graphics.Point) TagType(com.biglybt.core.tag.TagType) UISWTView(com.biglybt.ui.swt.pif.UISWTView) TableCellRefreshListener(com.biglybt.pif.ui.tables.TableCellRefreshListener) TableCellMouseEvent(com.biglybt.pif.ui.tables.TableCellMouseEvent) Tag(com.biglybt.core.tag.Tag) Taggable(com.biglybt.core.tag.Taggable)

Example 4 with UISWTView

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

the class ActivityView method eventOccurred.

@Override
public boolean eventOccurred(UISWTViewEvent event) {
    switch(event.getType()) {
        case UISWTViewEvent.TYPE_CREATE:
            UISWTView swtView = event.getView();
            swtView.setTitle(MessageText.getString(MSGID_PREFIX + ".title.full"));
            break;
        case UISWTViewEvent.TYPE_DESTROY:
            delete();
            break;
        case UISWTViewEvent.TYPE_INITIALIZE:
            initialize((Composite) event.getData());
            break;
        case UISWTViewEvent.TYPE_LANGUAGEUPDATE:
            Messages.updateLanguageForControl(getComposite());
            break;
        case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
            break;
        case UISWTViewEvent.TYPE_FOCUSGAINED:
            refresh(true);
            break;
        case UISWTViewEvent.TYPE_REFRESH:
            refresh(false);
            break;
        case StatsView.EVENT_PERIODIC_UPDATE:
            periodicUpdate();
            break;
    }
    return true;
}
Also used : UISWTView(com.biglybt.ui.swt.pif.UISWTView)

Example 5 with UISWTView

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

the class CacheView method eventOccurred.

@Override
public boolean eventOccurred(UISWTViewEvent event) {
    switch(event.getType()) {
        case UISWTViewEvent.TYPE_CREATE:
            UISWTView swtView = (UISWTView) event.getData();
            swtView.setTitle(MessageText.getString(MSGID_PREFIX + ".title.full"));
            break;
        case UISWTViewEvent.TYPE_DESTROY:
            delete();
            break;
        case UISWTViewEvent.TYPE_INITIALIZE:
            initialize((Composite) event.getData());
            break;
        case UISWTViewEvent.TYPE_LANGUAGEUPDATE:
            Messages.updateLanguageForControl(getComposite());
            break;
        case UISWTViewEvent.TYPE_DATASOURCE_CHANGED:
            break;
        case UISWTViewEvent.TYPE_FOCUSGAINED:
            break;
        case UISWTViewEvent.TYPE_REFRESH:
            refresh();
            break;
        case StatsView.EVENT_PERIODIC_UPDATE:
            periodicUpdate();
            break;
    }
    return true;
}
Also used : UISWTView(com.biglybt.ui.swt.pif.UISWTView)

Aggregations

UISWTView (com.biglybt.ui.swt.pif.UISWTView)5 UISWTViewEventListener (com.biglybt.ui.swt.pif.UISWTViewEventListener)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 Tag (com.biglybt.core.tag.Tag)1 TagType (com.biglybt.core.tag.TagType)1 Taggable (com.biglybt.core.tag.Taggable)1 TaggableLifecycleAdapter (com.biglybt.core.tag.TaggableLifecycleAdapter)1 PluginInterface (com.biglybt.pif.PluginInterface)1 Download (com.biglybt.pif.download.Download)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1 TableCell (com.biglybt.pif.ui.tables.TableCell)1 TableCellMouseEvent (com.biglybt.pif.ui.tables.TableCellMouseEvent)1 TableCellMouseListener (com.biglybt.pif.ui.tables.TableCellMouseListener)1 TableCellRefreshListener (com.biglybt.pif.ui.tables.TableCellRefreshListener)1 TableColumn (com.biglybt.pif.ui.tables.TableColumn)1 TableColumnCreationListener (com.biglybt.pif.ui.tables.TableColumnCreationListener)1 TableManager (com.biglybt.pif.ui.tables.TableManager)1 ConfigSectionHolder (com.biglybt.pifimpl.local.ui.config.ConfigSectionHolder)1 ChatInstance (com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance)1