ActivityMapper with GIN

114 views
Skip to first unread message

Tom Meech

unread,
Aug 30, 2011, 6:42:05 AM8/30/11
to google-we...@googlegroups.com
I have been working with Activities and Places to develop an application in GWT.

I'm fairly pleased with how it's going so far, but I'm struggling to find a nice way to make my ActivityMapper work with GIN.
Here is some example code for my activity mapper

public class MyActivityMapper implements ActivityMapper {
private ClientFactory clientFactory;
@Inject
private Provider<TestActivity> provider;
@Inject
public MyActivityMapper(ClientFactory clientFactory) {
super();
this.clientFactory = clientFactory;
}
@Override
public Activity getActivity(final Place place) {
if (place instanceof TestPlace) {
TestActivity activity = provider.get().withPlace((TestPlace)place);
return activity;
}
        return null;
}
}

The provider allows the activity to be injected with the it's various dependencies, including the view, configured in the GinModule. It's all works quite nicely, but the mapper gets a little cumbersome as more and more activities are added to the application.

Does anyone have any suggestions to reduce the amount of "instanceof" boiler plate code?

Many thanks

Tom

Thomas Broyer

unread,
Aug 30, 2011, 7:09:40 AM8/30/11
to google-we...@googlegroups.com
If you only have "instanceof" checks, then you can use a GWT generator (see http://gwt-code-reviews.appspot.com/845802/diff/46002/user/src/com/google/gwt/app/rebind/ActivityMapperGenerator.java )

But experience told me "instanceof" checks are not enough.

Juan Pablo Gardella

unread,
Aug 30, 2011, 7:30:32 AM8/30/11
to google-we...@googlegroups.com
Check last comments in http://wanderingcanadian.posterous.com/hello-mvp-with-gin

2011/8/30 Thomas Broyer <t.br...@gmail.com>
If you only have "instanceof" checks, then you can use a GWT generator (see http://gwt-code-reviews.appspot.com/845802/diff/46002/user/src/com/google/gwt/app/rebind/ActivityMapperGenerator.java )

But experience told me "instanceof" checks are not enough.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/3-vrSk03yTEJ.

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.

Tom Meech

unread,
Aug 30, 2011, 9:12:47 AM8/30/11
to google-we...@googlegroups.com
Thank you. 

I did consider writing a generator, but as you say, just "instanceof" checks might not be enough. It's gives me some ideas though.

Reading through some of the comments on the The Wandering Canadian blog has given me some more ideas. The ActivityPlace that can be found in http://www.bright-creations.com/wp-content/uploads/2010/10/ContactsClientFactoryGin3-export.zip is an interesting solution.

Thanks again.

Tom

Reply all
Reply to author
Forward
0 new messages