Google-Gin in GWT 2.1 RC

19 views
Skip to first unread message

waldo2188

unread,
Oct 14, 2010, 9:45:01 AM10/14/10
to google-gin
Hi !

Is there an easy way to implement google-gin in the new GWT 2.1 RC1 or
it's too early for that?

The new features of MVP pattern (activity, place, ui, …) are very
interesting, but with google-gin i'll be seriously sexy.

Thanks in advance for your answer.

Peter Schmitt

unread,
Oct 14, 2010, 10:58:08 AM10/14/10
to googl...@googlegroups.com
Hi,

not quite sure what you'd like to have - generally you should be able to use Gin with any GWT feature, without any changes to the Gin library. :)

Peter


--
You received this message because you are subscribed to the Google Groups "google-gin" group.
To post to this group, send email to googl...@googlegroups.com.
To unsubscribe from this group, send email to google-gin+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gin?hl=en.


waldo2188

unread,
Oct 14, 2010, 11:17:45 AM10/14/10
to google-gin
Is there a basic example of integration with GWT 2.1 and its new MVP.
An example that would fit in the example given by Google here:
http://code.google.com/webtoolkit/doc/trunk/DevGuideMvpActivitiesAndPlaces.html
?

Waldo


On Oct 14, 4:58 pm, Peter Schmitt <ara...@gmail.com> wrote:
> Hi,
>
> not quite sure what you'd like to have - generally you should be able to use
> Gin with any GWT feature, without any changes to the Gin library. :)
>
> Peter
>
> On Thu, Oct 14, 2010 at 09:45, waldo2188 <waldo2...@gmail.com> wrote:
> > Hi !
>
> > Is there an easy way to implement google-gin in the new GWT 2.1 RC1 or
> > it's too early for that?
>
> > The new features of MVP pattern (activity, place, ui, …) are very
> > interesting, but with google-gin i'll be seriously sexy.
>
> > Thanks in advance for your answer.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "google-gin" group.
> > To post to this group, send email to googl...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-gin+...@googlegroups.com<google-gin%2Bunsu...@googlegroups.com>
> > .

Thomas Broyer

unread,
Oct 15, 2010, 9:15:00 AM10/15/10
to google-gin
> > On Thu, Oct 14, 2010 at 09:45, waldo2188 <waldo2...@gmail.com> wrote:
> > > Hi !
>
> > > Is there an easy way to implement google-gin in the new GWT 2.1 RC1 or
> > > it's too early for that?
>
> > > The new features of MVP pattern (activity, place, ui, …) are very
> > > interesting, but with google-gin i'll be seriously sexy.

See http://code.google.com/p/google-gin/issues/detail?id=117

On 14 oct, 17:17, waldo2188 <waldo2...@gmail.com> wrote:
> Is there a basic example of integration with GWT 2.1 and its new MVP.
> An example that would fit in the example given by Google here:http://code.google.com/webtoolkit/doc/trunk/DevGuideMvpActivitiesAndP...
> ?

It's as easy as (I haven't tested though):
1. make ClientFactory extend Ginjector and add
@GinModules(ClientFactoryImpl.class)
2. remove the <replace-with> for ClientFactory from the gwt.xml and
add the <inherits> for GIN
3. rewrite ClientFactoryImpl as a GinModule
public class ClientFactoryImpl extends AbstractGinModule {
public void configure() {

bind(EventBus.class).to(SimpleEventBus.class).as(Singleton.class);

bind(HelloView.class).to(HelloViewImpl.class).as(Singleton.class);

bind(GoodbyeView.class).to(GoodbyeViewImpl.class).as(Singleton.class);
}

@Provides @Singleton
PlaceController providesPlaceController(EventBus eventBus) {
return new PlaceController(eventBus);
}
}

To make things a bit simpler in your module, you can also replace the
2 bind() on the views with annotations on the interfaces instead:
@ImplementedBy(HelloViewImpl.class) @Singleton

And you can go further by having AppActivityMapper being @Inject'ed
Provider<>s for the activities (and you'll annotate their constructor
with @Inject) instead of new'ing them, and add some bindings and
providers for the PlaceHistoryXxx thing too (moving almost all the
HelloMVP code into the GIN module)

atoy40

unread,
Oct 20, 2010, 5:59:12 PM10/20/10
to google-gin

>
> And you can go further by having AppActivityMapper being @Inject'ed
> Provider<>s for the activities (and you'll annotate their constructor
> with @Inject) instead of new'ing them, and add some bindings and
> providers for the PlaceHistoryXxx thing too (moving almost all the
> HelloMVP code into the GIN module)

Hi,

i'm also looking to integrate GIN with gwt2.1 and espacially the MVP
part. Into the Google MVP example code, the ActivityMapper is defined
as (note the comment) :

public Activity getActivity(Place place)
{
// This is begging for GIN
if (place instanceof HelloPlace)
return new HelloActivity((HelloPlace) place, clientFactory);
else if (place instanceof GoodbyePlace)
return new GoodbyeActivity((GoodbyePlace) place, clientFactory);
}

My questions are :

- what is begging ? the "new" ? or the chain of "if+instanceof" (i
don't know how you can omit/replace it using GIN) ?
- how, if you use a set of Provider<PlaceType>, can you transmit the
place instance (which can contains important information for the
activity) to the activity ?

Thank you.

Anthony.

Peter Schmitt

unread,
Oct 21, 2010, 5:00:37 PM10/21/10
to googl...@googlegroups.com
- what is begging ? the "new" ? or the chain of "if+instanceof" (i
don't know how you can omit/replace it using GIN) ?
- how, if you use a set of Provider<PlaceType>, can you transmit the
place instance (which can contains important information for the
activity) to the activity ?

From what I can see there is (unfortunately) no straightforward way to replace ActivityMapper with a Gin-generated version. The presence of the GWT ActivityManager that relies on specific interfaces (like ActivityMapper) makes it hard to wire things up completely automatically with Gin. However, you can certainly replace large parts of the generation with Gin construction. I don't have the time to try this out for now but I encourage you to try and build some injection around this new framework, I expect it will reduce the setup significantly.

Hope this helps!

Peter
 

Thank you.

Anthony.

--
You received this message because you are subscribed to the Google Groups "google-gin" group.
To post to this group, send email to googl...@googlegroups.com.
To unsubscribe from this group, send email to google-gin+...@googlegroups.com.

Thomas Broyer

unread,
Oct 22, 2010, 5:59:11 AM10/22/10
to google-gin


On 20 oct, 23:59, atoy40 <anthony.hinsin...@gmail.com> wrote:
> > And you can go further by having AppActivityMapper being @Inject'ed
> > Provider<>s for the activities (and you'll annotate their constructor
> > with @Inject) instead of new'ing them, and add some bindings and
> > providers for the PlaceHistoryXxx thing too (moving almost all the
> > HelloMVP code into the GIN module)
>
> Hi,
>
> i'm also looking to integrate GIN with gwt2.1 and espacially the MVP
> part. Into the Google MVP example code, the ActivityMapper is defined
> as (note the comment) :
>
> public Activity getActivity(Place place)
> {
>     // This is begging for GIN
>     if (place instanceof HelloPlace)
>         return new HelloActivity((HelloPlace) place, clientFactory);
>     else if (place instanceof GoodbyePlace)
>         return new GoodbyeActivity((GoodbyePlace) place, clientFactory);
>
> }
>
> My questions are :
>
> - what is begging ? the "new" ? or the chain of "if+instanceof" (i
> don't know how you can omit/replace it using GIN) ?

As Peter said, I don't think you can replace the "if" cascade with GIN
(though you can do it with a GWT code generator, I've already done it:
http://gwt-code-reviews.appspot.com/845802/diff/46002/38011 ), so it's
probably the "new" thing.

> - how, if you use a set of Provider<PlaceType>, can you transmit the
> place instance (which can contains important information for the
> activity) to the activity ?

The idea (IMO) would be to use AssistedInject (or you own hand-crafted
factories if you don't want/can't use GIN 1.1-SNAPSHOT / Guice 2.1-
SNAPSHOT) with Provider<ActivityType>:

public Activity getActivity(Place place) {
if (place instanceof HelloPlace)
return helloActivityProvider.get(((HelloPlace) place);
else if (place instanceof GoodbyePlace)
return goodbyeActivityProvider.get((GoodbyePlace) place);
}

Note how the dependency on clientFactory (which mean: any dependency)
is moved to the provider/factory, which GIN can inject (and you use
AssistedInject, there's even less to code).

Thomas Broyer

unread,
Oct 22, 2010, 6:27:43 AM10/22/10
to google-gin
For those interested, the answers from the developer who wrote the
"this is begging for GIN" comment:
http://groups.google.com/group/google-web-toolkit-contributors/msg/38a3f36ffc1767a0
http://groups.google.com/group/google-web-toolkit/msg/82f0098b20669a73

On 22 oct, 11:59, Thomas Broyer <t.bro...@gmail.com> wrote:
> On 20 oct, 23:59, atoy40 <anthony.hinsin...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > > And you can go further by having AppActivityMapper being @Inject'ed
> > > Provider<>s for the activities (and you'll annotate their constructor
> > > with @Inject) instead of new'ing them, and add some bindings and
> > > providers for the PlaceHistoryXxx thing too (moving almost all the
> > > HelloMVP code into the GIN module)
>
> > Hi,
>
> > i'm also looking to integrate GIN with gwt2.1 and espacially the MVP
> > part. Into the Google MVP example code, the ActivityMapper is defined
> > as (note the comment) :
>
> > public Activity getActivity(Place place)
> > {
> >     // This is begging for GIN
> >     if (place instanceof HelloPlace)
> >         return new HelloActivity((HelloPlace) place, clientFactory);
> >     else if (place instanceof GoodbyePlace)
> >         return new GoodbyeActivity((GoodbyePlace) place, clientFactory);
>
> > }
>
> > My questions are :
>
> > - what is begging ? the "new" ? or the chain of "if+instanceof" (i
> > don't know how you can omit/replace it using GIN) ?
>
> As Peter said, I don't think you can replace the "if" cascade with GIN
> (though you can do it with a GWT code generator, I've already done it:http://gwt-code-reviews.appspot.com/845802/diff/46002/38011), so it's
Reply all
Reply to author
Forward
0 new messages