private void addMenuDisposeListener() { if( menu != null ) { if( menuDisposeListener == null ) { menuDisposeListener = new Listener() { @Override public void handleEvent( Event event ) { _setMenu( null ); } }; } menu.addListener( SWT.Dispose, menuDisposeListener ); } }
public static MenuItem addCloseDownloadBarsToMenu(Menu menu) { final MenuItem item = addMenuItem(menu, MENU_ID_CLOSE_ALL_DL_BARS, new Listener() { @Override public void handleEvent(Event e) { MiniBarManager.getManager().closeAll(); } }); Listener enableHandler = new Listener() { @Override public void handleEvent(Event event) { if (!item.isDisposed()) { item.setEnabled(!MiniBarManager.getManager().getShellManager().isEmpty()); } } }; menu.addListener(SWT.Show, enableHandler); // shell.addListener(SWT.FocusIn, enableHandler); return item; }
public static MenuItem addCloseDetailsMenuItem(Menu menu) { final MenuItem item = addMenuItem(menu, MENU_ID_CLOSE_ALL_DETAIL, new Listener() { @Override public void handleEvent(Event e) { UIFunctionsManagerSWT.getUIFunctionsSWT().closeAllDetails(); } }); Listener enableHandler = new Listener() { @Override public void handleEvent(Event event) { if (MenuFactory.isEnabledForCurrentMode(item)) { if (!item.isDisposed() && !event.widget.isDisposed()) { boolean hasDetails = UIFunctionsManagerSWT.getUIFunctionsSWT().hasDetailViews(); item.setEnabled(hasDetails); } } } }; menu.addListener(SWT.Show, enableHandler); return item; }
private Menu newMenu(int style) { final Menu m = new Menu(shell, style); m.addListener(SWT.Show, event -> updateMenus()); return m; }
/** * Adds the listener to the collection of listeners who will * be notified when menus are hidden or shown, by sending it * one of the messages defined in the <code>MenuListener</code> * interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see MenuListener * @see #removeMenuListener */ public void addMenuListener (MenuListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Hide,typedListener); addListener (SWT.Show,typedListener); }
/** * Adds the listener to the collection of listeners who will * be notified when menus are hidden or shown, by sending it * one of the messages defined in the <code>MenuListener</code> * interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see MenuListener * @see #removeMenuListener */ public void addMenuListener (MenuListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Hide,typedListener); addListener (SWT.Show,typedListener); }
/** * Adds the listener to the collection of listeners who will * be notified when menus are hidden or shown, by sending it * one of the messages defined in the <code>MenuListener</code> * interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see MenuListener * @see #removeMenuListener */ public void addMenuListener (MenuListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Hide,typedListener); addListener (SWT.Show,typedListener); }
/** * Creates the View menu and all its children * @param parent */ private void addViewMenu(final Shell parent) { try { MenuItem viewItem = MenuFactory.createViewMenuItem(menuBar); final Menu viewMenu = viewItem.getMenu(); viewMenu.addListener(SWT.Show, new Listener() { @Override public void handleEvent(Event event) { Utils.disposeSWTObjects(viewMenu.getItems()); buildSimpleViewMenu(viewMenu); } }); } catch (Exception e) { Debug.out("Error creating View Menu", e); } }
/** * Creates the File menu and all its children */ private void addFileMenu() { MenuItem fileItem = MenuFactory.createFileMenuItem(menuBar); final Menu fileMenu = fileItem.getMenu(); builFileMenu(fileMenu); fileMenu.addListener(SWT.Show, new Listener() { @Override public void handleEvent(Event event) { MenuItem[] menuItems = fileMenu.getItems(); for (int i = 0; i < menuItems.length; i++) { menuItems[i].dispose(); } builFileMenu(fileMenu); } }); }
/** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the * <code>HelpListener</code> interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see HelpListener * @see #removeHelpListener */ public void addHelpListener (HelpListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Help, typedListener); }
/** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the * <code>HelpListener</code> interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see HelpListener * @see #removeHelpListener */ public void addHelpListener (HelpListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Help, typedListener); }
/** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the * <code>HelpListener</code> interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see HelpListener * @see #removeHelpListener */ public void addHelpListener (HelpListener listener) { checkWidget(); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Help, typedListener); }
/** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, * by sending it one of the messages defined in the * <code>HelpListener</code> interface. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see HelpListener * @see #removeHelpListener */ public void addHelpListener (HelpListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); TypedListener typedListener = new TypedListener (listener); addListener (SWT.Help, typedListener); }
/** * Creates and returns the menu based on the settings provided via * setColorItems(), setPatternItems() and setGradientItems() * * @return A menu based on the settings */ public Menu createMenu(Control parent, ColorListener cl) { Menu menu = new Menu(parent); MenuItemListener menuItemListener = createMenuItemListener(parent); menu.addListener(SWT.Selection, menuItemListener); menu.addListener(SWT.Dispose, menuItemListener); menuItemListener.setColorListener(cl); if (enableColorItems) { addColorItems(menu, menuItemListener, menuItemListener.getMenuResources()); } if (enablePatternItems) { addPatternItems(menu, menuItemListener, menuItemListener.getMenuResources()); } if (enableGradientItems) { addGradientItems(menu, menuItemListener); } return menu; }
public static MenuItem addTransferBarToMenu(final Menu menu) { final MenuItem item = addMenuItem(menu, SWT.CHECK, MENU_ID_TRANSFER_BAR, new ListenerNeedingCoreRunning() { @Override public void handleEvent(Core core, Event e) { if (AllTransfersBar.getManager().isOpen( core.getGlobalManager())) { AllTransfersBar.closeAllTransfersBar(); } else { AllTransfersBar.open(Utils.findAnyShell()); } } }); item.setSelection(!MiniBarManager.getManager().getShellManager().isEmpty()); menu.addListener(SWT.Show, new Listener() { @Override public void handleEvent(Event event) { if (item.isDisposed()) { menu.removeListener(SWT.Show, this); } else { item.setSelection(!MiniBarManager.getManager().getShellManager().isEmpty()); } } }); return item; }
/** * Handles the event when the toobar item does not have its own context * menu. * * @param event * the event object */ private void handleContextMenu(Event event) { ToolBar toolBar = toolBarManager.getControl(); // If parent has a menu then use that one Menu parentMenu = toolBar.getParent().getMenu(); if ((parentMenu != null) && (!parentMenu.isDisposed())) { toolBar.setMenu(parentMenu); // Hook listener to remove menu once it has disapeared parentMenu.addListener(SWT.Hide, new Listener() { @Override public void handleEvent(Event innerEvent) { ToolBar innerToolBar = toolBarManager.getControl(); if (innerToolBar != null) { innerToolBar.setMenu(null); Menu innerParentMenu = innerToolBar.getParent() .getMenu(); if (innerParentMenu != null) { innerParentMenu.removeListener(SWT.Hide, this); } } } }); } }
/** * Handles the event when the toobar item does not have its own context * menu. * * @param event * the event object */ private void handleContextMenu(Event event) { ToolBar toolBar = toolBarManager.getControl(); // If parent has a menu then use that one Menu parentMenu = toolBar.getParent().getMenu(); if ((parentMenu != null) && (!parentMenu.isDisposed())) { toolBar.setMenu(parentMenu); // Hook listener to remove menu once it has disapeared parentMenu.addListener(SWT.Hide, new Listener() { @Override public void handleEvent(Event innerEvent) { ToolBar innerToolBar = toolBarManager.getControl(); if (innerToolBar != null) { innerToolBar.setMenu(null); Menu innerParentMenu = innerToolBar.getParent() .getMenu(); if (innerParentMenu != null) { innerParentMenu.removeListener(SWT.Hide, this); } } } }); } }
/** * Creates the global download limit context menu item * @param parent The system tray contextual menu */ private final void createDownloadLimitMenu(final Menu parent) { if ( gm == null ){ return; } final MenuItem downloadSpeedItem = new MenuItem(parent, SWT.CASCADE); downloadSpeedItem.setText(MessageText.getString("GeneralView.label.maxdownloadspeed")); final Menu downloadSpeedMenu = new Menu(uiFunctions.getMainShell(), SWT.DROP_DOWN); downloadSpeedMenu.addListener(SWT.Show, new Listener() { @Override public void handleEvent(Event event) { SelectableSpeedMenu.generateMenuItems(downloadSpeedMenu, core, gm, false); } }); downloadSpeedItem.setMenu(downloadSpeedMenu); }
/** * Creates the global upload limit context menu item * @param parent The system tray contextual menu */ private final void createUploadLimitMenu(final Menu parent) { if ( gm == null ){ return; } final MenuItem uploadSpeedItem = new MenuItem(parent, SWT.CASCADE); uploadSpeedItem.setText(MessageText.getString("GeneralView.label.maxuploadspeed")); final Menu uploadSpeedMenu = new Menu(uiFunctions.getMainShell(), SWT.DROP_DOWN); uploadSpeedMenu.addListener(SWT.Show, new Listener() { @Override public void handleEvent(Event event) { SelectableSpeedMenu.generateMenuItems(uploadSpeedMenu, core, gm, true); } }); uploadSpeedItem.setMenu(uploadSpeedMenu); }
@Override public Menu getMenu(Menu parent) { createDropDownMenuMgr(); final Menu menu = new Menu(parent); menu.addListener(SWT.Show, event -> { if (menu.isDisposed()) { return; } MenuItem[] items = menu.getItems(); for (int i1 = 0; i1 < items.length; i1++) { items[i1].dispose(); } IContributionItem[] contributions = getContributionItems(); for (int i2 = 0; i2 < contributions.length; i2++) { contributions[i2].fill(menu, -1); } new ActionContributionItem(new OpenDialogAction()).fill( menu, -1); }); return menu; }