On 5 oct, 00:45, Chris Burrell <[email protected]> wrote:
> Hi
>
> I want to build a view in GWT but it is one of a few different types of
> views. So I was thinking, I could
> have them all share something common via inheritance, so that I could inject
> any kind of view I'd like into my module...
> I'm having trouble binding one of those things together. Any help would be
> welcome...
>
> Here's the idea:
>
> The new abstract presenter that things will be based upon:
>
> public abstract class StepModulePresenter<T extends
> StepModulePresenter.Display> extends WidgetPresenter<T> {
>
>     public interface Display extends WidgetDisplay {
>
>     }
>
>     @Inject
>     public StepModulePresenter(T display, EventBus eventBus) {
>         super(display, eventBus);
>     }
>
> }
>
> It defines an interface that inherits the WidgetDisplay. Then for example, a
> particular type of StepModulePresenter would be:
>
> public class HistoryModulePresenter extends
> StepModulePresenter<HistoryModulePresenter.Display> {
>
>     @Inject
>     public HistoryModulePresenter(Display display, EventBus eventBus) {
>         super(display, eventBus);
>         bind();
>     }
>
> ...
>
> }
>
> So my view can be defined as:
> public class HistoryModuleView extends Composite implements
> HistoryModulePresenter.Display {
>     HistoryModuleView() { ... }
>
> }
>
> So far so good. Now I'd like to use my HistoryModuleView but passed in as a
> StepModule in my Main app view:
>
> public class MainView extends Composite implements MainPresenter.Display {
>     @Inject
>     public MainView(P1 p1, P2 p2, P3 p3,
> StepModulePresenter<StepModulePresenter.Display> module) { ... }

HistoryModulePresenter is a
StepModulePresenter<HistoryModulePresenter.Display>, not a
StepModulePresenter<StepModulePresenter.Display>, so you can't use one
for the other (well, you can, but you'll have an "unchecked cast").

I'd rather define the ctor as:
@Inject
public MainView(P1 p1, P2 p2, P3 p3, StepModulePresenter<? extends
StepModulePresenter.Display> module) { ... }

> What I don't get is how to bind the HistoryModule as the thing that gets
> passed in here... And then later on, how I make it one of many things that
> can be passed in:

Not tested, but you should be able to write:
bind(new TypeLiteral<StepModulePresenter<? extends
StepModulePresenter.Display>() { }).to(HistoryModulePresenter.class);

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to