tags:

views:

55

answers:

2

in my ui.xml, i have style like below

<ui:style src="../teststyle.css" />

if i want to programmatically use the style inside java file rather than ui.xml, in my widget how to call .setStyleName(..) as the css is obfuscated

+2  A: 

if i understand your question correct you have to define a class which extends from CssResource (you probably have done that already). In your view you can have a static instance of this class (let's call it cssInstance). In the constructor you have to call cssInstance.ensureInjected(). If you now want to add or set a style you can do it easly like Example: anyWidget.addStyleName(cssInstance.styleBorder());

kukudas
In addition: http://code.google.com/intl/en/webtoolkit/doc/latest/DevGuideUiBinder.html#Programmatic_access
axtavt
yes rtfm is always good :)
kukudas
+2  A: 

You need to do the following steps to use the styles in your view class:

  • Define a interface that extends CssResource in your view class
interface Style extends CssResource {

    String myStyle();

}
  • Add a ui field of that type you just defined in your view class
@UiField
Style style;
  • In your ui.xml add the type attribute to your <ui:style> element (the type must match the interface of step 1):
<ui:style type="com.example.MyView.Style">
  • For each of the css classes you want to access in your view class you need to add a method to the Style interface (as done with myStyle())

  • You can now access the style via the style field (style.myStyle())

Hope that helps.

z00bs
Actually, the field has to be named 'style', not 'css'; or you should set an explicit field="" attribute on your <ui:style> to name the Java field, just like ui:field="" on elements and widgets.
Thomas Broyer
Thanks for pointing that out. I didn't copy that part of my code.
z00bs