use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class DataGridLoader method addDynamicAttributes.
protected void addDynamicAttributes(DataGrid component, Datasource ds, List<Column> availableColumns) {
if (metadataTools.isPersistent(ds.getMetaClass())) {
Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), context.getFullFrameId(), component.getId());
if (CollectionUtils.isNotEmpty(attributesToShow)) {
ds.setLoadDynamicAttributes(true);
for (CategoryAttribute attribute : attributesToShow) {
final MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(ds.getMetaClass(), attribute);
Object columnWithSameId = IterableUtils.find(availableColumns, column -> {
MetaPropertyPath propertyPath = column.getPropertyPath();
return propertyPath != null && propertyPath.equals(metaPropertyPath);
});
if (columnWithSameId != null) {
continue;
}
final Column column = component.addColumn(metaPropertyPath.getMetaProperty().getName(), metaPropertyPath);
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName()));
}
}
dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class FieldGroupLoader method loadValidators.
protected void loadValidators(FieldGroup resultComponent, FieldGroup.FieldConfig field) {
Element descriptor = field.getXmlDescriptor();
@SuppressWarnings("unchecked") List<Element> validatorElements = (descriptor == null) ? null : descriptor.elements("validator");
if (validatorElements != null) {
if (!validatorElements.isEmpty()) {
for (Element validatorElement : validatorElements) {
Field.Validator validator = loadValidator(validatorElement);
if (validator != null) {
field.addValidator(validator);
}
}
}
} else {
Datasource ds;
if (field.getDatasource() == null) {
ds = resultComponent.getDatasource();
} else {
ds = field.getDatasource();
}
if (ds != null) {
MetaClass metaClass = ds.getMetaClass();
MetaPropertyPath metaPropertyPath = metaClass.getPropertyPath(field.getProperty());
if (metaPropertyPath != null) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
Field.Validator validator = null;
if (descriptor == null) {
validator = getDefaultValidator(metaProperty);
} else if (!"timeField".equals(descriptor.attributeValue("field"))) {
// In this case we no need to use validator
validator = getDefaultValidator(metaProperty);
}
if (validator != null) {
field.addValidator(validator);
}
}
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class FieldGroupLoader method applyPermissions.
protected void applyPermissions(Component fieldComponent) {
if (fieldComponent instanceof DatasourceComponent) {
DatasourceComponent dsComponent = (DatasourceComponent) fieldComponent;
MetaPropertyPath propertyPath = dsComponent.getMetaPropertyPath();
Datasource datasource = dsComponent.getDatasource();
if (datasource != null && propertyPath != null) {
MetaClass metaClass = datasource.getMetaClass();
if (!security.isEntityAttrUpdatePermitted(metaClass, propertyPath.toString())) {
dsComponent.setEditable(false);
}
if (!security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
dsComponent.setVisible(false);
}
}
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebAbstractTable method getInitialVisibleColumns.
protected List<Object> getInitialVisibleColumns() {
List<Object> result = new ArrayList<>();
MetaClass metaClass = datasource.getMetaClass();
for (Column column : columnsOrder) {
if (column.getId() instanceof MetaPropertyPath) {
MetaPropertyPath propertyPath = (MetaPropertyPath) column.getId();
if (security.isEntityAttrReadPermitted(metaClass, propertyPath.toString())) {
result.add(column.getId());
}
} else {
result.add(column.getId());
}
}
return result;
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebAbstractTable method getColumnCaption.
protected String getColumnCaption(Object columnId, Column column) {
String caption = column.getCaption();
if (caption != null) {
return caption;
}
if (!(columnId instanceof MetaPropertyPath)) {
return StringUtils.capitalize(getColumnCaption(columnId));
}
MetaPropertyPath mpp = (MetaPropertyPath) columnId;
MetaProperty metaProperty = mpp.getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) {
return categoryAttribute.getLocaleName();
}
caption = StringUtils.capitalize(categoryAttribute.getName());
} else {
caption = StringUtils.capitalize(getColumnCaption(columnId));
}
return caption;
}
Aggregations