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());
}
}
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.
On Jan 25, 4:36 am, Thomas Broyer <t.bro...@gmail.com> wrote: