Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Handling Selection events of dynamically created popup menus
Handling Selection events of dynamically created popup menus [message #451337] Sat, 26 February 2005 19:10 Go to next message
Stefan Zeiger is currently offline Stefan ZeigerFriend
Messages: 102
Registered: July 2009
Senior Member
Hello,

I have encountered a strange behaviour of SWT's event dispatching. I'm
creating a popup menu dynamically when I receive a MenuDetect event on a
control. I'm adding a Hide listener which disposes the menu immediately
when it is being hidden.

This prevents all Selection listeners on the MenuItems from working.
When I remove the dispose() call from the Hide listener, the Selection
listeners work as expected. It seems the Hide event on the Menu is sent
before the Selection event on the selected MenuItem gets processed.

The platform is Windows XP. Is this a bug in SWT or the intended
behaviour? It certainly seems counter-intuitive.

--
Stefan Zeiger http://www.szeiger.de http://www.novocode.com
My SWT controls: http://www.novocode.com/swt
Re: Handling Selection events of dynamically created popup menus [message #451832 is a reply to message #451337] Wed, 09 March 2005 16:20 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Stefan, sorry for the late reply,

You're right that the event ordering is counter-intuitive. It's consistent
across the platforms, but this is a result of similar implementation
patterns as opposed to intentional design. Please log a bug report with
Platform - SWT about this issue, and in the meantime you can work around
your problem by executing your menu.dispose() within a Display.asyncExec()
runnable, ie.-

menu.addListener(SWT.Hide, new Listener() {
public void handleEvent(Event event) {
display.asyncExec(new Runnable() {
public void run() {
menu.dispose();
}
});
}
});

Grant

"Stefan Zeiger" <szeiger@novocode.com> wrote in message
news:cvqhma$mq7$1@www.eclipse.org...
> Hello,
>
> I have encountered a strange behaviour of SWT's event dispatching. I'm
> creating a popup menu dynamically when I receive a MenuDetect event on a
> control. I'm adding a Hide listener which disposes the menu immediately
> when it is being hidden.
>
> This prevents all Selection listeners on the MenuItems from working.
> When I remove the dispose() call from the Hide listener, the Selection
> listeners work as expected. It seems the Hide event on the Menu is sent
> before the Selection event on the selected MenuItem gets processed.
>
> The platform is Windows XP. Is this a bug in SWT or the intended
> behaviour? It certainly seems counter-intuitive.
>
> --
> Stefan Zeiger http://www.szeiger.de http://www.novocode.com
> My SWT controls: http://www.novocode.com/swt
Re: Handling Selection events of dynamically created popup menus [message #451890 is a reply to message #451832] Thu, 10 March 2005 18:09 Go to previous message
Stefan Zeiger is currently offline Stefan ZeigerFriend
Messages: 102
Registered: July 2009
Senior Member
Grant Gayed wrote:
>
> You're right that the event ordering is counter-intuitive. It's consistent
> across the platforms, but this is a result of similar implementation
> patterns as opposed to intentional design. Please log a bug report with
> Platform - SWT about this issue, and in the meantime you can work around

I've logged https://bugs.eclipse.org/bugs/show_bug.cgi?id=87678

> your problem by executing your menu.dispose() within a Display.asyncExec()
> runnable, ie.-

Ah, thanks, I haven't thought about that. I already went for a different
solution which avoids disposing and recreating the menu altogether by
just updating an existing menu.

--
Stefan Zeiger - Developer of Novocode Application Framework
Build SWT-based MVC GUIs via XML: http://www.novocode.com/naf/
Previous Topic:Reproducing Gdesklet look and feel ?
Next Topic:Communicating between eclipse and swt browser...
Goto Forum:
  


Current Time: Thu Apr 25 12:56:38 GMT 2024

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

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

Back to the top