How to get com.google.web.bindery.event.shared.EventBus instance in com.google.gwt.user.client.ui.Composite extending class?;
I've readed: How to use EventBus for non-Presenter class in GWTP?, but I am looking for answer like:
BEST APPROACHES TO GWT DEVELOPMENT
I have widget that I would like to fire an event IndicatorEvent. But in this widget I don't have a handler for this event.
The handler is in other class. So to fire it I will use:
fireEvent(new IndicatorEvent("Custom Widget Message"));
Method fireEvent is avalible in com.google.web.bindery.event.shared;EventBus
public abstract void fireEvent(Event<?> event);
So I need an instance of EventBus in view class that extends Composite. This view doesn't have MVP stuff (presenters, uihandlers, etc.) it is simple one class element/widget.
What approach should I pick up?
- Should I convert this to
Presenter/Viewpair? (In gwtp presenters is EventBus reference fromPresenterWidgetclass) And then using ui handlers, delegate execution from view to presenter? - Should I
injectinstance ofEventBusinto widget class?
Please help.
We can assign only single component per view. So approach first doesn't make any sense as we creates lots of component/widgets for all small sections from particular view.
Second approach is comparatively more likable if we are already using some dependency injection framework like gin or dagger2.
I can add one more approach is to have simple setter method in component for passing eventBus instance from the parent class like presenter or controller where we are using/creating component object.
My conclusion will be it absolutely depends upon purpose and implementation of component. If we have interface-implementation or presenter-implementation kind of component stating some common behavior second approach is best suitable way. On the other hand if we have simple plane component serving just as small part of view, I will recommend third approach.