|
|
Re: Plug-in Beginner [message #331381 is a reply to message #331372] |
Thu, 04 September 2008 07:49 |
|
On Wed, 3 Sep 2008 21:17:38 +0000 (UTC), jasoncartercs@gmail.com
(Jason Carter) wrote:
>Hello,
>
>
>I am writing an eclipse plug-in.
>
>//get the current display, eclipse display
>Display currentDisplay = PlatformUI.getWorkbench().getDisplay();
>
>From here I would like to add event listeners to the currentDisplay to
>detect any events that happen within eclipse. I am just looking for a
>little direction, not the exact program. I mean if someone has the exact
>why I'd love to take a look at it.
>
>Thanks in advance,
>
>Jason
To see EVERY event you have to register an event filter and NOT filter
any event inside. If you just add an event listener you will miss the
filtered events. So use the addFilter(...) method instead of the
addListener(...) method.
Achim
--
Achim Lörke
Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/news/events.html
Achim Lörke
|
|
|
|
|
Re: Plug-in Beginner [message #331416 is a reply to message #331407] |
Fri, 05 September 2008 08:51 |
|
On Fri, 5 Sep 2008 02:46:07 +0000 (UTC), jasoncartercs@gmail.com
(Jason Carter) wrote:
>Could you please give me an example of this?
Display currentDisplay = PlatformUI.getWorkbench().getDisplay();
// add a filter for all interesting event, i.e. KeyDown/Up,
// MouseDown/Up, MouseMove, ...
// example for KeyDown
currentDisplay.addFilter(SWT.KeyDown, new Listener(){
@Override
public void handleEvent(Event event) {
// log your event, don't modify the event instance!
// you know that this is a KeyDown event, so
// you may call an appropriate logger.
}});
Achim
--
Achim Lörke
Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/news/events.html
Achim Lörke
|
|
|
|
Re: Plug-in Beginner [message #331428 is a reply to message #331422] |
Fri, 05 September 2008 13:40 |
|
On Fri, 05 Sep 2008 08:11:06 -0400, Paul Webster <pwebster@ca.ibm.com>
wrote:
>Jason Carter wrote:
>> Could you please give me an example of this?
>>
>
>And I'll just add ... use addFilter(*) with care (i.e. don't spend a lot
>of time in your handleEvent, and don't use it at all in an eclipse
>plugin if you can help it). It filters every event that the Display
>sees (so a simple mistake here can render anything that depends on SWT
>unusable, flaky, or extremely slow).
>
>PW
Of course you are right. It is extremely dangerous to use addFilter()
and might introduce some hard to find errors. One has to be very
careful when switching threads in a filter operation and should NEVER
do any syncExec() calls.
But it's the only way to get all events which is a must in certain
debugging or test scenarios (which is our excuse for using filters :-)
).
Achim
--
Achim Lörke
Eclipse-Stammtisch in the Braunschweig, Germany area:
http://www.bredex.de/de/news/events.html
Achim Lörke
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03366 seconds