I'm looking at 2.1 (RC1) for the first time right now and I try to
refactor the hellomvp sample to use GIN.
Unfortunately, I have some problems with the places -> activities
mapping. The doc says "A better way to implement the chain of nested
ifs would be with a GIN module." and the code is commented "Map each
Place to its corresponding Activity. This would be a great use for
GIN.".
I agree, but I don't really know how to do this mapping :) Has anyone
refactored this code to use GIN?
Thank you,
Sebastian
that's what I was thinking -- and I'm playing with a custom code
generator already :)
Just wondering what "they" mean with the GIN comments in the doc/code...
In my pre-2.1 homegrown framework I use a code-generated presenter
config based on a Ginjector (declaring all the getFooPresenter()
methods annotated with location (place) and security informations). My
presenters were singletons and were "started" with the actual Place.
That way I could use GIN to (constructor) inject all my dependencies.
I'm not sure if I like this 2.1-design (constructing activities with
the actual place) which means I cannot use GIN to construct them.
Maybe I make my activities extends some AbstractBaseActivity
containing a setPlace(P place) method which is called in the
ActivityMapper...
Sebastian
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
Unfortunately, the mere mention of a need for something does not imply
its current availability :-) I wrote the Activities and Places doc and
really should have left GIN out of it for the time being. The root
issue is that GIN does not have a way to createMeA(Foo.class), as such
a method might impede the GWT compiler's ability to do whole program
optimization as it does today.
Thus, the only way to implement ActivityMapper.getActivity() or
PlaceHistoryMapper.getPlace() using GIN would be to return an instance
of an Activity or Place that has previously been instantiated by GIN
and injected into to the mapper class. In other words, each Activity
and Place would have to be a singleton, much like Presenter and Place
are in the gwt-presenter framework. But in GWT 2.1, Activity and Place
are designed to be disposable, not singletons, which leaves us with
the need for "if (place instanceof SomePlace) return new
SomePlace()..." It seems like it would be possible to create
SomeActivityFactory and SomePlaceFactory classes bound as singletons
in GIN gwt-presenter style, which in turn provide newly-created
instances of SomeActivity and SomePlace, but that requires lots of
boilerplate code...
As for the onerous chain of if statements (which is sounding less
onerous all the while), it could be created at compile time using a
GWT generator, just as GWT's PlaceHistoryMapperGenerator generates a
sub-class of AbstractPlaceHistoryMapper using @WithTokenizers from
your PlaceHistoryMapper interface. The advantage of creating your own
PlaceHistoryMapper base class and generator would be the ability to
pass a ClientFactory or factory-managed objects to newly constructed
Places. That is, the generated code could do
if (token.startsWith("SomePlace"))
return new SomePlace(clientFactory, token);
else if (token.startsWith("AnotherPlace"))
return new AnotherPlace(clientFactory, token);
...
Hope that helps someone...
The GWT team is working hard to make this easier in a future point release.
/dmc
> --
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
David Chandler
Developer Programs Engineer, Google Web Toolkit
http://googlewebtoolkit.blogspot.com/
I would like to know if it's possible to customize the style of CellTable's
header. For example headers looking like buttons.
Thanks for any help
Rodrigue
public class SimplePlaceMapper implements PlaceHistoryMapper {
private ClientFactory clientFactory;
public SimplePlaceMapper(ClientFactory cf) {
this.clientFactory = cf;
}
@Override
public Place getPlace(String token) {
if (token.startsWith("helloPlace"))
return new HelloPlace(clientFactory, token);
else if (token.startsWith("goodbyePlace"))
return new GoodbyePlace(clientFactory, token);
return null;
}
@Override
public String getToken(Place place) {
if (place instanceof ActivityPlace)
return ((ActivityPlace) place).getToken();
return null;
}
}
Note that ActivityPlace has one additional method, getToken():
public abstract class ActivityPlace<T extends Activity> extends Place {
public abstract T getActivity();
public abstract String getToken();
}
You need this in your gwt.xml to turn off the
PlaceHistoryMapperGenerator that will otherwise try to generate a
class replacing SimplePlaceHistoryMapper:
<replace-with
class="com.google.gwt.sample.hellomvp.client.mvp.SimplePlaceMapper">
<when-type-assignable
class="com.google.gwt.place.shared.PlaceHistoryMapper" />
</replace-with>
You could make a GIN-aware PlaceHistoryMapper, as well, which could
call Provider.get() as you're doing; however, this would require some
gwt.xml hackery because a rebind rule like the above doesn't work with
GIN. At least, I haven't gotten it to work yet...
/dmc
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
> Where I do have an issue now though is actually going to a new Place?
>
> From HelloMVP - HelloView:
> listener.goTo(new GoodbyePlace(name));
You would need to inject Provider<GoodbyePlace> into HelloViewImpl in
order to obtain a GoodbyePlace on which you would then call setName().
Perhaps this better belongs in the HelloActivity instead, in which
case you might use a method like listener.sayGoodbye(String name),
which in turn calls the injected Provider<GoodbyePlace>.
HTH,
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
We're still working on an official story for how best to use runAsync
with Activities and Places. In the mean time, feedback on your
experiences is welcome. GWT's AsyncProxy class or the AsyncProvider in
GIN trunk look promising as ways to wrap Activity creation with a
runAsync() call.
If view creation is initiated only through the corresponding Activity,
then wrapping Activity creation with runAsync() will defer loading of
the view code also, and you'll be able to see this in the SOYC report.
References:
http://code.google.com/webtoolkit/doc/latest/DevGuideCodeSplitting.html
http://code.google.com/webtoolkit/doc/latest/DevGuideCompileReport.html
HTH,