public class ViewPropWritable extends ViewProp {
private JavaScriptObject setFunc;
private JavaScriptObject data;
public ViewPropWritable(Binder view, ValueChangeListener uiElement,
String getExpr) {
super(view, uiElement, getExpr);
}
public ViewPropWritable(Binder view, ValueEditor uiElement,
String getExpr, String setExpr, String validExpr) {
super(view, uiElement, getExpr);
setFunc = getSetFunc(setExpr, validExpr);
((ValueEditor)uiElement).bindChangeEvent(this);
}
public void setScope(Scope scope) {
this.data = scope.getData();
}
public boolean setValue(Double value) {
return value == null ? setNull() : set(value.doubleValue());
}
public boolean setValue(Boolean value) {
return value == null ? setNull() : set(value.booleanValue());
}
public boolean setValue(Date value) {
return value == null ? setNull() : set(value.getTime());
}
public native boolean setValue(String value) /*-{
var f = this.@net.qark.core.ViewPropWritable::setFunc;
return f(this.data, value);
}-*/;
public native boolean setValue(JavaScriptObject value) /*-{
var f = this.@net.qark.core.ViewPropWritable::setFunc;
return f(this.data, value);
}-*/;
// Private methods
private native boolean set(double value) /*-{
var f = this.@net.qark.core.ViewPropWritable::setFunc;
return f(this.data, value);
}-*/;
private native boolean set(boolean value) /*-{
var f = this.@net.qark.core.ViewPropWritable::setFunc;
return f(this.data, value);
}-*/;
private native boolean setNull() /*-{
var f = this.@net.qark.core.ViewPropWritable::setFunc;
return f(this.data, value);
}-*/;
private native JavaScriptObject getSetFunc(String setExpr, String validExpr) /*-{
return function() {
var sf = new Function("$", "v", setExpr + "=v;");
if (validExpr) {
var vf = new Function("$", "v", validExpr);
return function(d, v) {
var b = v ? v(d, v) : true;
if (b) sf(d, v);
return b;
}
} else {
return function(d, v) {
return sf(d, v);
}
}
}();
}-*/;
}
BTW, the documentation of GWT 2.7 suggests that fully qualified class names are not necessary anymore, but Eclipse complains if I set this.@ViewPropWritable::setFunc for example.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment