PDA

View Full Version : Event problem with TextToolItem



Tapir0815
23 Apr 2008, 6:02 AM
Hi ,

A click (Events.Click) on TextToolItem never invoke handleEvent of Listener. "Toggle Click" (Events.Toggle) works fine.

What's wrong? Any idee?

Thanks!




Listener listener = new Listener<BaseEvent>() {

public void handleEvent(BaseEvent baseEvent) {
Window.alert(((ButtonEvent) baseEvent).button.getText());
}

};

final TextToolItem itemExport = new TextToolItem("Export");
itemExport.setToolTip("Show Export Explorer");
itemExport.setIconStyle("icon-export");
itemExport.addListener(Events.Click, listener);

final ToggleToolItem itemSynchronise = new ToggleToolItem("Synchroise");
itemSynchronise.setToolTip("Toggle Synchronise Explorer");
itemSynchronise.setIconStyle("icon-synchronise");
itemSynchronise.addListener(Events.Toggle, listener);

final ToolBar toolBar = new ToolBar();
toolBar.add(itemExport);
toolBar.add(new SeparatorToolItem());
toolBar.add(itemSynchronise);

darrellmeyer
23 Apr 2008, 9:45 AM
TextToolItem does not fire the Click event, it fires the Select event. Each component should define what events is fires in its javadocs. There is one issue that is being corrected for the next in beta2. TextToolItem wraps a Button and it is the Button that is passed to the listeners in the ButtonEvent.

So you can do this:

TextToolItem standard = new TextToolItem("Click Me");
standard.addListener(Events.Select, new Listener<ButtonEvent>() {
public void handleEvent(ButtonEvent be) {
System.out.println("bang bang");
}
});You can also use a SelectionListener:

standard.addSelectionListener(new SelectionListener() {
public void componentSelected(ComponentEvent ce) {
System.out.println("i have been selected");
}
});