Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » how to get the mouse location for an Action
how to get the mouse location for an Action [message #193689] Fri, 26 August 2005 21:47 Go to next message
Eclipse UserFriend
Originally posted by: pbeagan.yahoo_dontspamme_.com

I want to be able to right-click on the root EditPart (the diagram), have
the context menu come up, select 'Add Item', and have the Item created at
the Point the user clicked.

I can't get access to the mouse location. The only place I see that you can
get it would be in org.eclipse.get.tools.SelectionTool, but the
getLocation() method is protected. My plan is to get the mouse location in
ContextMenuProvider and give to my Action. Alternatively, if the EditPart
knew where it was clicked, that would also work.

Maybe I am looking in the wrong place? This was somewhat discussed in a
recent post 'How to get the EditPart at the mouse location'.

Thanks
Re: how to get the mouse location for an Action [message #193750 is a reply to message #193689] Mon, 29 August 2005 05:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

This question gets asked quite often on this newsgroup. It has now been
promoted to a FAQ:
http://www.eclipse.org/gef/developer/faq.html#code_contextme nulocation

"Patrick" <pbeagan@yahoo_dontspamme_.com> wrote in message
news:deo29f$7d5$1@news.eclipse.org...
> I want to be able to right-click on the root EditPart (the diagram), have
> the context menu come up, select 'Add Item', and have the Item created at
> the Point the user clicked.
>
> I can't get access to the mouse location. The only place I see that you
can
> get it would be in org.eclipse.get.tools.SelectionTool, but the
> getLocation() method is protected. My plan is to get the mouse location
in
> ContextMenuProvider and give to my Action. Alternatively, if the EditPart
> knew where it was clicked, that would also work.
>
> Maybe I am looking in the wrong place? This was somewhat discussed in a
> recent post 'How to get the EditPart at the mouse location'.
>
> Thanks
Re: how to get the mouse location for an Action [message #193932 is a reply to message #193750] Mon, 29 August 2005 16:36 Go to previous messageGo to next message
Felix L J Mayer is currently offline Felix L J MayerFriend
Messages: 202
Registered: July 2009
Senior Member
While I agree that the FAQ points out a valid issue, I don't think this
means you should not provide access to the mouse location because the mouse
will be over the editor nearly all the time. Instead, it could be up to the
developer to provide a default location as you described if the mouse is not
over the editor.

Here is one workaround I came up with: I have extended the
org.eclipse.gef.tools.SelectionTool in order to make one protected method
public; this gives me access to the mouse location . Then I set the default
tool on the DefaultEditDomain of my GraphicalEditor to my own SelectionTool,
and also load it. Here is the code from the constructor of my editor:

DefaultEditDomain editDomain = new DefaultEditDomain( this );
editDomain.setDefaultTool( new SelectionTool() );
editDomain.loadDefaultTool();
setEditDomain( editDomain );

Another possibility is to change the default mouse tool to one that places
your node at the location of the next mouse-click. You can do this in the
run()-method of your action like this:

CreationTool tool = new CreationTool( new DefaultCreationFactory(
.... ) );
UMLEditor editor = (UMLEditor) getWorkbenchPart();
editor.getEditDomain().setActiveTool( tool );

where DefaultCreationFactory implements CreationFactory. Naturally the rest
of your plugin needs to support this also by creating (in a subclass of
AbstractTransferDropTargetListener) and processing the CreateRequest.

"Pratik Shah" <none@unknown.com> wrote in message
news:deu4sb$gos$1@news.eclipse.org...
> This question gets asked quite often on this newsgroup. It has now been
> promoted to a FAQ:
> http://www.eclipse.org/gef/developer/faq.html#code_contextme nulocation
>
> "Patrick" <pbeagan@yahoo_dontspamme_.com> wrote in message
> news:deo29f$7d5$1@news.eclipse.org...
>> I want to be able to right-click on the root EditPart (the diagram), have
>> the context menu come up, select 'Add Item', and have the Item created at
>> the Point the user clicked.
>>
>> I can't get access to the mouse location. The only place I see that you
> can
>> get it would be in org.eclipse.get.tools.SelectionTool, but the
>> getLocation() method is protected. My plan is to get the mouse location
> in
>> ContextMenuProvider and give to my Action. Alternatively, if the
>> EditPart
>> knew where it was clicked, that would also work.
>>
>> Maybe I am looking in the wrong place? This was somewhat discussed in a
>> recent post 'How to get the EditPart at the mouse location'.
>>
>> Thanks
>
>
Re: how to get the mouse location for an Action [message #194188 is a reply to message #193932] Wed, 31 August 2005 14:52 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> While I agree that the FAQ points out a valid issue, I don't think this
> means you should not provide access to the mouse location because the
> mouse will be over the editor nearly all the time. Instead, it could be up
> to the developer to provide a default location as you described if the
> mouse is not over the editor.

The popup menu gets shown when a MenuEvent is generated. If you look at that
event you will see that there is NO x,y data. GEF is NOT hiding the mouse
location from you.

If you want to cheat, you can call Display.getCurrent().getCursorLocation().
Previous Topic:EditPart with multilayer figure
Next Topic:Adding SWT Combo to the draw2d Figure
Goto Forum:
  


Current Time: Tue Apr 23 16:35:36 GMT 2024

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

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

Back to the top