Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Mouse Handling in GEF
Mouse Handling in GEF [message #164692] Thu, 20 January 2005 07:10 Go to next message
Ravi is currently offline RaviFriend
Messages: 19
Registered: July 2009
Junior Member
I am in the process of learning GEF. I was wondering how to do the
following:

1. Handle Mouse Up and Mouse Down events. By default it seems like first
there is a Selection request on a single mouse click. On the 2nd mouse
click (after some time) a DIRECT_EDIT request is sent to the
performRequest() method of AbstractEditPart. This is not what i want - i
need to something on a single click rightaway. How do i take complete
control of MouseUp and MouseDown events?

2. How do i trap Mouse move events? Will performRequest be called for
this? I want to highlight my edit part when the mouse is over the edit
part and back to the normal state when the mouse moves away.

3. How do i add a Tooltip to editparts? Do i have to add Tooltip to the
GraphicalViewer control and set the tooltip location depending on the edit
part location?

Mouse Double click handling was easy to do in the performRequest method.
The rest does not seem so straightforward. One option to sublcass
TargetingTool or SelectionTool and then take completely take control of
low level mouse handling but it does not seem so clean especially since
there are high level abstraction like a Request.


thanks,
-Ravi
Re: Mouse Handling in GEF [message #164716 is a reply to message #164692] Thu, 20 January 2005 14:16 Go to previous messageGo to next message
Brian Fernandes is currently offline Brian FernandesFriend
Messages: 68
Registered: July 2009
Member
Ravi,

If you are using GEF and not just Draw2D - you have a good MVC framework
ready for you to take control of. In almost all the cases, GEF will be
able to do what you desire - it will handle all the low level stuff like
mouse hovering, selection etc. and you get to access this functionality
through various parts of the framework, like EditPolicies and EditParts.

So, to answer your questsions..
1) What exactly do you want to do on mouse click? The EditPart can be
selected automatically by GEF mechanism. If you want to do something
further, override the override AbstractEditPart#setSelected in your
EditPart

2) Install a SELECTION_FEEDBACK_ROLE for your EditPart. You would be
notified of hover events and you can do what you want thereafter.

3) A simple way is to use Draw2D to add a tooltip to your figure directly
(IFigure#setTooltip). I was not happy with this (I can't remember why), so
I implemented my own tooltips using the SELECTION_FEEDBACK_ROLE.

Believe me, for normal requirements, you certainly don't need to be
looking at tools and trackers. I would strongly suggest looking at the
Shapes plugin example and the GEF redbook (link somewhere in this
newsgroup) to avoid yourself unnecessary pain. :)

All the best,
Brian.

Ravi wrote:

> I am in the process of learning GEF. I was wondering how to do the
> following:

> 1. Handle Mouse Up and Mouse Down events. By default it seems like first
> there is a Selection request on a single mouse click. On the 2nd mouse
> click (after some time) a DIRECT_EDIT request is sent to the
> performRequest() method of AbstractEditPart. This is not what i want - i
> need to something on a single click rightaway. How do i take complete
> control of MouseUp and MouseDown events?

> 2. How do i trap Mouse move events? Will performRequest be called for
> this? I want to highlight my edit part when the mouse is over the edit
> part and back to the normal state when the mouse moves away.

> 3. How do i add a Tooltip to editparts? Do i have to add Tooltip to the
> GraphicalViewer control and set the tooltip location depending on the edit
> part location?

> Mouse Double click handling was easy to do in the performRequest method.
> The rest does not seem so straightforward. One option to sublcass
> TargetingTool or SelectionTool and then take completely take control of
> low level mouse handling but it does not seem so clean especially since
> there are high level abstraction like a Request.


> thanks,
> -Ravi
Re: Mouse Handling in GEF [message #164772 is a reply to message #164716] Thu, 20 January 2005 18:31 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> So, to answer your questsions..
> 1) What exactly do you want to do on mouse click? The EditPart can be
> selected automatically by GEF mechanism. If you want to do something
> further, override the override AbstractEditPart#setSelected in your
> EditPart
>
> 2) Install a SELECTION_FEEDBACK_ROLE for your EditPart. You would be
> notified of hover events and you can do what you want thereafter.

Yes, you'll get a REQ_SELECTION_HOVER request type.

> 3) A simple way is to use Draw2D to add a tooltip to your figure directly
> (IFigure#setTooltip). I was not happy with this (I can't remember why), so
> I implemented my own tooltips using the SELECTION_FEEDBACK_ROLE.

Probably because tooltips are active all the time, regardless of which GEF
tool is loaded. Also, they don't go away at the right time when you start
dragging I think. Hopefully PopupHelper class was helpful for displaying a
figure in a popup.
Re: Mouse Handling in GEF [message #164907 is a reply to message #164772] Fri, 21 January 2005 07:22 Go to previous messageGo to next message
Ravi is currently offline RaviFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks Brian and Randy.

1. Overriding setSelected on my EditPart seems to work if want to get
mouseUp behavior. But it only works if the EditPart is Selectable. But i
want to trap the mouse event even if the EditPart is not Selectable. Is
there a way to do this?

2. To highlight my EditPart on a Mouse Move, i had to override the methods
showTargetFeedback and eraseTargetFeedback on my SelectionEditPolicy.

3. IFigure.setTooltip worked. Is there a way to set a Control instead of an
IFigure as a tooltip?

As i am learning GEF i am confused by the way we handle mouse clicks.

- We handle Double Clicks and Direct Edit requests in performRequest() of
AbstractEditPart

- We handle MouseUp in setSelected() of AbstractEditPart

- Mouse Moves in showTargetFeedback()

- i found no way in GEF to capture a Mouse Click (ie press and release in
the same location) and Mouse Down

This means for certain things we override EditPart methods and for others we
use the EditPolicy. This for me is very confusing and does not seem like a
consistent way of doing things. Even the GEF documenetation does not talk
about mouse handling in depth. It seems like the currently active tool will
do what it wants to when it receieves mouse events. And also i tried to use
EditPolicy Command to handle Double Click actions and for some reason they
never get called.

Does this all mean i have to extend one of the tools (like SelectionTool) to
take complete control of what to do with all the low level mouse events ?


thanks,
-Ravi



"Randy Hudson" <none@us.ibm.com> wrote in message
news:csotd8$pk5$1@www.eclipse.org...
>> So, to answer your questsions..
>> 1) What exactly do you want to do on mouse click? The EditPart can be
>> selected automatically by GEF mechanism. If you want to do something
>> further, override the override AbstractEditPart#setSelected in your
>> EditPart
>>
>> 2) Install a SELECTION_FEEDBACK_ROLE for your EditPart. You would be
>> notified of hover events and you can do what you want thereafter.
>
> Yes, you'll get a REQ_SELECTION_HOVER request type.
>
>> 3) A simple way is to use Draw2D to add a tooltip to your figure directly
>> (IFigure#setTooltip). I was not happy with this (I can't remember why),
>> so I implemented my own tooltips using the SELECTION_FEEDBACK_ROLE.
>
> Probably because tooltips are active all the time, regardless of which GEF
> tool is loaded. Also, they don't go away at the right time when you start
> dragging I think. Hopefully PopupHelper class was helpful for displaying a
> figure in a popup.
Re: Mouse Handling in GEF [message #164938 is a reply to message #164907] Fri, 21 January 2005 12:18 Go to previous messageGo to next message
Fabian Wolf is currently offline Fabian WolfFriend
Messages: 96
Registered: July 2009
Member
>[...]
> As i am learning GEF i am confused by the way we handle mouse clicks.
>
> - We handle Double Clicks and Direct Edit requests in performRequest() of
> AbstractEditPart
>
> - We handle MouseUp in setSelected() of AbstractEditPart
>
> - Mouse Moves in showTargetFeedback()
>
> - i found no way in GEF to capture a Mouse Click (ie press and release in
> the same location) and Mouse Down


This leads me to a question,
how would I detect double click events on a figure? Let's say I want some
dialog to pop up when the user double clicks on a figure.


Thanks,
Fabian
Re: Mouse Handling in GEF [message #165011 is a reply to message #164907] Fri, 21 January 2005 16:41 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> 1. Overriding setSelected on my EditPart seems to work if want to get
> mouseUp behavior. But it only works if the EditPart is Selectable. But i
> want to trap the mouse event even if the EditPart is not Selectable. Is
> there a way to do this?

Don't override setSelected(). This method is called at times not related to
mouse events.

> 2. To highlight my EditPart on a Mouse Move, i had to override the methods
> showTargetFeedback and eraseTargetFeedback on my SelectionEditPolicy.

If your editpart is actually targeted, yes.

> 3. IFigure.setTooltip worked. Is there a way to set a Control instead of
> an IFigure as a tooltip?

I don't think so. in #2 above, respond to the feedback by creating an SWT
Shell(SWT.NO_TRIM), and do whatever you want with it.

> As i am learning GEF i am confused by the way we handle mouse clicks.

Tools should handle all mouse events 99% of the time.

> - We handle Double Clicks and Direct Edit requests in performRequest() of
> AbstractEditPart
>
> - We handle MouseUp in setSelected() of AbstractEditPart

No. If you want the mouseUp, you should customize the DragTracker which
your EditPart returned in getDragTracker(...)

> - Mouse Moves in showTargetFeedback()
>
> - i found no way in GEF to capture a Mouse Click (ie press and release in
> the same location) and Mouse Down

DragTracker

> This means for certain things we override EditPart methods and for others
> we use the EditPolicy. This for me is very confusing and does not seem
> like a consistent way of doing things. Even the GEF documenetation does
> not talk about mouse handling in depth. It seems like the currently active
> tool will do what it wants to when it receieves mouse events. And also i
> tried to use EditPolicy Command to handle Double Click actions and for
> some reason they never get called.
>
> Does this all mean i have to extend one of the tools (like SelectionTool)
> to take complete control of what to do with all the low level mouse events
> ?

answered above

>
> thanks,
> -Ravi
>
>
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:csotd8$pk5$1@www.eclipse.org...
>>> So, to answer your questsions..
>>> 1) What exactly do you want to do on mouse click? The EditPart can be
>>> selected automatically by GEF mechanism. If you want to do something
>>> further, override the override AbstractEditPart#setSelected in your
>>> EditPart
>>>
>>> 2) Install a SELECTION_FEEDBACK_ROLE for your EditPart. You would be
>>> notified of hover events and you can do what you want thereafter.
>>
>> Yes, you'll get a REQ_SELECTION_HOVER request type.
>>
>>> 3) A simple way is to use Draw2D to add a tooltip to your figure
>>> directly (IFigure#setTooltip). I was not happy with this (I can't
>>> remember why), so I implemented my own tooltips using the
>>> SELECTION_FEEDBACK_ROLE.
>>
>> Probably because tooltips are active all the time, regardless of which
>> GEF tool is loaded. Also, they don't go away at the right time when you
>> start dragging I think. Hopefully PopupHelper class was helpful for
>> displaying a figure in a popup.
>
>
Re: Mouse Handling in GEF [message #165018 is a reply to message #164938] Fri, 21 January 2005 16:57 Go to previous message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> This leads me to a question,
> how would I detect double click events on a figure? Let's say I want some
> dialog to pop up when the user double clicks on a figure.

If the figure corresponds to an editpart, you should do it using the OPEN
request on the editpart. If it's something else, you should consume the
figure's mouseEvent and open the dialog.

> Thanks,
> Fabian
Previous Topic:DirectGraphLayout
Next Topic:Start connection-creation without palette ??
Goto Forum:
  


Current Time: Thu Mar 28 17:13:39 GMT 2024

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

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

Back to the top