Using CssResource constant definitions in UiBunder styles

17 views
Skip to first unread message

jarrod

unread,
Jan 2, 2010, 4:58:08 PM1/2/10
to Google Web Toolkit Contributors
I have setup a global ClientBundle for my app that contains a global
CssResource. I want the global CssResource to make available certain
constants (such as colors, font sizes, and so forth) so those style
definitions may easily be reused elsewhere in my application - as
dependent styles, if you will.

Below are several code files illustrating what I'm trying to do:

>> Global.java

public interface Global extends ClientBundle {

public interface Style extends CssResource {
String getLightColor();
String getDarkColor();
}

@Source("global.css")
Style style();

}

<<


>> global.css

@def darkColor #333333;
@def lightColor #CCCCCC;

<<


>> MyEntryPoint.java

public class MyEntryPoint implements EntryPoint {

public void onModuleLoad() {
GWT.<Global> create(Global.class).style().ensureInjected();
RootPanelLayout.get().add(new MyWidget());
}

}

<<


>> MyWidget.java

public class MyWidget extends Composite {

interface Binder extends UiBinder<Widget, MyWidget> {}
private static Binder binder = GWT.create(Binder.class);

public MyWidget() {
initWidget(binder.createAndBind(this));
}

}

<<


>> MyWidget.ui.xml

<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">

<ui:with field="global" type="Global" />

<ui:style>
@def DARK value('global.style.darkColor');

.myStyle {
background-color: value('global.style.darkColor'); /* method 1:
this doesn't work */
}
.foo {
background-color: DARK; /* method 2: this doesn't work either */
}
</ui:style>

<g:HTML styleName="{style.myStyle}">
<span class="{style.foo}" style="color:
{global.style.lightColor};">Method 3: This text is colored properly
when using the inline style attribute.</span>
</g:HTML>

</ui:UiBinder>

<<

Does anyone have a suggestion as to how I could use the colors defined
in Global.Style in other contexts, such as UiBinder *.ui.xml layouts?

With methods 1 or 2 above, I get a compiler error as follows:
00:38:55.817 [ERROR] Could not find no-arg method named global in type
MyWidget_BinderImpl_GenBundle

Clearly the generators can find the styles I'm interested in, since
method 3 does work, albeit incredibly cumbersome...

Thomas Broyer

unread,
Jan 2, 2010, 7:07:41 PM1/2/10
to Google Web Toolkit Contributors
Hi,

On Jan 2, 10:58 pm, jarrod <jarrod.carl...@gmail.com> wrote:
> I have setup a global ClientBundle for my app that contains a global
> CssResource. I want the global CssResource to make available certain
> constants (such as colors, font sizes, and so forth) so those style
> definitions may easily be reused elsewhere in my application - as
> dependent styles, if you will.

See http://groups.google.com/group/google-web-toolkit-contributors/t/ca91dbdeaa6f93e8

Reply all
Reply to author
Forward
0 new messages