PL-5497 Re-write CategoryAttribute editor, Runtime properties frame and all linked. Get rid of SetValueEntity.

SetValue entity removed, runtimePropertiesFrame refactored
#PL-5497
This commit is contained in:
Eugeny Degtyarjov 2015-06-30 11:32:12 +00:00
parent 890381fcad
commit 91ee1a391f
18 changed files with 324 additions and 402 deletions

View File

@ -11,7 +11,6 @@ import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.chile.core.model.utils.InstanceUtils;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
@ -175,9 +174,8 @@ public abstract class DesktopAbstractOptionsField<C extends JComponent>
setCaptionMode(CaptionMode.ITEM);
}
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
if (metaProperty.getRange().isClass() && DynamicAttributesUtils.isDynamicAttribute(property)) {
CategoryAttribute categoryAttribute = dynamicAttributes.getAttributeForMetaClass(metaClass, property);
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
setOptionsList(categoryAttribute.getEnumerationOptions());
}

View File

@ -7,7 +7,6 @@ package com.haulmont.cuba.core.app.dynamicattributes;
import com.haulmont.chile.core.datatypes.Datatypes;
import com.haulmont.chile.core.model.*;
import com.haulmont.chile.core.model.impl.AbstractRange;
import com.haulmont.chile.core.model.impl.ClassRange;
import com.haulmont.chile.core.model.impl.DatatypeRange;
import com.haulmont.chile.core.model.impl.MetadataObjectImpl;
@ -15,7 +14,6 @@ import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.core.sys.SetValueEntity;
import java.io.Serializable;
import java.lang.annotation.Annotation;
@ -28,24 +26,23 @@ import java.lang.reflect.AnnotatedElement;
* @version $Id$
*/
public class DynamicAttributesMetaProperty extends MetadataObjectImpl implements MetaProperty {
private MetaClass metaClass;
private transient Range range;
private Class javaClass;
private Boolean mandatory;
private AnnotatedElement annotatedElement = new FakeAnnotatedElement();
protected final MetaClass metaClass;
protected final transient Range range;
protected final Class javaClass;
protected final Boolean mandatory;
protected final AnnotatedElement annotatedElement = new FakeAnnotatedElement();
protected final CategoryAttribute attribute;
public DynamicAttributesMetaProperty(MetaClass metaClass, CategoryAttribute attribute) {
this.attribute = attribute;
this.javaClass = DynamicAttributesUtils.getAttributeClass(attribute);
this.metaClass = metaClass;
this.name = DynamicAttributesUtils.encodeAttributeCode(attribute.getCode());
this.mandatory = attribute.getRequired();
Metadata metadata = AppBeans.get(Metadata.NAME);
Session metadataSession = metadata.getSession();
if (SetValueEntity.class.isAssignableFrom(javaClass)) {
range = new ClassRange(metadataSession.getClass(SetValueEntity.class));
((AbstractRange) range).setCardinality(Range.Cardinality.ONE_TO_ONE);
} else if (Entity.class.isAssignableFrom(javaClass)) {
if (Entity.class.isAssignableFrom(javaClass)) {
range = new ClassRange(metadataSession.getClass(javaClass));
} else {
this.range = new DatatypeRange(Datatypes.getNN(javaClass));
@ -140,4 +137,8 @@ public class DynamicAttributesMetaProperty extends MetadataObjectImpl implements
public int hashCode() {
return 31 * metaClass.hashCode() + name.hashCode();
}
public CategoryAttribute getAttribute() {
return attribute;
}
}

View File

@ -11,11 +11,12 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.sys.SetValueEntity;
import org.apache.commons.lang.BooleanUtils;
import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Date;
import java.util.UUID;
/**
* @author degtyarjov
@ -49,6 +50,28 @@ public final class DynamicAttributesUtils {
}
}
/**
* Get special meta property path object for dynamic attribute id
*/
@Nullable
public static MetaPropertyPath getMetaPropertyPath(MetaClass metaClass, UUID attributeId) {
Collection<CategoryAttribute> attributes = AppBeans.get(DynamicAttributes.NAME, DynamicAttributes.class)
.getAttributesForMetaClass(metaClass);
CategoryAttribute attribute = null;
for (CategoryAttribute theAttribute : attributes) {
if (theAttribute.getId().equals(attributeId)) {
attribute = theAttribute;
break;
}
}
if (attribute != null) {
return getMetaPropertyPath(metaClass, attribute);
} else {
return null;
}
}
/**
* Remove dynamic attribute marker (+) from attribute code (if exists)
*/
@ -70,6 +93,17 @@ public final class DynamicAttributesUtils {
return name.startsWith("+");
}
/**
* Check if the meta property is dynamic attribute property
*/
public static boolean isDynamicAttribute(MetaProperty metaProperty) {
return metaProperty instanceof DynamicAttributesMetaProperty;
}
public static CategoryAttribute getCategoryAttribute(MetaProperty metaProperty) {
return ((DynamicAttributesMetaProperty) metaProperty).getAttribute();
}
/**
* Resolve attribute value's Java class
*/
@ -91,7 +125,7 @@ public final class DynamicAttributesUtils {
case DATE:
return Date.class;
case ENUMERATION:
return SetValueEntity.class;
return String.class;
}
}
return String.class;

View File

@ -10,7 +10,6 @@ import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.annotation.Listeners;
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.sys.SetValueEntity;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.persistence.Persistent;
@ -270,15 +269,10 @@ public class CategoryAttribute extends StandardEntity {
return PropertyType.valueOf(dataType);
}
public List<SetValueEntity> getEnumerationOptions() {
public List<String> getEnumerationOptions() {
Preconditions.checkState(getDataTypeAsPropertyType() == PropertyType.ENUMERATION, "Only enumeration attributes have options");
String enumeration = getEnumeration();
String[] values = StringUtils.split(enumeration, ',');
List<SetValueEntity> options = new LinkedList<>();
for (String value : values) {
String trimmedValue = StringUtils.trimToNull(value);
options.add(new SetValueEntity(trimmedValue));
}
return options;
return Arrays.asList(values);
}
}

View File

@ -7,12 +7,10 @@ package com.haulmont.cuba.core.entity;
import com.google.common.base.Preconditions;
import com.haulmont.bali.util.ReflectionHelper;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.DataManager;
import com.haulmont.cuba.core.global.LoadContext;
import com.haulmont.cuba.core.sys.SetValueEntity;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.persistence.Persistent;
@ -155,8 +153,6 @@ public class CategoryAttributeValue extends StandardEntity {
setBooleanValue((Boolean) value);
} else if (value instanceof UUID) {
setEntityValue((UUID) value);
} else if (value instanceof SetValueEntity) {
setStringValue(((SetValueEntity) value).getValue());
} else if (value instanceof Entity) {
setEntityValue(((Entity) value).getUuid());
} else if (value instanceof String) {
@ -168,9 +164,6 @@ public class CategoryAttributeValue extends StandardEntity {
public Object getValue() {
if (stringValue != null) {
if (categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
return new SetValueEntity(stringValue);
}
return stringValue;
} else if (intValue != null) {
return intValue;

View File

@ -1,60 +0,0 @@
/*
* Copyright (c) 2008-2013 Haulmont. All rights reserved.
* Use is subject to license terms, see http://www.cuba-platform.com/license for details.
*/
package com.haulmont.cuba.core.sys;
import com.haulmont.chile.core.annotations.MetaClass;
import com.haulmont.chile.core.annotations.MetaProperty;
import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.cuba.core.entity.AbstractNotPersistentEntity;
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
/**
* <p>$Id$</p>
*
* @author devyatkin
*/
@NamePattern("%s|value")
@MetaClass(name = "sys$SetValue")
@SystemLevel
public class SetValueEntity extends AbstractNotPersistentEntity {
private static final long serialVersionUID = -1652898874022057451L;
public SetValueEntity(String value) {
this.value = value;
}
private String value;
@MetaProperty
public String getValue() {
return value;
}
@MetaProperty
public void setValue(String value) {
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (super.equals(o)) return true;
SetValueEntity that = (SetValueEntity) o;
if (value != null ? !value.equals(that.value) : that.value != null) return false;
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (value != null ? value.hashCode() : 0);
return result;
}
}

View File

@ -14,7 +14,6 @@
<class>com.haulmont.cuba.core.entity.diff.EntityDiff</class>
<class>com.haulmont.cuba.core.entity.diff.EntityPropertyDiff</class>
<class>com.haulmont.cuba.core.global.LockInfo</class>
<class>com.haulmont.cuba.core.sys.SetValueEntity</class>
<class>com.haulmont.cuba.security.entity.EntityLogAttr</class>
<class>com.haulmont.cuba.security.entity.UserSessionEntity</class>
</metadata-model>

View File

@ -11,7 +11,6 @@ import com.haulmont.chile.core.datatypes.impl.*;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
@ -54,6 +53,14 @@ public abstract class AbstractFieldFactory implements FieldFactory {
Datatype datatype = mpp.getRange().asDatatype();
String typeName = datatype.getName();
MetaProperty metaProperty = mpp.getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
return createEnumField(datasource, property);
}
}
if (xmlDescriptor != null
&& "true".equalsIgnoreCase(xmlDescriptor.attributeValue("link"))) {
return createDatatypeLinkField(datasource, property, xmlDescriptor);
@ -76,14 +83,6 @@ public abstract class AbstractFieldFactory implements FieldFactory {
return createNumberField(datasource, property);
}
} else if (mpp.getRange().isClass()) {
if (DynamicAttributesUtils.isDynamicAttribute(property)) {
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
CategoryAttribute categoryAttribute = dynamicAttributes.getAttributeForMetaClass(metaClass, property);
if (categoryAttribute != null && categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
return createEnumField(datasource, property);
}
}
return createEntityField(datasource, property, xmlDescriptor);
} else if (mpp.getRange().isEnum()) {
return createEnumField(datasource, property);

View File

@ -12,12 +12,13 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.chile.core.model.Range;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.CategoryAttributeValue;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.DevelopmentException;
import com.haulmont.cuba.core.global.View;
import com.haulmont.cuba.core.sys.SetValueEntity;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.WindowParam;
import com.haulmont.cuba.gui.components.validators.DateValidator;
@ -52,6 +53,7 @@ public class RuntimePropertiesFrame extends AbstractWindow {
private final DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
protected RuntimePropsDatasource rds;
protected CollectionDatasource categoriesDs;
protected boolean requiredControlEnabled = true;
@ -110,6 +112,7 @@ public class RuntimePropertiesFrame extends AbstractWindow {
categoryField.setOptionsDatasource(categoriesDs);
}
@SuppressWarnings("unchecked")
protected void loadComponent(Datasource ds) {
ds.addListener(new DsListenerAdapter() {
@Override
@ -117,140 +120,48 @@ public class RuntimePropertiesFrame extends AbstractWindow {
if (!Datasource.State.VALID.equals(state)) {
return;
}
Component runtime = getComponent("runtime");
if (runtime != null) {
remove(runtime);
}
final FieldGroup newRuntime = componentsFactory.createComponent(FieldGroup.NAME);
newRuntime.setBorderVisible(Boolean.TRUE.equals(borderVisible));
newRuntime.setWidth("100%");
newRuntime.setId("runtime");
newRuntime.setFrame(getFrame());
add(newRuntime);
final List<FieldGroup.FieldConfig> fields = newRuntime.getFields();
for (FieldGroup.FieldConfig field : fields) {
newRuntime.removeField(field);
}
int rowsPerColumn;
int propertiesCount = rds.getPropertiesFilteredByCategory().size();
if (StringUtils.isNotBlank(cols)) {
int propertiesSize = propertiesCount;
if (propertiesSize % Integer.valueOf(cols) == 0)
rowsPerColumn = propertiesSize / Integer.parseInt(cols);
else
rowsPerColumn = propertiesSize / Integer.parseInt(cols) + 1;
} else if (StringUtils.isNotBlank(rows)) {
rowsPerColumn = Integer.parseInt(rows);
} else {
rowsPerColumn = propertiesCount;
}
int columnNo = 0;
int fieldsCount = 0;
final java.util.List<FieldGroup.FieldConfig> rootFields = loadFields();
for (final FieldGroup.FieldConfig field : rootFields) {
fieldsCount++;
newRuntime.addField(field, columnNo);
if (fieldsCount % rowsPerColumn == 0) {
columnNo++;
newRuntime.setColumns(columnNo + 1);
}
}
if (!rootFields.isEmpty()) {
newRuntime.setDatasource(ds);
}
addCustomFields(newRuntime, rootFields, ds);
for (FieldGroup.FieldConfig fieldConfig : newRuntime.getFields()) {
loadValidators(newRuntime, fieldConfig);
loadRequired(newRuntime, fieldConfig);
}
createRuntimeFieldGroup(ds);
}
});
}
protected void addCustomFields(FieldGroup component, java.util.List<FieldGroup.FieldConfig> fields, final Datasource ds) {
Collection<MetaProperty> metaProperties = rds.getPropertiesFilteredByCategory();
for (final MetaProperty property : metaProperties) {
Range range = property.getRange();
if (!range.isDatatype()) {
if (range.asClass().getJavaClass().equals(SetValueEntity.class)) {
for (FieldGroup.FieldConfig field : fields) {
if (field.getId().equals(property.getName())) {
field.setCustom(true);
component.addCustomField(property.getName(), new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
LookupField field = componentsFactory.createComponent(LookupField.NAME);
field.setFrame(RuntimePropertiesFrame.this);
CategoryAttribute categoryAttribute =
dynamicAttributes.getAttributeForMetaClass(rds.getMainDs().getMetaClass(), propertyId);
if (categoryAttribute != null) {
field.setOptionsList(categoryAttribute.getEnumerationOptions());
}
field.setDatasource(rds, propertyId);
field.setWidth(fieldWidth);
return field;
}
});
}
}
} else {
component.addCustomField(property.getName(), new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
final PickerField pickerField;
Boolean lookup = ((DynamicAttributesEntity) datasource.getItem()).getCategoryValue(property.getName()).getCategoryAttribute().getLookup();
if (lookup != null && lookup) {
pickerField = AppConfig.getFactory().createComponent(LookupPickerField.NAME);
CollectionDatasource optionsDs = new DsBuilder(datasource.getDsContext())
.setMetaClass(property.getRange().asClass())
.setViewName(View.MINIMAL)
.buildCollectionDatasource();
optionsDs.refresh();
Action action = pickerField.getAction(LookupAction.NAME);
if (action != null)
pickerField.removeAction(action);
((LookupPickerField) pickerField).setOptionsDatasource(optionsDs);
} else {
pickerField = componentsFactory.createComponent(PickerField.NAME);
pickerField.addLookupAction();
}
pickerField.setMetaClass(ds.getMetaClass());
pickerField.setFrame(RuntimePropertiesFrame.this);
pickerField.setDatasource(ds, propertyId);
LookupAction lookupAction = (LookupAction) pickerField.getAction(LookupAction.NAME);
if (lookupAction != null) {
DynamicAttributesEntity dynamicAttributesEntity = (DynamicAttributesEntity) ds.getItem();
CategoryAttributeValue categoryAttributeValue = dynamicAttributesEntity.getCategoryValue(property.getName());
if (categoryAttributeValue != null) {
String screen = categoryAttributeValue.getCategoryAttribute().getScreen();
if (StringUtils.isBlank(screen)) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
screen = windowConfig.getBrowseScreenId(pickerField.getMetaClass());
}
lookupAction.setLookupScreen(screen);
}
}
pickerField.addOpenAction();
pickerField.setWidth(fieldWidth);
return pickerField;
}
});
}
}
protected FieldGroup createRuntimeFieldGroup(Datasource ds) {
Component runtime = getComponent("runtime");
if (runtime != null) {
remove(runtime);
}
final FieldGroup newRuntimeFieldGroup = componentsFactory.createComponent(FieldGroup.NAME);
newRuntimeFieldGroup.setBorderVisible(Boolean.TRUE.equals(borderVisible));
newRuntimeFieldGroup.setWidth("100%");
newRuntimeFieldGroup.setId("runtime");
newRuntimeFieldGroup.setFrame(getFrame());
add(newRuntimeFieldGroup);
for (FieldGroup.FieldConfig field : newRuntimeFieldGroup.getFields()) {
newRuntimeFieldGroup.removeField(field);
}
final java.util.List<FieldGroup.FieldConfig> fields = createFieldsForAttributes();
addFieldsToFieldGroup(newRuntimeFieldGroup, fields);
if (!newRuntimeFieldGroup.getFields().isEmpty()) {
newRuntimeFieldGroup.setDatasource(ds);
}
initCustomFields(newRuntimeFieldGroup, newRuntimeFieldGroup.getFields(), ds);
for (FieldGroup.FieldConfig fieldConfig : newRuntimeFieldGroup.getFields()) {
loadValidators(newRuntimeFieldGroup, fieldConfig);
loadRequired(newRuntimeFieldGroup, fieldConfig);
}
return newRuntimeFieldGroup;
}
protected java.util.List<FieldGroup.FieldConfig> loadFields() {
protected java.util.List<FieldGroup.FieldConfig> createFieldsForAttributes() {
@SuppressWarnings("unchecked")
Collection<MetaProperty> metaProperties = rds.getPropertiesFilteredByCategory();
java.util.List<FieldGroup.FieldConfig> fields = new ArrayList<>();
for (MetaProperty property : metaProperties) {
@ -268,6 +179,109 @@ public class RuntimePropertiesFrame extends AbstractWindow {
return fields;
}
protected void addFieldsToFieldGroup(FieldGroup newRuntimeFieldGroup, List<FieldGroup.FieldConfig> fields) {
int rowsPerColumn;
int propertiesCount = rds.getPropertiesFilteredByCategory().size();
if (StringUtils.isNotBlank(cols)) {
if (propertiesCount % Integer.valueOf(cols) == 0) {
rowsPerColumn = propertiesCount / Integer.parseInt(cols);
} else {
rowsPerColumn = propertiesCount / Integer.parseInt(cols) + 1;
}
} else if (StringUtils.isNotBlank(rows)) {
rowsPerColumn = Integer.parseInt(rows);
} else {
rowsPerColumn = propertiesCount;
}
int columnNo = 0;
int fieldsCount = 0;
for (final FieldGroup.FieldConfig field : fields) {
fieldsCount++;
newRuntimeFieldGroup.addField(field, columnNo);
if (fieldsCount % rowsPerColumn == 0) {
columnNo++;
newRuntimeFieldGroup.setColumns(columnNo + 1);
}
}
}
protected void initCustomFields(FieldGroup component, java.util.List<FieldGroup.FieldConfig> fields, final Datasource ds) {
@SuppressWarnings("unchecked")
Collection<MetaProperty> metaProperties = rds.getPropertiesFilteredByCategory();
for (final MetaProperty metaProperty : metaProperties) {
Range range = metaProperty.getRange();
if (!range.isDatatype()) {
component.addCustomField(metaProperty.getName(), new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
final PickerField pickerField;
Boolean lookup = ((DynamicAttributesEntity) datasource.getItem())
.getCategoryValue(metaProperty.getName()).getCategoryAttribute().getLookup();
if (lookup != null && lookup) {
pickerField = AppConfig.getFactory().createComponent(LookupPickerField.NAME);
CollectionDatasource optionsDs = new DsBuilder(datasource.getDsContext())
.setMetaClass(metaProperty.getRange().asClass())
.setViewName(View.MINIMAL)
.buildCollectionDatasource();
optionsDs.refresh();
Action action = pickerField.getAction(LookupAction.NAME);
if (action != null)
pickerField.removeAction(action);
((LookupPickerField) pickerField).setOptionsDatasource(optionsDs);
} else {
pickerField = componentsFactory.createComponent(PickerField.NAME);
pickerField.addLookupAction();
}
pickerField.setMetaClass(ds.getMetaClass());
pickerField.setFrame(RuntimePropertiesFrame.this);
pickerField.setDatasource(ds, propertyId);
LookupAction lookupAction = (LookupAction) pickerField.getAction(LookupAction.NAME);
if (lookupAction != null) {
DynamicAttributesEntity dynamicAttributesEntity = (DynamicAttributesEntity) ds.getItem();
CategoryAttributeValue categoryAttributeValue = dynamicAttributesEntity.getCategoryValue(metaProperty.getName());
if (categoryAttributeValue != null) {
String screen = categoryAttributeValue.getCategoryAttribute().getScreen();
if (StringUtils.isBlank(screen)) {
WindowConfig windowConfig = AppBeans.get(WindowConfig.NAME);
screen = windowConfig.getBrowseScreenId(pickerField.getMetaClass());
}
lookupAction.setLookupScreen(screen);
}
}
pickerField.addOpenAction();
pickerField.setWidth(fieldWidth);
return pickerField;
}
});
} else {
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
final CategoryAttribute attribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (attribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
for (FieldGroup.FieldConfig field : fields) {
if (field.getId().equals(metaProperty.getName())) {
field.setCustom(true);
component.addCustomField(metaProperty.getName(), new FieldGroup.CustomFieldGenerator() {
@Override
public Component generateField(Datasource datasource, String propertyId) {
LookupField field = componentsFactory.createComponent(LookupField.NAME);
field.setFrame(RuntimePropertiesFrame.this);
field.setOptionsList(attribute.getEnumerationOptions());
field.setDatasource(rds, propertyId);
field.setWidth(fieldWidth);
return field;
}
});
}
}
}
}
}
}
}
protected Field.Validator getValidator(MetaProperty property) {
Field.Validator validator = null;
if (property.getRange().isDatatype()) {

View File

@ -14,10 +14,11 @@ import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.app.DataService;
import com.haulmont.cuba.core.app.PersistenceManagerService;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.core.sys.SetValueEntity;
import com.haulmont.cuba.gui.AppConfig;
import com.haulmont.cuba.gui.WindowManagerProvider;
import com.haulmont.cuba.gui.WindowParams;
@ -91,8 +92,8 @@ public class Param {
}
public Param(String name, Class javaClass, String entityWhere, String entityView,
Datasource datasource, boolean inExpr, UUID categoryAttrId, boolean required) {
this(name, javaClass, entityWhere, entityView, datasource, null, inExpr, required);
Datasource datasource, MetaProperty property, boolean inExpr, boolean required, UUID categoryAttrId) {
this(name, javaClass, entityWhere, entityView, datasource, property, inExpr, required);
this.categoryAttrId = categoryAttrId;
}
@ -106,6 +107,12 @@ public class Param {
this.property = property;
this.inExpr = inExpr;
this.required = required;
if (DynamicAttributesUtils.isDynamicAttribute(property)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(property);
if (categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
type = Type.RUNTIME_ENUM;
}
}
}
public String getName() {
@ -119,9 +126,7 @@ public class Param {
public void setJavaClass(Class javaClass) {
if (javaClass != null) {
this.javaClass = javaClass;
if (SetValueEntity.class.isAssignableFrom(javaClass)) {
type = Type.RUNTIME_ENUM;
} else if (Entity.class.isAssignableFrom(javaClass)) {
if (Entity.class.isAssignableFrom(javaClass)) {
type = Type.ENTITY;
} else if (Enum.class.isAssignableFrom(javaClass)) {
type = Type.ENUM;
@ -153,7 +158,7 @@ public class Param {
for (ValueListener listener : listeners) {
listener.valueChanged(this, "value", prevValue, value);
}
if ( updateEditComponent && this.editComponent instanceof Component.HasValue) {
if (updateEditComponent && this.editComponent instanceof Component.HasValue) {
((Component.HasValue) editComponent).setValue(value);
}
}
@ -245,7 +250,7 @@ public class Param {
if (value instanceof Collection) {
StringBuilder sb = new StringBuilder();
for (Iterator iterator = ((Collection) value).iterator(); iterator.hasNext();) {
for (Iterator iterator = ((Collection) value).iterator(); iterator.hasNext(); ) {
Object v = iterator.next();
sb.append(formatSingleValue(v));
if (iterator.hasNext())
@ -309,6 +314,7 @@ public class Param {
/**
* Creates an GUI component for condition parameter.
*
* @param valueProperty What value the editor will be connected with: current filter value or default one.
* @return GUI component for condition parameter.
*/
@ -621,7 +627,6 @@ public class Param {
}
private Component createEntityLookup(final ValueProperty valueProperty) {
Metadata metadata = AppBeans.get(Metadata.NAME);
MetaClass metaClass = metadata.getSession().getClass(javaClass);
@ -804,7 +809,7 @@ public class Param {
Element paramElem = element.addElement("param");
paramElem.addAttribute("name", getName());
paramElem.addAttribute("javaClass", getJavaClass().getName());
if (SetValueEntity.class.isAssignableFrom(javaClass) && runtimeEnum != null) {
if (runtimeEnum != null) {
paramElem.addAttribute("categoryAttrId", categoryAttrId.toString());
}

View File

@ -14,18 +14,16 @@ import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.Scripting;
import com.haulmont.cuba.core.sys.SetValueEntity;
import com.haulmont.cuba.gui.components.filter.Op;
import com.haulmont.cuba.gui.components.filter.Param;
import com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor;
import com.haulmont.cuba.gui.components.filter.operationedit.AbstractOperationEditor;
import com.haulmont.cuba.gui.components.filter.Param;
import com.haulmont.cuba.gui.data.Datasource;
import org.apache.commons.lang.*;
import org.dom4j.Element;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import static org.apache.commons.lang.StringUtils.isBlank;
@ -37,7 +35,7 @@ import static org.apache.commons.lang.StringUtils.isBlank;
*/
@MetaClass(name = "sec$AbstractCondition")
@SystemLevel
public abstract class AbstractCondition extends AbstractNotPersistentEntity{
public abstract class AbstractCondition extends AbstractNotPersistentEntity {
public interface Listener {
@ -50,7 +48,8 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
protected String paramName;
protected String caption;
protected String messagesPack;
@MetaProperty protected String locCaption;
@MetaProperty
protected String locCaption;
protected String filterComponentName;
protected String text;
protected Boolean group = false;
@ -65,7 +64,6 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
protected String entityParamWhere;
protected String entityParamView;
protected Datasource datasource;
protected UUID categoryAttrId;
protected Integer width = 1;
protected Op operator;
@ -92,7 +90,6 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
this.entityParamWhere = other.entityParamWhere;
this.entityParamView = other.entityParamView;
this.datasource = other.datasource;
this.categoryAttrId = other.categoryAttrId;
this.width = other.width;
this.param = other.param;
this.text = other.text;
@ -120,45 +117,7 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
width = Strings.isNullOrEmpty(element.attributeValue("width")) ? 1 : Integer.valueOf(element.attributeValue("width"));
this.datasource = datasource;
Scripting scripting = AppBeans.get(Scripting.NAME);
String aclass = element.attributeValue("class");
if (!isBlank(aclass))
javaClass = scripting.loadClass(aclass);
List<Element> paramElements = Dom4j.elements(element, "param");
if (!paramElements.isEmpty()) {
Element paramElem = paramElements.iterator().next();
if (BooleanUtils.toBoolean(paramElem.attributeValue("hidden", "false"), "true", "false")) {
paramElem = paramElements.iterator().next();
}
paramName = paramElem.attributeValue("name");
if (!isBlank(paramElem.attributeValue("javaClass"))) {
paramClass = scripting.loadClass(paramElem.attributeValue("javaClass"));
if (SetValueEntity.class.isAssignableFrom(paramClass)) {
categoryAttrId = UUID.fromString(paramElem.attributeValue("categoryAttrId"));
}
}
param = createParam();
param.parseValue(paramElem.getText());
param.setDefaultValue(param.getValue());
}
String operatorName = element.attributeValue("operatorType", null);
if (operatorName != null) {
//for backward compatibility with old filters that still use EMPTY operator
if ("EMPTY".equals(operatorName)) {
operatorName = "NOT_EMPTY";
if (BooleanUtils.isTrue((Boolean) param.getValue()))
param.setValue(false);
param.setDefaultValue(false);
}
operator = Op.valueOf(operatorName);
}
resolveParam(element);
}
protected AbstractCondition(AbstractConditionDescriptor descriptor) {
@ -179,6 +138,45 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
}
}
protected void resolveParam(Element element) {
Scripting scripting = AppBeans.get(Scripting.NAME);
String aclass = element.attributeValue("class");
if (!isBlank(aclass)) {
javaClass = scripting.loadClass(aclass);
}
List<Element> paramElements = Dom4j.elements(element, "param");
if (!paramElements.isEmpty()) {
Element paramElem = paramElements.iterator().next();
if (BooleanUtils.toBoolean(paramElem.attributeValue("hidden", "false"), "true", "false")) {
paramElem = paramElements.iterator().next();
}
paramName = paramElem.attributeValue("name");
if (!isBlank(paramElem.attributeValue("javaClass"))) {
paramClass = scripting.loadClass(paramElem.attributeValue("javaClass"));
}
param = createParam();
param.parseValue(paramElem.getText());
param.setDefaultValue(param.getValue());
}
String operatorName = element.attributeValue("operatorType", null);
if (operatorName != null) {
//for backward compatibility with old filters that still use EMPTY operator
if ("EMPTY".equals(operatorName)) {
operatorName = "NOT_EMPTY";
if (BooleanUtils.isTrue((Boolean) param.getValue()))
param.setValue(false);
param.setDefaultValue(false);
}
operator = Op.valueOf(operatorName);
}
}
protected Param createParam() {
if (Strings.isNullOrEmpty(paramName)) {
paramName = createParamName();
@ -187,12 +185,8 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
if (unary)
return new Param(paramName, null, null, null, null, false, required);
if (categoryAttrId != null) {
return new Param(paramName, paramClass, entityParamWhere,
entityParamView, datasource, inExpr, categoryAttrId, required);
} else
return new Param(paramName, paramClass == null ? javaClass : paramClass,
entityParamWhere, entityParamView, datasource, inExpr, required);
return new Param(paramName, paramClass == null ? javaClass : paramClass,
entityParamWhere, entityParamView, datasource, inExpr, required);
}
public void addListener(Listener listener) {
@ -395,7 +389,9 @@ public abstract class AbstractCondition extends AbstractNotPersistentEntity{
public AbstractOperationEditor getOperationEditor() {
return operationEditor;
};
}
;
public abstract AbstractCondition createCopy();

View File

@ -8,14 +8,16 @@ package com.haulmont.cuba.gui.components.filter.condition;
import com.google.common.base.Strings;
import com.haulmont.bali.util.Dom4j;
import com.haulmont.chile.core.annotations.MetaClass;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.entity.annotation.SystemLevel;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.MessageTools;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.gui.components.filter.Op;
import com.haulmont.cuba.gui.components.filter.operationedit.AbstractOperationEditor;
import com.haulmont.cuba.gui.components.filter.Param;
import com.haulmont.cuba.gui.components.filter.descriptor.AbstractConditionDescriptor;
import com.haulmont.cuba.gui.components.filter.operationedit.AbstractOperationEditor;
import com.haulmont.cuba.gui.components.filter.operationedit.DynamicAttributesOperationEditor;
import com.haulmont.cuba.gui.data.Datasource;
import org.apache.commons.lang.BooleanUtils;
@ -84,6 +86,8 @@ public class DynamicAttributesCondition extends AbstractCondition {
}
}
}
resolveParam(element);
}
@Override
@ -149,10 +153,17 @@ public class DynamicAttributesCondition extends AbstractCondition {
@Override
protected Param createParam() {
if (unary)
return new Param(paramName, Boolean.class, null, null, null, false, required);
if (categoryAttributeId != null) {
Class paramJavaClass = unary ? Boolean.class : javaClass;
return super.createParam();
MetaPropertyPath metaPropertyPath = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), categoryAttributeId);
Param param = new Param(paramName, paramJavaClass, null, null, datasource,
metaPropertyPath != null ? metaPropertyPath.getMetaProperty() : null,
inExpr, required, categoryAttributeId);
return param;
} else {
return super.createParam();
}
}
@Override

View File

@ -5,15 +5,18 @@
package com.haulmont.cuba.gui.components.filter.edit;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.app.DataService;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.entity.Category;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.core.sys.SetValueEntity;
import com.haulmont.cuba.gui.components.*;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.Metadata;
import com.haulmont.cuba.gui.components.IFrame;
import com.haulmont.cuba.gui.components.Label;
import com.haulmont.cuba.gui.components.LookupField;
import com.haulmont.cuba.gui.components.filter.Op;
import com.haulmont.cuba.gui.components.filter.Param;
import com.haulmont.cuba.gui.components.filter.condition.DynamicAttributesCondition;
@ -123,9 +126,7 @@ public class DynamicAttributesConditionFrame extends ConditionFrame<DynamicAttri
Class javaClass = DynamicAttributesUtils.getAttributeClass(attribute);
String valueFieldName = "stringValue";
if (SetValueEntity.class.isAssignableFrom(javaClass)) {
valueFieldName = "stringValue";
} else if (Entity.class.isAssignableFrom(javaClass))
if (Entity.class.isAssignableFrom(javaClass))
valueFieldName = "entityValue";
else if (String.class.isAssignableFrom(javaClass))
valueFieldName = "stringValue";
@ -160,17 +161,11 @@ public class DynamicAttributesConditionFrame extends ConditionFrame<DynamicAttri
condition.setEntityParamWhere(null);
condition.setInExpr(Op.IN.equals(op) || Op.NOT_IN.equals(op));
condition.setOperator(operationLookup.<Op>getValue());
Param param;
Class paramJavaClass = op.isUnary() ? Boolean.class : javaClass;
if (SetValueEntity.class.isAssignableFrom(javaClass)) {
condition.setJavaClass(String.class);
param = new Param(paramName, paramJavaClass, null, null, condition.getDatasource(),
condition.getInExpr(), attribute.getId(), condition.getRequired());
} else {
condition.setJavaClass(javaClass);
param = new Param(paramName, paramJavaClass, null, null, condition.getDatasource(),
condition.getInExpr(), condition.getRequired());
}
condition.setJavaClass(javaClass);
Param param = new Param(paramName, paramJavaClass, null, null, condition.getDatasource(),
DynamicAttributesUtils.getMetaPropertyPath(null, attribute).getMetaProperty(),
condition.getInExpr(), condition.getRequired(), attribute.getId());
Object defaultValue = condition.getParam().getDefaultValue();
param.setDefaultValue(defaultValue);
@ -184,24 +179,20 @@ public class DynamicAttributesConditionFrame extends ConditionFrame<DynamicAttri
}
protected void fillCategorySelect() {
List<String> metaClassName = getMetaClassNames();
LoadContext context = new LoadContext(Category.class);
context.setView("_minimal")
.setQueryString("select c from sys$Category c where c.entityType in :entityType")
.setParameter("entityType", metaClassName);
List<Category> categories = dataService.loadList(context);
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
Collection<Category> categories = dynamicAttributes.getCategoriesForMetaClass(condition.getDatasource().getMetaClass());
UUID catId = condition.getCategoryId();
Category selectedCategory = null;
Map<String, Object> categoriesMap = new TreeMap<String, Object>();
if (categories.size() == 1 && (catId == null || ObjectUtils.equals(catId, categories.get(0).getId()))) {
Category category = categories.get(0);
Map<String, Object> categoriesMap = new TreeMap<>();
if (categories.size() == 1 && (catId == null || ObjectUtils.equals(catId, categories.iterator().next().getId()))) {
Category category = categories.iterator().next();
categoryLookup.setVisible(false);
categoryLabel.setVisible(false);
attributeLookup.requestFocus();
categoriesMap.put(category.getName(), category);
categoryLookup.setOptionsMap(categoriesMap);
categoryLookup.setValue(category);
fillAttributeSelect(categories.get(0));
fillAttributeSelect(category);
} else {
categoryLookup.setVisible(true);
categoryLabel.setVisible(true);
@ -216,30 +207,11 @@ public class DynamicAttributesConditionFrame extends ConditionFrame<DynamicAttri
}
}
protected List<String> getMetaClassNames() {
String metaClassName = condition.getDatasource().getMetaClass().getName();
List<String> metaClassNames = new ArrayList<>();
metaClassNames.add(metaClassName);
MetaClass currentMetaClass = metadata.getClass(metaClassName);
if (currentMetaClass == null)
return metaClassNames;
Collection<MetaClass> descendants = currentMetaClass.getDescendants();
for (MetaClass metaClass : descendants) {
metaClassNames.add(metaClass.getName());
}
return metaClassNames;
}
protected void fillAttributeSelect(Category category) {
LoadContext context = new LoadContext(CategoryAttribute.class);
LoadContext.Query query = context.setQueryString("select ca from sys$CategoryAttribute ca where ca.category.id = :id ");
query.setParameter("id", category.getId());
context.setView("_local");
List<CategoryAttribute> attributes = dataService.loadList(context);
UUID attrId = condition.getCategoryAttributeId();
CategoryAttribute selectedAttribute = null;
Map<String, Object> attributesMap = new TreeMap<>();
for (CategoryAttribute attribute : attributes) {
for (CategoryAttribute attribute : category.getCategoryAttrs()) {
attributesMap.put(attribute.getName(), attribute);
if (attribute.getId().equals(attrId)) {
selectedAttribute = attribute;
@ -250,7 +222,7 @@ public class DynamicAttributesConditionFrame extends ConditionFrame<DynamicAttri
}
protected void fillOperationSelect(Class clazz) {
List ops = new LinkedList(Op.availableOps(clazz));
List<Op> ops = new LinkedList<>(Op.availableOps(clazz));
operationLookup.setOptionsList(ops);
Op operator = condition.getOperator();
if (operator != null) {

View File

@ -6,14 +6,13 @@ package com.haulmont.cuba.gui.data;
import com.haulmont.chile.core.common.ValueListener;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.BaseEntity;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.CategoryAttributeValue;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.UuidProvider;
import com.haulmont.cuba.core.sys.SetValueEntity;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
@ -189,12 +188,8 @@ public class DynamicAttributesEntity implements BaseEntity {
attrValue.setDateValue((Date) value);
break;
case STRING:
attrValue.setStringValue(StringUtils.trimToNull((String) value));
break;
case ENUMERATION:
if (value != null)
attrValue.setStringValue(StringUtils.trimToNull(((SetValueEntity) value).getValue()));
else attrValue.setStringValue(null);
attrValue.setStringValue(StringUtils.trimToNull((String) value));
break;
case ENTITY:
attrValue.setEntityValue((UUID) value);

View File

@ -14,7 +14,6 @@ import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.*;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.core.sys.SetValueEntity;
import com.haulmont.cuba.gui.data.*;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
@ -98,6 +97,7 @@ public class RuntimePropsDatasourceImpl
if (PersistenceHelper.isNew(baseGenericIdEntity)) {
baseGenericIdEntity.setDynamicAttributes(new HashMap<String, CategoryAttributeValue>());
}
@SuppressWarnings("unchecked")
Map<String, CategoryAttributeValue> dynamicAttributes = baseGenericIdEntity.getDynamicAttributes();
Preconditions.checkNotNullArgument(dynamicAttributes, "Dynamic attributes should be loaded explicitly");
@ -190,43 +190,16 @@ public class RuntimePropsDatasourceImpl
switch (PropertyType.valueOf(dataType)) {
case STRING:
if (attrValue != null)
return attrValue.getStringValue();
else return attribute.getDefaultString();
case INTEGER:
if (attrValue != null)
return attrValue.getIntValue();
else return attribute.getDefaultInt();
case DOUBLE:
if (attrValue != null)
return attrValue.getDoubleValue();
else
return attribute.getDefaultDouble();
case BOOLEAN:
if (attrValue != null)
return attrValue.getBooleanValue();
else
return attribute.getDefaultBoolean();
case DATE:
if (attrValue != null)
return attrValue.getDateValue();
else
return attribute.getDefaultDate();
case ENUMERATION:
if (attrValue != null) {
String stringValue = attrValue.getStringValue();
if (stringValue != null && !StringUtils.isBlank(stringValue))
return new SetValueEntity(stringValue);
else
return null;
} else {
String eValue = attribute.getDefaultString();
if (eValue != null)
return new SetValueEntity(eValue);
else
return null;
}
return attrValue != null ? attrValue.getStringValue() : attribute.getDefaultString();
case INTEGER:
return attrValue != null ? attrValue.getIntValue() : attribute.getDefaultInt();
case DOUBLE:
return attrValue != null ? attrValue.getDoubleValue() : attribute.getDefaultDouble();
case BOOLEAN:
return attrValue != null ? attrValue.getBooleanValue() : attribute.getDefaultBoolean();
case DATE:
return attrValue != null ? attrValue.getDateValue() : attribute.getDefaultDate();
}
}

View File

@ -5,6 +5,7 @@
package com.haulmont.cuba.gui.xml.layout.loaders;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.chile.core.model.MetaProperty;
import com.haulmont.chile.core.model.MetaPropertyPath;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
@ -329,11 +330,11 @@ public abstract class AbstractTableLoader extends ComponentLoader {
String columnCaption;
if (column.getId() instanceof MetaPropertyPath) {
MetaPropertyPath mpp = (MetaPropertyPath) column.getId();
String propertyName = mpp.getMetaProperty().getName();
MetaProperty metaProperty = mpp.getMetaProperty();
String propertyName = metaProperty.getName();
if (DynamicAttributesUtils.isDynamicAttribute(propertyName)) {
CategoryAttribute categoryAttribute =
dynamicAttributes.getAttributeForMetaClass(ds.getMetaClass(), propertyName);
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
columnCaption = categoryAttribute != null ? categoryAttribute.getName() : propertyName;
} else {
MetaClass propertyMetaClass = metadataTools.getPropertyEnclosingMetaClass(mpp);

View File

@ -300,9 +300,8 @@ public class FieldGroupLoader extends AbstractFieldLoader {
}
String propertyName = metaPropertyPath != null ? metaPropertyPath.getMetaProperty().getName() : null;
if (propertyName != null && DynamicAttributesUtils.isDynamicAttribute(propertyName)) {
CategoryAttribute categoryAttribute =
dynamicAttributes.getAttributeForMetaClass(ds.getMetaClass(), propertyName);
if (metaPropertyPath != null && DynamicAttributesUtils.isDynamicAttribute(metaPropertyPath.getMetaProperty())) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaPropertyPath.getMetaProperty());
field.setCaption(categoryAttribute != null ? categoryAttribute.getName() : propertyName);
} else {
loadCaption(field, element);
@ -461,7 +460,7 @@ public class FieldGroupLoader extends AbstractFieldLoader {
boolean visible = security.isEntityAttrReadPermitted(metaClass, propertyPath.toString());
component.setVisible(field, visible);
} else if (!DynamicAttributesUtils.isDynamicAttribute(propertyPath.toString())) {
} else if (!DynamicAttributesUtils.isDynamicAttribute(propertyPath.getMetaProperty())) {
Element element = field.getXmlDescriptor();
final String editable = element.attributeValue("editable");
if (!StringUtils.isEmpty(editable)) {

View File

@ -6,7 +6,6 @@ package com.haulmont.cuba.web.gui.components;
import com.haulmont.chile.core.datatypes.Enumeration;
import com.haulmont.chile.core.model.MetaClass;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributes;
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
@ -77,9 +76,8 @@ public abstract class WebAbstractOptionsField<T extends com.vaadin.ui.AbstractSe
setCaptionMode(CaptionMode.ITEM);
}
DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME);
if (metaProperty.getRange().isClass() && DynamicAttributesUtils.isDynamicAttribute(property)) {
CategoryAttribute categoryAttribute = dynamicAttributes.getAttributeForMetaClass(metaClass, property);
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataTypeAsPropertyType() == PropertyType.ENUMERATION) {
setOptionsList(categoryAttribute.getEnumerationOptions());
}