3

Currently I have an application using CssResource in gwt like this...

interface MyClientBundle extends ClientBundle{

@Source("images/one.png")
Image someImageThatAlwaysLooksTheSame();

@Source("images/two.png")
Image someImageThatDependingOnTheClientThemeChanges();

@Source("css/main.css")
MyCssResource css();

}

And then the CssResource interface

interface MyCssResource extends CssResource{

String someStyleThatNeverChanges();

String someStyleThatChangesDependingOnTheClient();

}

If I override MyClientBundle to create and interface called MyPinkThemedClientBundle

interface MyClientBundle extends ClientBundle{

@Source("images/one.png")
Image someImageThatAlwaysLooksTheSame();

@Source("images/**twoPinkVersion**.png")
Image someImageThatDependingOnTheClientThemeChanges();

@Source("css/**mainPinkVersion**.css")
MyPinkCssResource css();

}

Then of course MyPinkCssResource extends MyCssResource

interface MyPinkCssResource extends MyCssResource{


} 

The problem I have is that when I try to compile this the GWT compiler complains that "css/mainPinkVersion.css" is missing the style name "someStyleThatNeverChanges". I would have thought that a cssresource interface would inherit the backing css file of its super class. If this is not the case, is it possible to achieve the effect of being able to extend a CssResource and override just the classes you care about but otherwise use the super-classes' backing .css file?

benstpierre
  • 32,833
  • 51
  • 177
  • 288

1 Answers1

6

I ran into almost exactly this issue. The solution I came up with after reading the @Import example in the GWT documentation is as follows. In your MyPinkThemedClientBundle you need to define css() method as:

@Source({"main.css", "css/**mainPinkVersion**.css"})
MyCssResource css();

If you are just overriding already defined CSS entries, and not creating any new ones that need to be accessed in your code then you won't need the MyPinkCssResource type.

David Sykes
  • 7,131
  • 4
  • 36
  • 39
  • I get "error: annotation Source is missing value for the attribute value" when I try have 2 comma separated css files. Tried GWT 2.5.1 and 2.6.0. Actually this comes from the Java compiler under Netbeans, not GWT compiler. Did you have the same issues? – Budric Apr 16 '14 at 16:25
  • Putting values in braces (since the annotation is defined as String []) like @Source({"main.css", "myPinkVersion.css"}) gets rid of java compiler error. I'm not sure how you guys are compiling it on your system and not getting these errors. – Budric Apr 16 '14 at 17:29