use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class AbstractTableLoader method loadColumn.
protected Table.Column loadColumn(Element element, Datasource ds) {
String id = element.attributeValue("id");
MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(ds.getMetaClass(), id);
Table.Column column = new Table.Column(metaPropertyPath != null ? metaPropertyPath : id);
String editable = element.attributeValue("editable");
if (StringUtils.isNotEmpty(editable)) {
column.setEditable(Boolean.parseBoolean(editable));
}
String collapsed = element.attributeValue("collapsed");
if (StringUtils.isNotEmpty(collapsed)) {
column.setCollapsed(Boolean.parseBoolean(collapsed));
}
String groupAllowed = element.attributeValue("groupAllowed");
if (StringUtils.isNotEmpty(groupAllowed)) {
column.setGroupAllowed(Boolean.parseBoolean(groupAllowed));
}
String sortable = element.attributeValue("sortable");
if (StringUtils.isNotEmpty(sortable)) {
column.setSortable(Boolean.parseBoolean(sortable));
}
loadCaption(column, element);
loadDescription(column, element);
if (column.getCaption() == null) {
String columnCaption;
if (column.getId() instanceof MetaPropertyPath) {
MetaPropertyPath mpp = (MetaPropertyPath) column.getId();
MetaProperty metaProperty = mpp.getMetaProperty();
String propertyName = metaProperty.getName();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
} else {
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);
columnCaption = messageTools.getPropertyCaption(propertyMetaClass, propertyName);
}
} else {
Class<?> declaringClass = ds.getMetaClass().getJavaClass();
String className = declaringClass.getName();
int i = className.lastIndexOf('.');
if (i > -1)
className = className.substring(i + 1);
columnCaption = messages.getMessage(declaringClass, className + "." + id);
}
column.setCaption(columnCaption);
}
column.setXmlDescriptor(element);
if (metaPropertyPath != null)
column.setType(metaPropertyPath.getRangeJavaClass());
String width = loadThemeString(element.attributeValue("width"));
if (!StringUtils.isBlank(width)) {
if (StringUtils.endsWith(width, "px")) {
width = StringUtils.substring(width, 0, width.length() - 2);
}
try {
column.setWidth(Integer.parseInt(width));
} catch (NumberFormatException e) {
throw new GuiDevelopmentException("Property 'width' must contain only numeric value", context.getCurrentFrameId(), "width", element.attributeValue("width"));
}
}
String align = element.attributeValue("align");
if (StringUtils.isNotBlank(align)) {
column.setAlignment(Table.ColumnAlignment.valueOf(align));
}
column.setFormatter(loadFormatter(element));
loadAggregation(column, element);
loadCalculatable(column, element);
loadMaxTextLength(column, element);
return column;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebGroupTable method applyColumnSettings.
@Override
public void applyColumnSettings(Element element) {
super.applyColumnSettings(element);
final Element groupPropertiesElement = element.element("groupProperties");
if (groupPropertiesElement != null) {
final List elements = groupPropertiesElement.elements("property");
final List<MetaPropertyPath> properties = new ArrayList<>(elements.size());
for (final Object o : elements) {
final MetaPropertyPath property = datasource.getMetaClass().getPropertyPath(((Element) o).attributeValue("id"));
properties.add(property);
}
groupBy(properties.toArray());
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebLabel method resolveMetaPropertyPath.
protected MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String property) {
MetaPropertyPath metaPropertyPath = AppBeans.get(MetadataTools.NAME, MetadataTools.class).resolveMetaPropertyPath(metaClass, property);
Preconditions.checkNotNullArgument(metaPropertyPath, "Could not resolve property path '%s' in '%s'", property, metaClass);
return metaPropertyPath;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebLookupField method tryToAssignCaptionProperty.
protected void tryToAssignCaptionProperty() {
if (optionsDatasource != null && captionProperty != null && getCaptionMode() == CaptionMode.PROPERTY) {
MetaPropertyPath propertyPath = optionsDatasource.getMetaClass().getPropertyPath(captionProperty);
if (propertyPath != null && component.getContainerDataSource() != null) {
((LookupOptionsDsWrapper) component.getContainerDataSource()).addProperty(propertyPath);
component.setItemCaptionPropertyId(propertyPath);
} else {
throw new IllegalArgumentException(String.format("Can't find property for given caption property: %s", captionProperty));
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebPickerField method checkDatasourceProperty.
public void checkDatasourceProperty(Datasource datasource, String property) {
Preconditions.checkNotNullArgument(datasource);
Preconditions.checkNotNullArgument(property);
MetaPropertyPath metaPropertyPath = getResolvedMetaPropertyPath(datasource.getMetaClass(), property);
if (!metaPropertyPath.getRange().isClass()) {
throw new DevelopmentException(String.format("property '%s.%s' should have Entity type", datasource.getMetaClass().getName(), property));
}
}
Aggregations