Search in sources :

Example 1 with MenuBuilder

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

the class TorrentMenuFancy method addPluginItem.

private void addPluginItem(Composite detailArea, final com.biglybt.pif.ui.menus.MenuItem item) {
    // menuWillBeShown listeners might change the visibility, so run before check
    MenuItemImpl menuImpl = ((MenuItemImpl) item);
    menuImpl.invokeMenuWillBeShownListeners(getTarget(item));
    if (!item.isVisible()) {
        if (DEBUG_MENU) {
            System.out.println("Menu Not Visible: " + item.getText() + ": " + item.getMenuID());
        }
        return;
    }
    Graphic graphic = item.getGraphic();
    FancyRowInfo row;
    if (DEBUG_MENU) {
        System.out.println("Menu " + item.getText() + ": " + item.getMenuID());
    }
    if (item.getStyle() == com.biglybt.pif.ui.menus.MenuItem.STYLE_MENU) {
        row = createMenuRow(detailArea, item.getResourceKey(), null, new FancyMenuRowInfoListener() {

            @Override
            public void buildMenu(Menu menu) {
                if (dms.length != 0) {
                    MenuBuilder submenuBuilder = ((MenuItemImpl) item).getSubmenuBuilder();
                    if (submenuBuilder != null) {
                        try {
                            item.removeAllChildItems();
                            submenuBuilder.buildSubmenu(item, getTarget(item));
                        } catch (Throwable t) {
                            Debug.out(t);
                        }
                    }
                    MenuBuildUtils.addPluginMenuItems(item.getItems(), menu, false, true, new MenuBuildUtils.PluginMenuController() {

                        @Override
                        public Listener makeSelectionListener(final com.biglybt.pif.ui.menus.MenuItem plugin_menu_item) {
                            return new TableSelectedRowsListener(tv, false) {

                                @Override
                                public boolean run(TableRowCore[] rows) {
                                    if (rows.length != 0) {
                                        ((MenuItemImpl) plugin_menu_item).invokeListenersMulti(getTarget(item));
                                    }
                                    return true;
                                }
                            };
                        }

                        @Override
                        public void notifyFillListeners(com.biglybt.pif.ui.menus.MenuItem menu_item) {
                            ((MenuItemImpl) menu_item).invokeMenuWillBeShownListeners(getTarget(item));
                        }

                        // @see com.biglybt.ui.swt.MenuBuildUtils.PluginMenuController#buildSubmenu(com.biglybt.pif.ui.menus.MenuItem)
                        @Override
                        public void buildSubmenu(com.biglybt.pif.ui.menus.MenuItem parent) {
                            com.biglybt.pif.ui.menus.MenuBuilder submenuBuilder = ((MenuItemImpl) parent).getSubmenuBuilder();
                            if (submenuBuilder != null) {
                                try {
                                    parent.removeAllChildItems();
                                    submenuBuilder.buildSubmenu(parent, getTarget(item));
                                } catch (Throwable t) {
                                    Debug.out(t);
                                }
                            }
                        }
                    });
                }
            }
        });
    } else {
        row = createRow(detailArea, item.getResourceKey(), null, new TableSelectedRowsListener(tv, false) {

            @Override
            public boolean run(TableRowCore[] rows) {
                if (rows.length != 0) {
                    ((MenuItemImpl) item).invokeListenersMulti(getTarget(item));
                }
                return true;
            }
        });
    }
    row.setEnabled(item.isEnabled());
    if (graphic instanceof UISWTGraphic) {
        row.getIconLabel().setImage(((UISWTGraphic) graphic).getImage());
    } else if (graphic instanceof GraphicURI) {
        ImageLoader.getInstance().setLabelImage(row.getIconLabel(), ((GraphicURI) graphic).getURI().toString());
    }
}
Also used : TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) Graphic(com.biglybt.pif.ui.Graphic) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuBuilder(com.biglybt.pif.ui.menus.MenuBuilder) MenuItemImpl(com.biglybt.pifimpl.local.ui.menus.MenuItemImpl) TableRowCore(com.biglybt.ui.common.table.TableRowCore) GraphicURI(com.biglybt.pif.ui.GraphicURI) MenuItem(com.biglybt.pif.ui.menus.MenuItem) UISWTGraphic(com.biglybt.ui.swt.pif.UISWTGraphic)

Aggregations

Graphic (com.biglybt.pif.ui.Graphic)1 GraphicURI (com.biglybt.pif.ui.GraphicURI)1 MenuBuilder (com.biglybt.pif.ui.menus.MenuBuilder)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemImpl (com.biglybt.pifimpl.local.ui.menus.MenuItemImpl)1 TableRowCore (com.biglybt.ui.common.table.TableRowCore)1 UISWTGraphic (com.biglybt.ui.swt.pif.UISWTGraphic)1 TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)1