2010-07-08 22 views
3

這個問題最好用一個例子來描述。GWT:如何從同一個ClientBundle在另一個樣式表中定義的一個樣式表常量中訪問

我在我的GWT應用中的以下ClientBundle:

interface Resources extends ClientBundle { 
    public static final Resources INSTANCE = GWT.create(Resources.class); 

    @Source("defines.css") 
    Defines defines(); 

    @Source("appStyle.css") 
    @CssResource.NotStrict 
    Style style(); 

    interface Style extends CssResource { 
     String appLogo(); 
     (...) 
    } 

    interface Defines extends CssResource { 
     String formInputBackgroundColor(); 
     String formInputBorderColor(); 
     (...) 
    } 
} 

appStyle.css是由應用程序使用的主要樣式表和defines.css是包含只喜歡常量樣式表:

@def formInputBackgroundColor #D8ECFD; 
@def formInputBorderColor #7FAAFF; 
(...) 

現在我可以使用UIBinder模板中的defines.css樣式表中的常量和應用程序代碼沒有問題,但我不能在我的appStyle.css中使用這些常量。

我已經嘗試與interface Style extends Defines更換interface Style extends CssResource,希望從Defines樣式繼承會給我訪問的常量「子」 Style樣式,但隨後的GWT編譯器一樣的錯誤抱怨:

Rebinding my.project.client.resources.Resources 
    Creating assignment for style() 
     Replacing CSS class names 
      The following obfuscated style classes were missing from the source CSS file: 
       formInputBorderColor: Fix by adding .formInputBorderColor{} 
       formInputBackgroundColor: Fix by adding .formInputBackgroundColor{} 
       (...) 

有什麼辦法可以做到這一點?

回答

1

我找到了一種方法來做到這一點,但它遠非優雅,我更喜歡另一種解決方案,如果可能的話,使用某種繼承或註釋。

我得到它的工作方式是@eval每個常量我需要defines.cssappStyle.css樣式表中,但這會導致大量的代碼重複,並且這是一個混亂的mantain。

@eval formInputBackgroundColor Resources.INSTANCE.defines().formInputBackgroundColor(); 
@eval formInputBorderColor Resources.INSTANCE.defines().formInputBorderColor(); 

如果您有更好的解決方案,請分享。

1

更換

@Source("appStyle.css") 

@Source({"defines.css", "appStyle.css"}) 

應該做的伎倆。通過指定兩個css文件,你的style()將是這兩者的聯合。

相關問題