GWT 2.1 MVP with GIN

115 views
Skip to first unread message

Tolga Tarhan

unread,
Oct 19, 2010, 8:31:11 PM10/19/10
to google-web-tool...@googlegroups.com
Folks,

I'm trying to make GWT 2.1 MVP work nicely with GIN. It looks like this use case was specifically considered when creating PlaceHistoryMapperWithFactory, but no such thing seems to exist for ActivityMapper. There is a passing reference to using Gin in DevGuideMvpActivitiesAndPlaces.html , where it says "... ClientFactory is used by HelloActivity to obtain a reference to the HelloView as well as the EventBus and PlaceController. Any of these could alternatively be injected via GIN." and also when it says "A better way to implement the chain of nested ifs would be with a GIN module", in reference to ActivityMapper.

The problem, however, is that we cannot both inject application-level objects (EventBus, PlaceController, etc) and also pass the Place as constructor arguments to the Activity. We could have all of the dependencies for every Activity (like all the views) injected into our ActivityMapper and pass them thru, but this leaks a lot of details into what should be a very simple mapper class. If done incorrectly, it would also cause code-splitting issues.

One way around this is to inject a Provider<MyActivity> or AsyncProvider<MyActivity> in the ActivityMapper and then do something like myActivityProvider.get().initPlace(place) - which is like the assisted injection that's discussed in the Guice docs. I'm wondering if there's a more elegant way that was considered?

Additionally, I'm not sure I understand how to "implement the chain of nested ifs" in a GIN module. This sounds like a great idea, but what did you have in mind to make GIN do this for us? We can have GIN differentiate on a bunch of things (annotations, generics, interfaces, etc), but I don't know how you could replace the if-block with GIN. Could someone point me in the right direction here?

Thanks,
Tolga

Aigeec

unread,
Oct 20, 2010, 8:54:17 AM10/20/10
to Google Web Toolkit Contributors
Hey Guys,

I am also interested in an implementation of GWT 2.1 MVP using GIN.

I have made some head way with it.

This has been done mostly by extending the ActivityManager,
PlaceController and PlaceHistoryHandler classes and overriding their
constructors to use GIN injection. I don't know if this is the correct
implementation and if anyone has comments please let me know. But I
have been able to remove the need for the ClientFactory and use GIN
injection to instantiate everything but the Activity classes.

However, I do not know how to tackle the ActivityMapper class.

As Tolga says how do we replace the nested if statement with a GIN
module?

I would much prefer to be able to instantiate the Activity Class this
way as I am using the SecureDispatchAsync as would like to use DI to
pass it to the Activity.

Regards,

Aigeec

David Chandler

unread,
Oct 20, 2010, 11:32:10 AM10/20/10
to google-web-tool...@googlegroups.com
Hmmm, I see my comments about GIN in the ActivityMapper have caught up
with me. I haven't worked this out fully yet, but was thinking of
something along the lines of gwt-presenter's <a
href="http://code.google.com/p/gwt-presenter/source/browse/src/main/java/net/customware/gwt/presenter/client/place/PresenterPlace.java">PresenterPlace</a>.
My thought is to use GIN in place of the ClientFactory, and to write
ActivityMapper.getActivity() like this:

public Activity getActivity(Place place) {
if (place instanceof ActivityPlace)
{
return ((ActivityPlace) place).getActivity();
}
}

where an ActivityPlace would be obtained from a GIN-aware
PlaceHistoryMapperWithFactory implementation so it can be injected
with the EventBus, etc.

> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors
>

--
David Chandler
Developer Programs Engineer, Google Web Toolkit
http://googlewebtoolkit.blogspot.com/

David

unread,
Oct 20, 2010, 2:02:34 PM10/20/10
to google-web-tool...@googlegroups.com
Why not include Gin in GWT 2.1 ? It could maybe be useful inside the
GWT codebase as well ?

> --
> http://groups.google.com/group/Google-Web-Toolkit-Contributors

Aigeec

unread,
Oct 21, 2010, 12:32:57 PM10/21/10
to Google Web Toolkit Contributors
Hey guys,

Thanks David for your thoughts on how it could be implemented.

Perhaps you could provide an example of using the
PlaceHistoryMapperWithFactory.

Regards,

Aodhagán

On Oct 20, 7:02 pm, David <david.no...@gmail.com> wrote:
> Why not include Gin in GWT 2.1 ? It could maybe be useful inside the
> GWT codebase as well ?
>
>
>
>
>
>
>
> On Wed, Oct 20, 2010 at 5:32 PM, David Chandler <drfibona...@google.com> wrote:
> > Hmmm, I see my comments about GIN in the ActivityMapper have caught up
> > with me. I haven't worked this out fully yet, but was thinking of
> > something along the lines of gwt-presenter's <a
> > href="http://code.google.com/p/gwt-presenter/source/browse/src/main/java/ne...">PresenterPlace</a>.
> > My thought is to use GIN in place of the ClientFactory, and to write
> > ActivityMapper.getActivity() like this:
>
> >        public Activity getActivity(Place place) {
> >                if (place instanceof ActivityPlace)
> >                {
> >                        return ((ActivityPlace) place).getActivity();
> >                }
> >        }
>
> > where an ActivityPlace would be obtained from a GIN-aware
> > PlaceHistoryMapperWithFactory implementation so it can be injected
> > with the EventBus, etc.
>

David Chandler

unread,
Oct 21, 2010, 3:29:44 PM10/21/10
to google-web-tool...@googlegroups.com
Moving this thread to the general GWT forum, where I've written a bit
more about it:

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2ed199a42c500156/b54c0c00cd73ed8f#b54c0c00cd73ed8f

/dmc

Reply all
Reply to author
Forward
0 new messages