use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.
the class TextAreaLoader method loadComponent.
@Override
public void loadComponent() {
super.loadComponent();
loadMaxLength(resultComponent, element);
loadTrimming(resultComponent, element);
loadInputPrompt(resultComponent, element);
loadCaseConversion(resultComponent, element);
loadTextChangeEventProperties(resultComponent, element);
String cols = element.attributeValue("cols");
if (StringUtils.isNotEmpty(cols)) {
resultComponent.setColumns(Integer.parseInt(cols));
}
String rows = element.attributeValue("rows");
if (StringUtils.isNotEmpty(rows)) {
resultComponent.setRows(Integer.parseInt(rows));
}
String wordwrap = element.attributeValue("wordwrap");
if (StringUtils.isNotEmpty(wordwrap)) {
resultComponent.setWordwrap(Boolean.parseBoolean(wordwrap));
}
String datatypeAttribute = element.attributeValue("datatype");
if (StringUtils.isNotEmpty(datatypeAttribute)) {
Datatype datatype = Datatypes.get(datatypeAttribute);
resultComponent.setDatatype(datatype);
}
}
use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.
the class TextFieldLoader method loadComponent.
@Override
public void loadComponent() {
super.loadComponent();
loadMaxLength(resultComponent, element);
loadTrimming(resultComponent, element);
String datatypeAttribute = element.attributeValue("datatype");
if (StringUtils.isNotEmpty(datatypeAttribute)) {
Datatype datatype = Datatypes.get(datatypeAttribute);
resultComponent.setDatatype(datatype);
}
resultComponent.setFormatter(loadFormatter(element));
loadInputPrompt(resultComponent, element);
loadCaseConversion(resultComponent, element);
loadTextChangeEventProperties(resultComponent, element);
}
use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.
the class LinkColumnHelper method initColumn.
public static void initColumn(Table table, final String propertyName, final Handler handler) {
final ComponentsFactory componentsFactory = AppBeans.get(ComponentsFactory.NAME);
table.addGeneratedColumn(propertyName, new Table.ColumnGenerator() {
@Override
public Component generateCell(final Entity entity) {
// //process properties like building.house.room
String[] props = propertyName.split("\\.");
Instance nestedEntity = entity;
for (int i = 0; i < props.length - 1; i++) {
nestedEntity = nestedEntity.getValue(props[i]);
if (nestedEntity == null) {
break;
}
}
final Object value = (nestedEntity == null) ? null : nestedEntity.getValue(props[props.length - 1]);
if (value != null) {
Button button = componentsFactory.createComponent(Button.class);
button.setStyleName("link");
button.setAction(new AbstractAction("open") {
@Override
public void actionPerform(Component component) {
handler.onClick(entity);
}
@Override
public String getCaption() {
String str;
Datatype datatype = Datatypes.get(value.getClass());
if (datatype != null) {
UserSessionSource sessionSource = AppBeans.get(UserSessionSource.NAME);
str = datatype.format(value, sessionSource.getLocale());
} else {
str = value.toString();
}
return str;
}
});
button.setStyleName("link");
return button;
}
return null;
}
});
}
use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.
the class MetaModelLoader method loadProperty.
protected MetadataObjectInfo<MetaProperty> loadProperty(MetaClassImpl metaClass, Field field) {
Collection<RangeInitTask> tasks = new ArrayList<>();
MetaPropertyImpl property = new MetaPropertyImpl(metaClass, field.getName());
Range.Cardinality cardinality = getCardinality(field);
Map<String, Object> map = new HashMap<>();
map.put("cardinality", cardinality);
boolean mandatory = isMandatory(field);
map.put("mandatory", mandatory);
Datatype datatype = getAdaptiveDatatype(field);
map.put("datatype", datatype);
String inverseField = getInverseField(field);
if (inverseField != null)
map.put("inverseField", inverseField);
Class<?> type;
Class typeOverride = getTypeOverride(field);
if (typeOverride != null)
type = typeOverride;
else
type = field.getType();
property.setMandatory(mandatory);
property.setReadOnly(!setterExists(field));
property.setAnnotatedElement(field);
property.setDeclaringClass(field.getDeclaringClass());
MetadataObjectInfo<Range> info = loadRange(property, type, map);
Range range = info.getObject();
if (range != null) {
((AbstractRange) range).setCardinality(cardinality);
property.setRange(range);
assignPropertyType(field, property, range);
assignInverse(property, range, inverseField);
}
if (info.getObject() != null && info.getObject().isEnum()) {
property.setJavaType(info.getObject().asEnumeration().getJavaClass());
} else {
property.setJavaType(field.getType());
}
tasks.addAll(info.getTasks());
return new MetadataObjectInfo<>(property, tasks);
}
use of com.haulmont.chile.core.datatypes.Datatype in project cuba by cuba-platform.
the class MetaModelLoader method loadRange.
protected MetadataObjectInfo<Range> loadRange(MetaProperty metaProperty, Class<?> type, Map<String, Object> map) {
Datatype datatype = (Datatype) map.get("datatype");
if (datatype != null) {
// A datatype is assigned explicitly
return new MetadataObjectInfo<>(new DatatypeRange(datatype));
}
datatype = getAdaptiveDatatype(metaProperty, type);
if (datatype == null) {
datatype = datatypes.get(type);
}
if (datatype != null) {
MetaClass metaClass = metaProperty.getDomain();
Class javaClass = metaClass.getJavaClass();
try {
String name = "get" + StringUtils.capitalize(metaProperty.getName());
Method method = javaClass.getMethod(name);
Class<Enum> returnType = (Class<Enum>) method.getReturnType();
if (returnType.isEnum()) {
return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl<>(returnType)));
}
} catch (NoSuchMethodException e) {
// ignore
}
return new MetadataObjectInfo<>(new DatatypeRange(datatype));
} else if (type.isEnum()) {
return new MetadataObjectInfo<>(new EnumerationRange(new EnumerationImpl(type)));
} else {
return new MetadataObjectInfo<>(null, Collections.singletonList(new RangeInitTask(metaProperty, type, map)));
}
}
Aggregations