My current process for custom widgets is the following:
My listeners fire fine-grained events, such as onEntityDisplayRequested(Entity entity)
, so I can't use the stock listeners.
While this achieves low coupling for the widget and allows for re-use, it's quite verbose. Is there a better way of handling design of custom widgets?
You don't need a separate listener interface for every new widget. E.g. ClickListener is used by a variety of different widget classes. Obviously, some custom widgets will require a new listener type, but that shouldn't be automatic.
I think Java faced the same issue some time ago, and a solution was to have the PropertyChange events. They come with - the PropertyEvent, that contains the source, the property name and the old+new values - a PropertyChangeListener - a PropertyChangeSupport, to which you can delegate the event firing, as well as the registering and unregistering the listeners.
You loose a bit of specificity (event are matched by their name as a string), but you can still fire fine-grained events and have some external class support.
I have not used this extensively in GWT, so I can't comment on efficiency aspects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With