PDA

View Full Version : How to use the event model?



timefortea
23 Oct 2008, 2:20 AM
Hi,
I'm confused. Every time I think I know how to use the Event Model, I get it wrong. How do I read the JavaDocs and know what I need to do? For example, I want to set a listener on a Tree, which is fired when I right-click on it to get a context menu (the context menu itself and its listeners are all working ok). So I checked out the JavaDocsfor Tree:



ContextMenu : TreeEvent(tree)
Fires before the tree's context menu is shown.

component : this

I'm not entirely clear on what this means I need to write, but I had a go:



<snip>
contextMenu.addListener(Events.ContextMenu, new Listener<TreeEvent>()
{
public void handleEvent(TreeEvent ce)
{
//TreeItem item = (TreeItem)tree.getSelectionModel().getSelectedItem();
Info.display("Message", "You right clicked on the menu");
}
});
<snip>


This doesn't seem to fire the listener. So I want to know how to do this - but more importantly I'd like to know how to use the listeners so that I don't have to ask this question the next time I need to use a different one. Is this (definitive) information available?

Many thanks.

timefortea
24 Oct 2008, 12:51 AM
Seriously, is there no definitive description of the event model? Is it just a case of constant trial and error? That's the way it feels for me and it means that development using this library is too slow for a commercial product - which is what I was hoping to use it for.

sandlee
24 Oct 2008, 1:20 AM
hi,
you have to add the listener to the tree and not to the contextmenu.

timefortea
24 Oct 2008, 1:35 AM
Thanks for your response, that's done the trick. It seems like an obvious fix now and helps bolster what I *thought* I understood about the event model. I must have been looking at it too hard...

Cheers.