for (java.lang.reflect.Field f : fs) {
String chId = f.getName();
Class type = f.getType();
Binding binding = bnd.getBinding(chId);
binding.setName(chId);
Object adapter = new ClassAdapterFactory().getAdapter(type,
IValidator.class);
if (adapter != null) {
binding.setAdapter(IValidator.class, (IValidator) adapter);
}
binding.setAutoCommit(false);
if (type == String.class) {
OneLineTextElement<String> t = new OneLineTextElement<String>();
t.setBinding(binding);
editor.add(t);
} else if (Number.class.isAssignableFrom(type)
|| type.isPrimitive()) {
OneLineTextElement<Number> t = new OneLineTextElement<Number>();
final Class tt = type;
binding.addValidator(new ValidatorAdapter() {
public CodeAndMessage isValid(IBinding context,
Object object) {
if (object == null) {
return CodeAndMessage.OK_MESSAGE;
}
try {
if (object instanceof String) {
if (tt == Double.class) {
Double.parseDouble((String) object);
} else if (tt == Long.class) {
Long.parseLong((String) object);
} else if (tt == Float.class) {
Float.parseFloat((String) object);
} else if (tt == Integer.class) {
Integer.parseInt((String) object);
}
} else {
if (!Number.class.isAssignableFrom(object
.getClass())) {
return CodeAndMessage
.errorMessage("The number should be in this place");
}
}
return CodeAndMessage.OK_MESSAGE;
} catch (NumberFormatException e) {
return CodeAndMessage
.errorMessage("The number should be in this place");
}
// return super.isValid(context, object);
}
});
t.setBinding(binding);
editor.add(t);
} else if (type == Boolean.class) {
ComboEnumeratedValueSelector<Boolean> t = new ComboEnumeratedValueSelector<Boolean>();
t.setBinding(binding);
editor.add(t);
} else if (type == Text.class) {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
editor.setData("text", text);
editor.add(text);
}
createText(editor, text, binding, false);
} else if (type == Link.class) {
createLink(editor, binding);
} else if (type == Category.class) {
createCategory(editor, binding);
} else if (type == Email.class) {
createEmail(editor, binding);
} else if (type == PostalAddress.class) {
createPostalAddress(editor, binding);
} else if (type == PhoneNumber.class) {
createPhoneNumber(editor, binding);
} else if (type == Date.class) {
createDate(editor, binding);
} else if (type == IMHandle.class) {
createIMHandle(editor, binding);
} else if (type == GeoPt.class) {
createGeoPt(editor, binding);
} else if (type == User.class) {
createUser(editor, binding);
} else if (type == Blob.class || type == ShortBlob.class) {
createBlob(editor, type, binding, project);
} else if (type == Rating.class) {
createRating(editor, binding);
} else if (type == Key.class) {
OneLineTextElement<String> t = new OneLineTextElement<String>();
t.setBinding(binding);
editor.add(t);
// GAEField ff = f.new GAEField(chId, false);
// createKey(editor, binding, ff);
} else {
if (!binding.allowsMultiValues()) {
OneLineTextElement<String> t = new OneLineTextElement<String>();
t.setBinding(binding);
binding.allowsMultiValues();
binding.setReadOnly(true);
editor.add(t);
} else {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
editor.setData("text", text);
editor.add(text);
}
Container m = new Container();
m.setLayout(new GridLayout(1, false));
m.setCaption(binding.getName());
final ListEnumeratedValueSelector<Object> v = new ListEnumeratedValueSelector<Object>();
binding.addValueListener(new IValueListener<Object>() {
public void valueChanged(Object oldValue,
Object newValue) {
return;