final CompositeEditor ed = new CompositeEditor();
ed.setLayout(new GridLayout());
ed.setLayoutManager(new HorizontalLayouter());
if (fm.multiplicity) {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
ed.setData("text", text);
ed.add(text);
}
IBinding bb = createSpecialMultiEdit(e, bnd, facade, text, f, fm,
needIndexable);
// addButtonSelector(bb, ed,null);
ed.setId(bnd.getId());
editor.add(ed);
return text;
}
if (f.isKey()) {
return text;
} else {
final Class<?> type = f.getType();
if (type != null) {
final Binding binding = bnd.getBinding(f.name);
binding.setValue(e.getProperty(f.name), null);
Object adapter = new ClassAdapterFactory().getAdapter(type,
IValidator.class);
if (adapter != null) {
binding.setAdapter(IValidator.class, (IValidator) adapter);
}
adapter = new ClassAdapterFactory().getAdapter(type,
ILabelLookup.class);
if (adapter != null) {
binding.setAdapter(ILabelLookup.class,
(ILabelLookup) adapter);
}
adapter = new ClassAdapterFactory().getAdapter(type,
IRealmProvider.class);
if (adapter != null) {
binding.setAdapter(IRealmProvider.class,
(IRealmProvider) adapter);
} else {
IRealm<?> c = facade.getRealm(f);
if (c != null) {
binding.setRealm(c);
}
}
binding.setReadOnly(false);
binding.setName(f.getTitle());
if (type == String.class) {
OneLineTextElement<String> t = new OneLineTextElement<String>();
t.setBinding(binding);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (Number.class.isAssignableFrom(type)
|| type.isPrimitive()) {
binding.setSubjectClass(type);
OneLineTextElement<Number> t = new OneLineTextElement<Number>();
binding.addValidator(new ValidatorAdapter() {
public CodeAndMessage isValid(IBinding context,
Object object) {
if (object == null) {
return CodeAndMessage.OK_MESSAGE;
}
try {
if (object instanceof String) {
if (type == Double.class) {
Double.parseDouble((String) object);
} else if (type == Long.class) {
Long.parseLong((String) object);
} else if (type == Float.class) {
Float.parseFloat((String) object);
} else if (type == 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);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Boolean.class) {
binding.setSubjectClass(type);
ComboEnumeratedValueSelector<Boolean> t = new ComboEnumeratedValueSelector<Boolean>();
t.setBinding(binding);
ed.add(t);
addIsNullButtonSelector(binding, ed, null);
if (needIndexable) {
addNotIndexableButton(binding, ed, f);
}
} else if (type == Text.class) {
if (text == null) {
text = new CTabFolderElement();
text.setBordered(true);
ed.setData("text", text);
ed.add(text);
}
createText(ed, text, binding, true);