use of org.eclipse.swt.events.MenuEvent in project webtools.sourceediting by eclipse.
the class BaseGroupActionDelegate method getMenu.
/* (non-Javadoc)
* @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
*/
public Menu getMenu(Menu parent) {
// Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu).
Menu menu = new Menu(parent);
/**
* Add listener to repopulate the menu each time
* it is shown because MenuManager.update(boolean, boolean)
* doesn't dispose pulldown ActionContribution items for each popup menu.
*/
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent e) {
if (fFillMenu) {
Menu m = (Menu) e.widget;
MenuItem[] items = m.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
fillMenu(m);
fFillMenu = false;
}
}
});
return menu;
}
use of org.eclipse.swt.events.MenuEvent in project webtools.sourceediting by eclipse.
the class RefactorGroupActionDelegate method getMenu.
/* (non-Javadoc)
* @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
*/
public Menu getMenu(Menu parent) {
// Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu).
Menu menu = new Menu(parent);
/**
* Add listener to repopulate the menu each time
* it is shown because MenuManager.update(boolean, boolean)
* doesn't dispose pulldown ActionContribution items for each popup menu.
*/
menu.addMenuListener(new MenuAdapter() {
public void menuShown(MenuEvent e) {
if (fFillMenu) {
Menu m = (Menu) e.widget;
MenuItem[] items = m.getItems();
for (int i = 0; i < items.length; i++) {
items[i].dispose();
}
fillMenu(m);
fFillMenu = false;
}
}
});
return menu;
}
use of org.eclipse.swt.events.MenuEvent in project netxms by netxms.
the class FilterBuilder method createColumnSelectionMenu.
/**
* Create menu for selecting log column
*
* @param listener selection listener
*/
private void createColumnSelectionMenu(final ColumnSelectionHandler handler, Control linkControl) {
if (logHandle == null)
return;
if (columnSelectionMenu != null)
columnSelectionMenu.dispose();
columnSelectionMenu = new Menu(getShell(), SWT.POP_UP);
getShell().setMenu(columnSelectionMenu);
for (final LogColumn lc : logHandle.getColumns()) {
MenuItem item = new MenuItem(columnSelectionMenu, SWT.PUSH);
item.setText(lc.getDescription());
item.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
handler.columnSelected(lc);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
widgetSelected(e);
}
});
}
columnSelectionMenu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
}
@Override
public void menuHidden(MenuEvent e) {
getShell().setMenu(null);
}
});
columnSelectionMenu.setVisible(true);
Point p = linkControl.getParent().toDisplay(linkControl.getLocation());
p.y += linkControl.getSize().y;
columnSelectionMenu.setLocation(p);
}
use of org.eclipse.swt.events.MenuEvent in project dbeaver by serge-rider.
the class ToolsContextMenuHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (part == null || activeShell == null) {
return null;
}
final Control focusControl = activeShell.getDisplay().getFocusControl();
if (focusControl == null) {
return null;
}
Point location = getLocationFromControl(activeShell, focusControl);
if (menuManager != null) {
menuManager.dispose();
}
menuManager = new MenuManager();
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_CONNECT));
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_DISCONNECT));
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_INVALIDATE));
if (part instanceof IEditorPart) {
menuManager.add(new Separator());
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_COMMIT));
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), ConnectionCommands.CMD_ROLLBACK));
{
final MenuManager txnMenu = new MenuManager(DBeaverActivator.getPluginResourceBundle().getString("command.org.jkiss.dbeaver.core.transaction_mode.name"));
txnMenu.add(new DataSourceTransactionModeContributor());
menuManager.add(txnMenu);
}
}
menuManager.add(new Separator());
{
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), SQLEditorCommands.CMD_SQL_EDITOR_OPEN));
/*
final MenuManager toolsMenu = new MenuManager(
DBeaverActivator.getPluginResourceBundle().getString("menu.database.tools"));
toolsMenu.add(new DataSourceToolsContributor());
menuManager.add(toolsMenu);
*/
}
if (part instanceof IEditorPart) {
menuManager.add(ActionUtils.makeCommandContribution(part.getSite(), CoreCommands.CMD_LINK_EDITOR, CoreMessages.action_menu_tools_find_in_navigator, null));
}
final Menu contextMenu = menuManager.createContextMenu(focusControl);
if (location != null) {
contextMenu.setLocation(location);
}
contextMenu.setVisible(true);
contextMenu.addMenuListener(new MenuAdapter() {
@Override
public void menuShown(MenuEvent e) {
int keyIndex = 1;
for (MenuItem item : contextMenu.getItems()) {
if (/*item.getMenu() == null && */
!CommonUtils.isEmpty(item.getText())) {
item.setText(String.valueOf(keyIndex) + ". " + item.getText());
keyIndex++;
if (keyIndex >= 10) {
break;
}
}
}
}
});
return null;
}
use of org.eclipse.swt.events.MenuEvent in project dbeaver by serge-rider.
the class NavigatorUtils method createContextMenu.
public static MenuManager createContextMenu(final IWorkbenchSite workbenchSite, final Viewer viewer, final ISelectionProvider selectionProvider, final IMenuListener menuListener) {
final Control control = viewer.getControl();
final MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(control);
menu.addMenuListener(new MenuListener() {
@Override
public void menuHidden(MenuEvent e) {
}
@Override
public void menuShown(MenuEvent e) {
Menu m = (Menu) e.widget;
DBNNode node = getSelectedNode(viewer.getSelection());
if (node != null && !node.isLocked() && node.allowsOpen()) {
String commandID = NavigatorUtils.getNodeActionCommand(DBXTreeNodeHandler.Action.open, node, NavigatorCommands.CMD_OBJECT_OPEN);
// Get contribution item from menu item and check it's ID
try {
for (MenuItem item : m.getItems()) {
Object itemData = item.getData();
if (itemData instanceof IContributionItem) {
String contribId = ((IContributionItem) itemData).getId();
if (contribId != null && contribId.equals(commandID)) {
m.setDefaultItem(item);
}
}
}
} catch (Exception ex) {
log.debug(ex);
}
}
}
});
menuMgr.addMenuListener(manager -> {
ViewerColumnController columnController = ViewerColumnController.getFromControl(control);
if (columnController != null && columnController.isClickOnHeader()) {
columnController.fillConfigMenu(manager);
manager.add(new Separator());
return;
}
manager.add(new Separator());
addStandardMenuItem(workbenchSite, manager, selectionProvider);
if (menuListener != null) {
menuListener.menuAboutToShow(manager);
}
});
menuMgr.setRemoveAllWhenShown(true);
control.setMenu(menu);
return menuMgr;
}
Aggregations