* @param info The actual attribute info to create a form item for.
* @param attributeProvider The attribute value provider for association attributes
* @return The new form item instance associated with the type of attribute.
*/
public static FormItem createFormItem(AttributeInfo info, AttributeProvider attributeProvider) {
FormItem formItem = null;
if (info.getFormInputType() != null) {
formItem = FORMITEMS.get(info.getFormInputType()).create();
}
if (formItem == null) {
if (info instanceof PrimitiveAttributeInfo) {
String name = ((PrimitiveAttributeInfo) info).getType().name();
formItem = FORMITEMS.get(name).create();
} else if (info instanceof AssociationAttributeInfo) {
String name = ((AssociationAttributeInfo) info).getType().name();
formItem = FORMITEMS.get(name).create();
}
}
if (formItem != null) {
formItem.setName(info.getName());
formItem.setTitle(info.getLabel());
formItem.setValidateOnChange(true);
formItem.setWidth("*");
// Special treatment for associations
if (info instanceof AssociationAttributeInfo) {
AssociationAttributeInfo associationInfo = (AssociationAttributeInfo) info;
String displayName = associationInfo.getFeature().getDisplayAttributeName();
if (displayName == null) {
displayName = associationInfo.getFeature().getAttributes().get(0).getName();
}
formItem.setDisplayField(displayName);
Object o = formItem.getAttributeAsObject(AssociationItem.ASSOCIATION_ITEM_ATTRIBUTE_KEY);
if (o instanceof OneToManyItem<?>) {
OneToManyItem<?> item = (OneToManyItem<?>) o;
item.init(associationInfo, attributeProvider);
} else if (o instanceof ManyToOneItem<?>) {
ManyToOneItem<?> item = (ManyToOneItem<?>) o;