Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » how to disable contextmenu?
how to disable contextmenu? [message #242355] Fri, 11 April 2008 11:42 Go to next message
ming is currently offline mingFriend
Messages: 3
Registered: July 2009
Junior Member
in my project, i use leftmouse click and rightmouse click to scale
image. so i need to disable contextmenu when i click rightmouse.
how is it prossible?

thanks
ming
Re: how to disable contextmenu? [message #243790 is a reply to message #242355] Tue, 17 June 2008 19:41 Go to previous message
Thomas Kerle is currently offline Thomas KerleFriend
Messages: 13
Registered: July 2009
Junior Member
Hi,

I assume that you add somewhere your context menu in a viewer or an editor.
As an example to explain I will take an editor that is a child of
GraphicalEditorWithFlyoutPalette

@Override
public void configureGraphicalViewer() {
viewer = getGraphicalViewer();
.. (here follows your code)

EditorContextMenuProvider provider = new EditorContextMenuProvider
(viewer, getActionRegistry(), this);
..(important)
provider.setRemoveAllWhenShown(true);
viewer.setContextMenu(provider);
...
}


(The following class is actually only a dummy class. The menu will be build
dynamically:

public class EditorContextMenuProvider extends ContextMenuProvider {

private ActionRegistry actionRegistry;

private IWorkbenchPart part;

public EditorContextMenuProvider(EditPartViewer viewer, ActionRegistry
registry, IWorkbenchPart part) {
super(viewer);
setEditorPart (part);
setActionRegistry (registry);
}
..... (your methods)
}

In the part where you want to show the context menu:
1) overwrite the activate methode

@Override
public void activate() {
super.activate();

EditorContextMenuProvider cmProvider = (EditorContextMenuProvider)
getViewer().getContextMenu();

actionRegistry = cmProvider.getActionRegistry();

editorPart = cmProvider.getEditorPart();

cmProvider.addMenuListener(new IMenuListener() {

@Override
public void menuAboutToShow(IMenuManager manager) {
fillContextMenu (manager);

}});

}

make a method fillContextMethod:

private void fillContextMenu (IMenuManager manager) {

if (getViewer().getEditDomain().getActiveTool() instanceof YourTool) {
YourTool tool = (YourTool) getViewer().getEditDomain().getActiveTool();

(it's important that you make some methods public in YourTool
to get i) the mouseLocation
ii) the mouse button

Point mouseLoc = tool.getLocation(); // is protected you must make it
public
AbstractTool.Input cInput= tool.getCurrentInput(); //here you have study
the code

... I think this method should do it ...
public boolean isMouseButtonDown(int which) {
return getFlag(1 << which);
}
...

if (cInput.isMouseDown (MOUSEBUTTON.LEFT)) {
IAction action = new MyAction(editorPart, getViewer());
actionRegistry.registerAction(action);
manager.add(action);
}

ok ?


"zming" <aachenzhang@yahoo.de> schrieb im Newsbeitrag
news:ftnir3$q33$1@build.eclipse.org...
> in my project, i use leftmouse click and rightmouse click to scale
> image. so i need to disable contextmenu when i click rightmouse.
> how is it prossible?
>
> thanks
> ming
>
Previous Topic:Zest Layout Algorithmn
Next Topic:Clickable figure is not receiving mouse events.
Goto Forum:
  


Current Time: Thu Apr 25 08:56:37 GMT 2024

Powered by FUDForum. Page generated in 0.03624 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top