Search code examples
gwtcssresource

How exactly would one override a CssResource


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?


Solution

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