Plug-in Beginner [message #331372] |
Wed, 03 September 2008 21:17  |
Eclipse User |
|
|
|
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
|
|
|
Re: Plug-in Beginner [message #331378 is a reply to message #331372] |
Thu, 04 September 2008 06:03   |
Eclipse User |
|
|
|
Hi Jason,
Which kind of UI events are you really interested in ??
In SWT, depending on the widget you are working on you have a lot of
addXXXListener methods, for example addMouseListener.
These methods are not available on the display but you can acces it on a
Shell.
For example PlatformUi.getWorkbench().getActiveWorkbenchWindow().getShel l()
Hope this can help
Manu
|
|
|
Re: Plug-in Beginner [message #331381 is a reply to message #331372] |
Thu, 04 September 2008 07:49   |
Eclipse User |
|
|
|
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
|
|
|
Re: Plug-in Beginner [message #331399 is a reply to message #331378] |
Thu, 04 September 2008 18:08   |
Eclipse User |
|
|
|
I am interested in all the events. I want to be able to capture what a
user is doing. If they clicked on the File Menu, if they debugged the
application, if they are typing text in the editor.
Thanks,
Jason
|
|
|
|
Re: Plug-in Beginner [message #331416 is a reply to message #331407] |
Fri, 05 September 2008 08:51   |
Eclipse User |
|
|
|
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
|
|
|
|
Re: Plug-in Beginner [message #331428 is a reply to message #331422] |
Fri, 05 September 2008 13:40   |
Eclipse User |
|
|
|
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
|
|
|
Re: Plug-in Beginner [message #331429 is a reply to message #331428] |
Fri, 05 September 2008 15:26   |
Eclipse User |
|
|
|
Thanks!
I am now able to see when a user clicks on the menu bar in eclipse with
this code.
Display display = PlatformUI.getWorkbench().getDisplay();
//user clicked a menu
Listener armListener = new Listener()
{
public void handleEvent(Event event) {
MenuItem item = (MenuItem) event.widget;
System.out.println(item.getText());
//I also do some logging here as well
}
};
display.addFilter(SWT.Arm, armListener);
}
Anyone have an idea on how to get events on the editor?
|
|
|
|
Powered by
FUDForum. Page generated in 0.04664 seconds