programatically using CssResource styles in 2.0

17 views
Skip to first unread message

ross

unread,
Jan 24, 2010, 11:38:39 PM1/24/10
to Google Web Toolkit
Hi,

This is probably a very noob question but I have updated my project to
GWT 2.0 and I am trying to rewrite some of my Widgets to use
Declarative UI because it looks very promising and cool!

However, I am a little stumped on how to apply CssResource styles
dynamically in my code. I found the trailing info on the site (http://
code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html) and
copied it here for convenience. The part that stumps is me is the
following lines:

void setEnabled(boolean enabled) {
getElement().addStyle(enabled ? : style.enabled() : style.disabled
());
getElement().removeStyle(enabled ? : style.disabled() :
style.enabled());
}

There do not appear to be addStyle(String) and removeStyle(String)
methods in the Element class?? Am I missing something obvious? I
hope so!

thanks!

--------------------------
Programmatic access to inline Styles
Your code will need access to at least some of the styles your
template uses. For example, suppose your widget needs to change color
when it's enabled or disabled:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>

<ui:style type='com.my.app.MyFoo.MyStyle'>
.redBox { background-color:pink; border: 1px solid red; }
.enabled { color:black; }
.disabled { color:gray; }
</ui:style>

<div class='{style.redBox} {style.enabled}'>I'm a red box widget.</
div>

</ui:UiBinder>
public class MyFoo extends Widget {
interface MyStyle extends CssResource {
String enabled();
String disabled();
}

@UiField MyStyle style;

/* ... */

void setEnabled(boolean enabled) {
getElement().addStyle(enabled ? : style.enabled() : style.disabled
());
getElement().removeStyle(enabled ? : style.disabled() :
style.enabled());
}
}

Thomas Broyer

unread,
Jan 25, 2010, 4:36:29 AM1/25/10
to Google Web Toolkit

On Jan 25, 5:38 am, ross <ross.m.sm...@googlemail.com> wrote:
> Hi,
>
> This is probably a very noob question but I have updated my project to
> GWT 2.0 and I am trying to rewrite some of my Widgets to use
> Declarative UI because it looks very promising and cool!
>
> However, I am a little stumped on how to apply CssResource styles
> dynamically in my code.  I found the trailing info on the site (http://
> code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html) and
> copied it here for convenience.  The part that stumps is me is the
> following lines:
>
> void setEnabled(boolean enabled) {
>     getElement().addStyle(enabled ? : style.enabled() : style.disabled
> ());
>     getElement().removeStyle(enabled ? : style.disabled() :
> style.enabled());
>   }
>
> There do not appear to be addStyle(String) and removeStyle(String)
> methods in the Element class??  Am I missing something obvious?  I
> hope so!

The methods are actually named addClassName and removeClassName.

Ewald Pankratz

unread,
Jan 25, 2010, 5:21:11 AM1/25/10
to Google Web Toolkit
I tried to understand the problem and the solution and spend some time
to fix the problem. But I always get compiler errors. Would be glad
if you could give me the full solution.

ross

unread,
Jan 26, 2010, 9:31:14 PM1/26/10
to Google Web Toolkit
thanks for the help Thomas!

On Jan 25, 4:36 am, Thomas Broyer <t.bro...@gmail.com> wrote:

Reply all
Reply to author
Forward
0 new messages