Is it possible to have a custom widget use the @UiHandler notation fo开发者_C百科r mouse events? e.g. when using GWT Designer could you right click on the custom widget, select add event handler, then select onClick. Rather than just onAttachOrDetach.
Regards Alex
Yes you can. For example I have a textbox+label widget and I couldnt create @UiHandler event on it from somewhere because it is not standard so what i did was:
public class TextBoxAndLabel implements HasKeyUpHandlers {
private TextBox myTextBox;
private Label myLabel;
@Override
public HandlerRegistration addKeyUpHandler(KeyUpHandler keyUpHandler) {
return myTextBox.addKeyUpHandler(keyUpHandler);
}
}
and now I can implement
@UiHandler("myClassObject")
I don't know how exactly GWT Designer detects those things, but @UiHandler
looks at the event argument's type to determine the event handler type and then looks at the type of the ui:field
referened in the @UiHandler
for a method returning a HandlerRegistration
and taking a single argument of the event handler type.
In brief: you can very well use @UiHandler
with your own custom widgets, I just don't know how well GWT Designer supports this.
See http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/uibinder/rebind/HandlerEvaluator.java
精彩评论