use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class EntityLogBrowser method fillAttributes.
protected void fillAttributes(String metaClassName, LoggedEntity item, boolean editable) {
clearAttributes();
setSelectAllCheckBox(false);
if (metaClassName != null) {
MetaClass metaClass = metadata.getExtendedEntities().getEffectiveMetaClass(metadata.getClassNN(metaClassName));
List<MetaProperty> metaProperties = new ArrayList<>(metaClass.getProperties());
selectAllCheckBox.setEditable(editable);
Set<LoggedAttribute> enabledAttr = null;
if (item != null)
enabledAttr = item.getAttributes();
for (MetaProperty property : metaProperties) {
if (allowLogProperty(property, null)) {
if (metadata.getTools().isEmbedded(property)) {
MetaClass embeddedMetaClass = property.getRange().asClass();
for (MetaProperty embeddedProperty : embeddedMetaClass.getProperties()) {
if (allowLogProperty(embeddedProperty, null)) {
addAttribute(enabledAttr, String.format("%s.%s", property.getName(), embeddedProperty.getName()), editable);
}
}
} else {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
Collection<CategoryAttribute> attributes = dynamicAttributes.getAttributesForMetaClass(metaClass);
if (attributes != null) {
for (CategoryAttribute categoryAttribute : attributes) {
MetaPropertyPath propertyPath = DynamicAttributesUtils.getMetaPropertyPath(metaClass, categoryAttribute);
MetaProperty property = propertyPath.getMetaProperty();
if (allowLogProperty(property, categoryAttribute)) {
addAttribute(enabledAttr, property.getName(), editable);
}
}
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopAbstractTable method addColumn.
@Override
public void addColumn(Column column) {
checkNotNullArgument(column, "Column must be non null");
Object columnId = column.getId();
columns.put(columnId, column);
columnsOrder.add(column);
if (tableModel != null) {
tableModel.addColumn(column);
}
if (datasource != null && column.isEditable() && columnId instanceof MetaPropertyPath) {
if (!editableColumns.contains(columnId)) {
editableColumns.add((MetaPropertyPath) columnId);
}
}
setColumnIdentifiers();
refresh();
column.setOwner(this);
if (column.getFormatter() == null && columnId instanceof MetaPropertyPath) {
MetaProperty metaProperty = ((MetaPropertyPath) columnId).getMetaProperty();
if (Collection.class.isAssignableFrom(metaProperty.getJavaType())) {
final Formatter collectionFormatter = new CollectionFormatter();
column.setFormatter(collectionFormatter);
}
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class DesktopCurrencyField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
super.setDatasource(datasource, property);
if (datasource != null && !DynamicAttributesUtils.isDynamicAttribute(property)) {
MetaProperty metaProperty = datasource.getMetaClass().getPropertyNN(property);
Object annotation = metaProperty.getAnnotations().get(CurrencyValue.class.getName());
if (annotation == null)
return;
// noinspection unchecked
currency = (String) ((Map<String, Object>) annotation).get("currency");
}
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class AttributeAccessSupport method calculateComponentState.
protected ComponentState calculateComponentState(Entity entity, MetaPropertyPath propertyPath) {
MetaProperty[] metaProperties = propertyPath.getMetaProperties();
ComponentState componentState = new ComponentState();
for (int i = 0; i < metaProperties.length; i++) {
MetaProperty metaProperty = metaProperties[i];
String name = metaProperty.getName();
SecurityState securityState = getSecurityState(entity);
if (securityState != null) {
componentState.hidden = test(componentState.hidden, securityState.getHiddenAttributes(), name);
componentState.readOnly = test(componentState.readOnly, securityState.getReadonlyAttributes(), name);
if (i == metaProperties.length - 1) {
componentState.required = test(componentState.required, securityState.getRequiredAttributes(), name);
}
}
if (i != metaProperties.length - 1) {
entity = entity.getValue(name);
if (entity == null) {
break;
}
}
}
return componentState;
}
use of com.haulmont.chile.core.model.MetaProperty in project cuba by cuba-platform.
the class ComponentsHelper method handleFilteredAttributes.
/**
* Set field's "required" flag to false if the value has been filtered by Row Level Security
* This is necessary to allow user to submit form with filtered attribute even if attribute is required
*/
public static void handleFilteredAttributes(Field component, Datasource datasource, MetaPropertyPath mpp) {
if (component.isRequired() && datasource.getState() == Datasource.State.VALID && datasource.getItem() != null && mpp.getMetaProperty().getRange().isClass()) {
Entity targetItem = datasource.getItem();
MetaProperty[] propertiesChain = mpp.getMetaProperties();
if (propertiesChain.length > 1) {
String basePropertyItem = Arrays.stream(propertiesChain).limit(propertiesChain.length - 1).map(MetadataObject::getName).collect(Collectors.joining("."));
targetItem = datasource.getItem().getValueEx(basePropertyItem);
}
if (targetItem instanceof BaseGenericIdEntity) {
String metaPropertyName = mpp.getMetaProperty().getName();
Object value = targetItem.getValue(metaPropertyName);
BaseGenericIdEntity baseGenericIdEntity = (BaseGenericIdEntity) targetItem;
String[] filteredAttributes = getFilteredAttributes(baseGenericIdEntity);
if (value == null && filteredAttributes != null && ArrayUtils.contains(filteredAttributes, metaPropertyName)) {
component.setRequired(false);
}
}
}
}
Aggregations