/** * Determines if the selection was on the dropdown affordance and, if so, opens the drop down menu * (populated using the same id as this item... * * @param event The <code>SWT.Selection</code> event to be tested * @return <code>true</code> iff a drop down menu was opened */ private boolean openDropDownMenu(Event event) { Widget item = event.widget; if (item != null) { int style = item.getStyle(); if ((style & SWT.DROP_DOWN) != 0) { if (event.detail == 4) { // on drop-down button ToolItem ti = (ToolItem) item; final MenuManager menuManager = new MenuManager(); Menu menu = menuManager.createContextMenu(ti.getParent()); menuManager.addMenuListener( new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { String id = getId(); if (dropDownMenuOverride != null) { id = dropDownMenuOverride; } menuService.populateContributionManager(menuManager, "menu:" + id); // $NON-NLS-1$ } }); // position the menu below the drop down item Rectangle b = ti.getBounds(); Point p = ti.getParent().toDisplay(new Point(b.x, b.y + b.height)); menu.setLocation(p.x, p.y); // waiting for SWT // 0.42 menu.setVisible(true); return true; // we don't fire the action } } } return false; }
public Menu getMenu(Control parent) { if (lastMenu != null) { lastMenu.dispose(); } lastMenu = new Menu(parent); createEntries(lastMenu); return lastMenu; }
public void dispose() { if (lastMenu != null) { lastMenu.dispose(); lastMenu = null; } }