use of com.haulmont.cuba.core.entity.CategoryAttribute 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.cuba.core.entity.CategoryAttribute 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.cuba.core.entity.CategoryAttribute in project cuba by cuba-platform.
the class WebAbstractOptionsField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
if ((datasource == null && property != null) || (datasource != null && property == null))
throw new IllegalArgumentException("Datasource and property should be either null or not null at the same time");
if (datasource == this.datasource && ((metaPropertyPath != null && metaPropertyPath.toString().equals(property)) || (metaPropertyPath == null && property == null)))
return;
if (this.datasource != null) {
metaProperty = null;
metaPropertyPath = null;
component.setPropertyDataSource(null);
// noinspection unchecked
this.datasource.removeItemChangeListener(securityWeakItemChangeListener);
securityWeakItemChangeListener = null;
this.datasource = null;
if (itemWrapper != null) {
itemWrapper.unsubscribe();
}
disableBeanValidator();
}
if (datasource != null) {
// noinspection unchecked
this.datasource = datasource;
MetaClass metaClass = datasource.getMetaClass();
resolveMetaPropertyPath(metaClass, property);
if (metaProperty.getRange().getCardinality() != null) {
setMultiSelect(metaProperty.getRange().getCardinality().isMany());
}
itemWrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath));
Property itemProperty = itemWrapper.getItemProperty(metaPropertyPath);
initRequired(metaPropertyPath);
if (metaProperty.getRange().isEnum()) {
Enumeration enumeration = metaProperty.getRange().asEnumeration();
List options = Arrays.asList(enumeration.getJavaClass().getEnumConstants());
setComponentContainerDs(createEnumContainer(options));
setCaptionMode(CaptionMode.ITEM);
}
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
setOptionsMap(categoryAttribute.getLocalizedEnumerationMap());
}
}
component.setPropertyDataSource(itemProperty);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityWeakItemChangeListener = new WeakItemChangeListener(datasource, securityItemChangeListener);
// noinspection unchecked
this.datasource.addItemChangeListener(securityWeakItemChangeListener);
initBeanValidator();
}
}
use of com.haulmont.cuba.core.entity.CategoryAttribute 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