public void put(String id, Scriptable start, Object value) {
if (delegate instanceof Repeater) {
if (id.equals("length")) {
int len = (int)Context.toNumber(value);
Repeater repeater = (Repeater)delegate;
int size = repeater.getSize();
if (size > len) {
while (repeater.getSize() > len) {
repeater.removeRow(repeater.getSize() -1);
}
} else {
for (int i = size; i < len; ++i) {
repeater.addRow();
}
}
}
} else if (delegate != null) {
Widget sub = delegate.getWidget(id);
if (sub instanceof Field) {
Field field = (Field)sub;
value = unwrap(value);
if (value instanceof Double) {
// make woody accept a JS Number
Class typeClass =
field.getFieldDefinition().getDatatype().getTypeClass();
if (typeClass == long.class || typeClass == Long.class) {
value = new Long(((Number)value).longValue());
} else if (typeClass == int.class || typeClass == Integer.class) {
value = new Integer(((Number)value).intValue());
} else if (typeClass == float.class || typeClass == Float.class) {
value = new Float(((Number)value).floatValue());
} else if (typeClass == short.class || typeClass == Short.class) {
value = new Short(((Number)value).shortValue());
}
}
field.setValue(value);
return;
} else if (sub instanceof BooleanField) {
BooleanField field = (BooleanField)sub;
value = unwrap(value);
field.setValue(value);
} else if (sub instanceof Output) {
Output field = (Output)sub;
value = unwrap(value);
field.setValue(value);
} else if (sub instanceof Repeater) {
Repeater repeater = (Repeater)sub;
if (value instanceof NativeArray) {
NativeArray arr = (NativeArray)value;
Object length = getProperty(arr, "length");
int len = ((Number)length).intValue();
for (int i = repeater.getSize(); i >= len; --i) {
repeater.removeRow(i);
}
for (int i = 0; i < len; i++) {
Object elemValue = getProperty(arr, i);
if (elemValue instanceof Scriptable) {
Scriptable s = (Scriptable)elemValue;
Object[] ids = s.getIds();
ScriptableWidget wid = wrap(repeater.getRow(i));
for (int j = 0; j < ids.length; j++) {
String idStr = ids[j].toString();
wid.put(idStr, wid, getProperty(s, idStr));
}
}