I think you are on the right track. The getImageResource(...) method
can be replaced with deferred binding.

On Feb 4, 2:40 am, Bob <[email protected]> wrote:
> Hi,
>
> I have a set of static objects which are retrieved from the server and
> rendered in a custom widget on the client.  Each of these objects has
> an image associated with it.  I want these images to be themeable,
> such that the entire set of images used for these objects can be
> swapped out.  For example, say there is a Cat object and a Dog object,
> and there is a 'domestic'themeand a 'wild'theme.   Thethemeis a
> user option.  If the wildthemeis selected, the images should be a
> cheetah and a dingo.  With the domesticthemethey would be a calico
> cat and a golden retriever.
>
> My thought was that I could distribute these image themes as
> ClientBundles.  So I implemented something like this:
>
> public interface ImageTheme {
>     ImageResource cat();
>     ImageResource dog();
>
> }
>
> public interface WildImageTheme extends ClientBundle, ImageTheme {
>     @Source("cheetah.jpg")
>     ImageResource cat();
>
>     @Source("dingo.jpg")
>     ImageResource dog();
>
> }
>
> public interface DomesticImageTheme extends ClientBundle, ImageTheme {
>     @Source("calico.jpg")
>     ImageResource cat();
>
>     @Source("golden-retriever.jpg")
>     ImageResource dog();
>
> }
>
> But then I end up needing some ugly and hard-to-maintain binding code
> on the client like this:
>
> public static ImageTheme CURRENT_THEME = (ImageTheme) GWT.create
> (DomesticImageTheme.class)
>
> public ImageResource getImageResource(String animalName) {
>     if ("Cat".equals(animalName)) {
>         return CURRENT_THEME.cat();
>     } else if ("Dog".equals(animalName)) {
>         return CURRENT_THEME.dog();
>     }
>     [...]
>
> }
>
> If it were available to me, I could use reflection to bind the animal
> names to matching method names, but obviously it isn't.  Deferred
> binding is described as GWT's answer to reflection, but does it fit
> here?  Is my ClientBundle asthemepack paradigm flawed?  Does anyone
> have a suggestion for a better way to accomplish this?
>
> Thanks,
> Bob

-- 
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