GWT CssResource Customization

Posted by Eric Landry on Stack Overflow See other posts from Stack Overflow or by Eric Landry
Published on 2010-04-05T15:08:46Z Indexed on 2010/04/05 15:13 UTC
Read the original article Hit count: 386

Filed under:
|
|
|

I'm writing a GWT widget using UIBinder and MVP. The widget's default styles are defined in TheWidgetView.ui.xml:

<ui:style type="com.widgetlib.spinner.display.TheWidgetView.MyStyle">
    .textbox {
        border: 1px solid #red;
    }
    .important {
        font-weight: bold;
    }
</ui:style>

The widget's CssResource interface is defined in TheWidgetView.java:

public class TheWidgetView extends HorizontalPanel implements TheWidgetPresenter.Display {
    // ... some code
    @UiField MyStyle style;
    public interface MyStyle extends CssResource {
        String textbox();
        String important();
    }
    // ... more code
}

I'd like the consumer of this widget to be able to customize part of the widget's styles and to have this in their MyExample.ui.xml:

<ui:style type="com.consumer.MyExample.MyStyle">
    .textbox {
        border: 2px solid #black;
    }
</ui:style>

And this be their MyExample.java:

public class MyExample extends Composite {
    // ... some code
    @UiField MyStyle style;
    interface MyStyle extends TheWidgetView.MyStyle{
        String textbox();
    }
    // ... more code
}

Is there a way that my widget can have default styles, but that the consumer of the widget can override one of them? When an interface extends TheWidgetView.MyStyle, the of the widget consumer needs to define all the styles listed in that parent interface. I've seen some widget libraries have the widget's constructor take in a ClientBundle as parameter, which I suppose could apply to CssResource. Although, I'm not sure how I'd pass in this style object in a constructor invoked by UIBinder.

Thanks much in advance!

© Stack Overflow or respective owner

Related posts about gwt

Related posts about uibinder