Alex
Alex

Reputation: 13

Custom widgets and @UiHandler

Is it possible to have a custom widget use the @UiHandler notation for 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

Upvotes: 1

Views: 1014

Answers (2)

Usman Zaheer
Usman Zaheer

Reputation: 625

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")

Upvotes: 1

Thomas Broyer
Thomas Broyer

Reputation: 64541

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

Upvotes: -1

Related Questions