Skip to main content



      Home
Home » Eclipse Projects » GEF » right mouse click in GEF
right mouse click in GEF [message #85023] Tue, 24 June 2003 17:31 Go to next message
Eclipse UserFriend
Originally posted by: rahul.dhar.intel.com

Is there a way to catch right mouse clicks? I'd like to provide
context-sensitive menus when the user right clicks on an object in my GEF
application. Also, are there any simple example of how to handle mouse
events with GEF?

Thanks,
-Rahul
Re: right mouse click in GEF [message #85072 is a reply to message #85023] Tue, 24 June 2003 20:20 Go to previous messageGo to next message
Eclipse UserFriend
Extend ContextMenuProvider and implement buildContextMenu(IMenuManager) which
gets called each time the context menu is about to show. You'll need to add
your provider to the viewer -- see LogicEditor.configureGraphicalViewer(),
specifically these lines:

ContextMenuProvider provider = new LogicContextMenuProvider(viewer,
getActionRegistry());
viewer.setContextMenu(provider);
getSite().registerContextMenu("org.eclipse.gef.examples.logic.editor.contextmenu ",
provider, viewer);



Rahul Dhar wrote:

> Is there a way to catch right mouse clicks? I'd like to provide
> context-sensitive menus when the user right clicks on an object in my GEF
> application. Also, are there any simple example of how to handle mouse
> events with GEF?
>
> Thanks,
> -Rahul
>
Re: right mouse click in GEF [message #85291 is a reply to message #85072] Wed, 25 June 2003 11:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rahul.dhar.intel.com

For some reason,
action = getActionRegistry().getAction(GEFActionConstants.UNDO)

always sets action to null. I'm probably forgetting to do something. Do
I need to register GEFActionConstants.UNDO as an action somewhere before I
retrieve it?

Thanks,
-Rahul

Eric Bordeau wrote:

> Extend ContextMenuProvider and implement buildContextMenu(IMenuManager)
which
> gets called each time the context menu is about to show. You'll need to add
> your provider to the viewer -- see LogicEditor.configureGraphicalViewer(),
> specifically these lines:

> ContextMenuProvider provider = new LogicContextMenuProvider(viewer,
> getActionRegistry());
> viewer.setContextMenu(provider);
>
getSite().registerContextMenu("org.eclipse.gef.examples.logic.editor.contextmenu ",
> provider, viewer);



> Rahul Dhar wrote:

> > Is there a way to catch right mouse clicks? I'd like to provide
> > context-sensitive menus when the user right clicks on an object in my GEF
> > application. Also, are there any simple example of how to handle mouse
> > events with GEF?
> >
> > Thanks,
> > -Rahul
> >
Re: right mouse click in GEF [message #85321 is a reply to message #85291] Wed, 25 June 2003 11:44 Go to previous messageGo to next message
Eclipse UserFriend
The ActionRegistry in the logic example's ContextMenuProvider is passed in by
the editor. GraphicalEditor initializes the action registry in createActions(),
which is where the UndoAction is added.

Rahul Dhar wrote:

> For some reason,
> action = getActionRegistry().getAction(GEFActionConstants.UNDO)
>
> always sets action to null. I'm probably forgetting to do something. Do
> I need to register GEFActionConstants.UNDO as an action somewhere before I
> retrieve it?
>
> Thanks,
> -Rahul
>
> Eric Bordeau wrote:
>
>
>>Extend ContextMenuProvider and implement buildContextMenu(IMenuManager)
>
> which
>
>>gets called each time the context menu is about to show. You'll need to add
>>your provider to the viewer -- see LogicEditor.configureGraphicalViewer(),
>>specifically these lines:
>
>
>>ContextMenuProvider provider = new LogicContextMenuProvider(viewer,
>> getActionRegistry());
>>viewer.setContextMenu(provider);
>>
>
> getSite().registerContextMenu("org.eclipse.gef.examples.logic.editor.contextmenu ",
>
>> provider, viewer);
>
>
>
>
>>Rahul Dhar wrote:
>
>
>>>Is there a way to catch right mouse clicks? I'd like to provide
>>>context-sensitive menus when the user right clicks on an object in my GEF
>>>application. Also, are there any simple example of how to handle mouse
>>>events with GEF?
>>>
>>>Thanks,
>>>-Rahul
>>>
>
>
>
>
>
Re: right mouse click in GEF [message #85377 is a reply to message #85321] Wed, 25 June 2003 14:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rahul.dhar.intel.com

Eric Bordeau wrote:

> The ActionRegistry in the logic example's ContextMenuProvider is passed in
by
> the editor. GraphicalEditor initializes the action registry in
createActions(),
> which is where the UndoAction is added.

So, is createActions() called somewhere? Going through the Logic Example,
i didn't see any explicit calls to it, so I'm assuming that it's being
called somewhere, or at least is supposed to be called somewhere. For
some reason, createActions() isn't being called in my code, and I've
followed along and even copy/pasted some of the example code into mine.

-Rahul
Re: right mouse click in GEF [message #85392 is a reply to message #85377] Wed, 25 June 2003 15:05 Go to previous messageGo to next message
Eclipse UserFriend
Here's the sequence of events:

1. Eclipse calls EditorPart.init(IEditorSite, IEditorInput) -- NOTE: If you
override this method in your editor, you *must* call super.init(...). This is
stated in the javadoc of GraphicalEditor.init(...).
2. GraphicalEditor implements init(...) which calls initializeActionRegistry()
3. initializeActionRegistry() calls createActions()

Rahul Dhar wrote:
> Eric Bordeau wrote:
>
>
>>The ActionRegistry in the logic example's ContextMenuProvider is passed in
>
> by
>
>>the editor. GraphicalEditor initializes the action registry in
>
> createActions(),
>
>>which is where the UndoAction is added.
>
>
> So, is createActions() called somewhere? Going through the Logic Example,
> i didn't see any explicit calls to it, so I'm assuming that it's being
> called somewhere, or at least is supposed to be called somewhere. For
> some reason, createActions() isn't being called in my code, and I've
> followed along and even copy/pasted some of the example code into mine.
>
> -Rahul
>
>
>
>
Re: right mouse click in GEF [message #85483 is a reply to message #85392] Thu, 26 June 2003 09:55 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rahul.dhar.intel.com

Eric,

Thanks a lot! This is hopefully my last question about context-sensitive
menus. Following the logic example, I'm creating menu in public
buildContextMenu(IMenuManager manager). However, I keep getting a
NullPointerException. My code is below. It seems that
getActionRegistry().getAction(GEFActionConstants.COPY) is always returning
null. Why is this? What's different about COPY that I don't have this
problem with UNDO/REDO? The API didn't give any information, and google
didn't help either.

public void buildContextMenu(IMenuManager manager) {
IAction action;

GEFActionConstants.addStandardActionGroups(manager);
action = getActionRegistry().getAction(GEFActionConstants.COPY);
actionRegistry.registerAction(action);
manager.appendToGroup(GEFActionConstants.GROUP_COPY, action);
}

Thanks,
Rahul
Re: right mouse click in GEF [message #85519 is a reply to message #85483] Thu, 26 June 2003 10:05 Go to previous message
Eclipse UserFriend
GEF doesn't provide a default copy action. You can look at the source code for
GraphicalEditor.createActions() to see what actions are provided.


Rahul Dhar wrote:
> Eric,
>
> Thanks a lot! This is hopefully my last question about context-sensitive
> menus. Following the logic example, I'm creating menu in public
> buildContextMenu(IMenuManager manager). However, I keep getting a
> NullPointerException. My code is below. It seems that
> getActionRegistry().getAction(GEFActionConstants.COPY) is always returning
> null. Why is this? What's different about COPY that I don't have this
> problem with UNDO/REDO? The API didn't give any information, and google
> didn't help either.
>
> public void buildContextMenu(IMenuManager manager) {
> IAction action;
>
> GEFActionConstants.addStandardActionGroups(manager);
> action = getActionRegistry().getAction(GEFActionConstants.COPY);
> actionRegistry.registerAction(action);
> manager.appendToGroup(GEFActionConstants.GROUP_COPY, action);
> }
>
> Thanks,
> Rahul
>
>
>
Previous Topic:Editor does not close when we close the project
Next Topic:Creating a new Connection using the palette
Goto Forum:
  


Current Time: Thu May 08 08:27:54 EDT 2025

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

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

Back to the top