I am extending a ScrollPanel and wish to process my own custom events with this new widget.
I made my own HasMyHandlers interface with two methods fireEvent(MyEvent event) and HandlerRegistration addMyHandler(MyHandler handler).
First I made a private member SimpleEventBus eventBus, but next thought that the ancestor class should already have it’s own copy.
Is it possible to use ancestor’s event bus, i.e. to register handlers within it and to fire them according to it?
Yes, it is possible. The standard way to do this is in the implementation of
HandlerRegistration addMyHandler(MyHandler handler)is :The
Widget.addHandler(...)method provides the mechanism to wire custom event handlers to the Widget’s HandlerManager.To fire your event to all registered handlers you use
Widget.fireEvent(...)method. So to fire your event you can do:It’s worth noting that your event should also extend the
GwtEventclass.