use of org.eclipse.jface.action.IMenuListener in project dbeaver by serge-rider.
the class Spreadsheet method hookContextMenu.
private void hookContextMenu() {
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(this);
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
// Let controller to provide it's own menu items
GridPos focusPos = getFocusPos();
presentation.fillContextMenu(manager, focusPos.col >= 0 && focusPos.col < columnElements.length ? columnElements[focusPos.col] : null, focusPos.row >= 0 && focusPos.row < rowElements.length ? rowElements[focusPos.row] : null);
}
});
menuMgr.setRemoveAllWhenShown(true);
super.setMenu(menu);
site.registerContextMenu(menuMgr, null);
}
use of org.eclipse.jface.action.IMenuListener in project dbeaver by serge-rider.
the class AbstractPresentation method registerContextMenu.
protected void registerContextMenu() {
// Register context menu
MenuManager menuMgr = new MenuManager();
Menu menu = menuMgr.createContextMenu(getControl());
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
controller.fillContextMenu(manager, getCurrentAttribute(), controller.getCurrentRow());
}
});
menuMgr.setRemoveAllWhenShown(true);
getControl().setMenu(menu);
controller.getSite().registerContextMenu(menuMgr, null);
}
use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.
the class SQLEditorComposite method createContextMenu.
protected void createContextMenu() {
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
if (copyAction != null) {
manager.add(copyAction);
}
IAction cutAction = ActionManager.getInstance().getAction(CutAction.ID);
if (cutAction != null) {
manager.add(cutAction);
}
IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
if (pasteAction != null) {
manager.add(pasteAction);
}
manager.add(new Separator());
IAction findAction = ActionManager.getInstance().getAction(FindReplaceAction.ID);
if (findAction != null) {
manager.add(findAction);
}
manager.add(new Separator());
IAction runQueryAction = ActionManager.getInstance().getAction(RunQueryAction.ID);
if (runQueryAction != null) {
manager.add(runQueryAction);
}
IAction runSqlmapQueryAction = ActionManager.getInstance().getAction(ParseSqlmapQueryAction.ID);
if (runSqlmapQueryAction != null) {
manager.add(runSqlmapQueryAction);
}
IAction runQueryPlanAction = ActionManager.getInstance().getAction(RunQueryPlanAction.ID);
if (runQueryPlanAction != null) {
manager.add(runQueryPlanAction);
}
IAction favoriteQueryAction = ActionManager.getInstance().getAction(AddQueryToFavoriteAction.ID);
if (favoriteQueryAction != null) {
manager.add(favoriteQueryAction);
}
manager.add(new Separator());
IAction showSchemaViewAction = ActionManager.getInstance().getAction(ShowSchemaAction.ID);
if (showSchemaViewAction != null) {
manager.add(showSchemaViewAction);
}
manager.add(new Separator());
IAction queryTunerRunAction = ActionManager.getInstance().getAction(QueryTunerRunAction.ID);
manager.add(queryTunerRunAction);
manager.add(new Separator());
IAction createPhpCodeAction = ActionManager.getInstance().getAction(CreateSqlPhpCodeAction.ID);
if (createPhpCodeAction != null) {
manager.add(createPhpCodeAction);
}
IAction createJavaCodeAction = ActionManager.getInstance().getAction(CreateSqlJavaCodeAction.ID);
if (createJavaCodeAction != null) {
manager.add(createJavaCodeAction);
}
manager.add(new Separator());
IAction reformatColumnsAliasAction = ActionManager.getInstance().getAction(ReformatColumnsAliasAction.ID);
if (reformatColumnsAliasAction != null) {
manager.add(reformatColumnsAliasAction);
}
}
});
Menu contextMenu = menuManager.createContextMenu(text);
text.setMenu(contextMenu);
}
use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.
the class CubridNavigatorView method createPartControl.
/**
* Create the part control
*
* @param parent Composite
*/
public void createPartControl(Composite parent) {
ViewForm viewForm = new ViewForm(parent, SWT.NONE);
viewForm.setLayout(new GridLayout());
tv = new TreeViewer(viewForm, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
tv.setFilters(NodeFilterManager.getInstance().getViewerFilter());
//create the navigator
createNavigator();
//get the isShowGroup configuration
isShowGroup = savedIsShowGroup();
//set the tree view's input.
setTreeInput();
toolTip = new ToolTip(tv.getTree().getShell(), SWT.BALLOON);
toolTip.setAutoHide(true);
//Create the context menu
MenuManager contextMenuManager = new MenuManager("#PopupMenu", "navigatorContextMenu");
contextMenuManager.setRemoveAllWhenShown(true);
contextMenuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
buildPopupMenu(manager);
}
});
Menu contextMenu = contextMenuManager.createContextMenu(tv.getControl());
tv.getControl().setMenu(contextMenu);
// register the context menu for providing extension by extension point
IWorkbenchPartSite site = getSite();
site.registerContextMenu(contextMenuManager, tv);
site.setSelectionProvider(tv);
//add the select the object text composite to top left of toolbar
ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
ToolBarManager toolBarManager = new ToolBarManager(toolBar);
SelectTreeObjContrItem textContrItem = new SelectTreeObjContrItem(tv);
toolBarManager.add(textContrItem);
toolBarManager.update(true);
viewForm.setContent(tv.getControl());
viewForm.setTopLeft(toolBar);
//add the other actions to the top right of toolbar
toolBar = new ToolBar(viewForm, SWT.FLAT | SWT.CENTER);
toolBarManager = new ToolBarManager(toolBar);
buildToolBar(toolBarManager);
toolBarManager.update(true);
viewForm.setTopRight(toolBar);
//Add the actions to view menu bar, you can add them by extension point or code define
IActionBars actionBar = getViewSite().getActionBars();
final IMenuManager menuManager = actionBar.getMenuManager();
menuManager.addMenuListener(new IMenuListener2() {
//reserve these actions by code define,these codes rebuild every time.
//hence when hide, remove them not including these actions by extension point
private IMenuManager lastMenuManager = new MenuManager();
public void menuAboutToShow(IMenuManager manager) {
lastMenuManager.removeAll();
//build the code defined actions
buildViewMenu(lastMenuManager);
for (IContributionItem item : lastMenuManager.getItems()) {
manager.add(item);
}
}
public void menuAboutToHide(IMenuManager manager) {
for (IContributionItem item : lastMenuManager.getItems()) {
manager.remove(item);
}
}
});
menuManager.add(new Separator());
activeContext();
addListener();
setFocus();
}
use of org.eclipse.jface.action.IMenuListener in project cubrid-manager by CUBRID.
the class CommonUITool method registerCopyPasteContextMenu.
/**
*
* Register context menu for styled text
*
* @param text StyledText
* @param isEditable boolean
*/
public static void registerCopyPasteContextMenu(final StyledText text, final boolean isEditable, final boolean isCopiable) {
text.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
ActionManager.getInstance().changeFocusProvider(text);
}
});
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
if (isCopiable) {
IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
if (copyAction instanceof CopyAction) {
manager.add(copyAction);
if (!copyAction.isEnabled()) {
FocusAction.changeActionStatus(copyAction, text);
}
}
IAction copyAllAction = ActionManager.getInstance().getAction(CopyAllAction.ID);
if (copyAllAction instanceof CopyAllAction) {
manager.add(copyAllAction);
if (!copyAllAction.isEnabled()) {
FocusAction.changeActionStatus(copyAllAction, text);
}
}
}
if (!isEditable) {
return;
}
IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
if (pasteAction instanceof PasteAction) {
manager.add(pasteAction);
if (!pasteAction.isEnabled()) {
FocusAction.changeActionStatus(pasteAction, text);
}
}
}
});
Menu contextMenu = menuManager.createContextMenu(text);
text.setMenu(contextMenu);
text.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
IAction copyAction = ActionManager.getInstance().getAction(CopyAction.ID);
if (!copyAction.isEnabled()) {
FocusAction.changeActionStatus(copyAction, text);
}
IAction pasteAction = ActionManager.getInstance().getAction(PasteAction.ID);
if (pasteAction != null && !pasteAction.isEnabled()) {
FocusAction.changeActionStatus(pasteAction, text);
}
}
});
}
Aggregations