Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Plug-in Beginner
Plug-in Beginner [message #331372] Wed, 03 September 2008 21:17 Go to next message
Jason Carter is currently offline Jason CarterFriend
Messages: 13
Registered: July 2009
Junior Member
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 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel SelvaFriend
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
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 Go to previous messageGo to next message
Achim Loerke is currently offline Achim LoerkeFriend
Messages: 376
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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 #331399 is a reply to message #331378] Thu, 04 September 2008 18:08 Go to previous messageGo to next message
Jason Carter is currently offline Jason CarterFriend
Messages: 13
Registered: July 2009
Junior Member
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 #331407 is a reply to message #331381] Fri, 05 September 2008 02:46 Go to previous messageGo to next message
Jason Carter is currently offline Jason CarterFriend
Messages: 13
Registered: July 2009
Junior Member
Could you please give me an example of this?
Re: Plug-in Beginner [message #331416 is a reply to message #331407] Fri, 05 September 2008 08:51 Go to previous messageGo to next message
Achim Loerke is currently offline Achim LoerkeFriend
Messages: 376
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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 #331422 is a reply to message #331407] Fri, 05 September 2008 12:11 Go to previous messageGo to next message
Paul Webster is currently offline Paul WebsterFriend
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

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

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclips e.platform.doc.isv/guide/workbench.htm


Re: Plug-in Beginner [message #331428 is a reply to message #331422] Fri, 05 September 2008 13:40 Go to previous messageGo to next message
Achim Loerke is currently offline Achim LoerkeFriend
Messages: 376
Registered: July 2009
Location: Braunschweig, Germany
Senior Member

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

Re: Plug-in Beginner [message #331429 is a reply to message #331428] Fri, 05 September 2008 15:26 Go to previous messageGo to next message
Jason Carter is currently offline Jason CarterFriend
Messages: 13
Registered: July 2009
Junior Member
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?
Re: Plug-in Beginner [message #331451 is a reply to message #331429] Mon, 08 September 2008 12:22 Go to previous message
Jason Carter is currently offline Jason CarterFriend
Messages: 13
Registered: July 2009
Junior Member
I am able to get to the editor. If anyone wants to know how I did it just
post here and I can send you the code.
Previous Topic:Ganymede: Annoying JRE warnings
Next Topic:Solution of ContentAssist Problem
Goto Forum:
  


Current Time: Fri Jul 05 05:22:52 GMT 2024

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

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

Back to the top