From 91ee1a391ff71e125fb7049418bbc6f30a73cd75 Mon Sep 17 00:00:00 2001 From: Eugeny Degtyarjov Date: Tue, 30 Jun 2015 11:32:12 +0000 Subject: [PATCH] PL-5497 Re-write CategoryAttribute editor, Runtime properties frame and all linked. Get rid of SetValueEntity. SetValue entity removed, runtimePropertiesFrame refactored #PL-5497 --- .../DesktopAbstractOptionsField.java | 6 +- .../DynamicAttributesMetaProperty.java | 25 +- .../DynamicAttributesUtils.java | 38 ++- .../cuba/core/entity/CategoryAttribute.java | 10 +- .../core/entity/CategoryAttributeValue.java | 7 - .../cuba/core/sys/SetValueEntity.java | 60 ---- modules/global/src/cuba-metadata.xml | 1 - .../gui/components/AbstractFieldFactory.java | 17 +- .../components/RuntimePropertiesFrame.java | 270 +++++++++--------- .../cuba/gui/components/filter/Param.java | 25 +- .../filter/condition/AbstractCondition.java | 102 ++++--- .../condition/DynamicAttributesCondition.java | 19 +- .../edit/DynamicAttributesConditionFrame.java | 68 ++--- .../gui/data/DynamicAttributesEntity.java | 9 +- .../data/impl/RuntimePropsDatasourceImpl.java | 47 +-- .../layout/loaders/AbstractTableLoader.java | 9 +- .../xml/layout/loaders/FieldGroupLoader.java | 7 +- .../components/WebAbstractOptionsField.java | 6 +- 18 files changed, 324 insertions(+), 402 deletions(-) delete mode 100644 modules/global/src/com/haulmont/cuba/core/sys/SetValueEntity.java diff --git a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractOptionsField.java b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractOptionsField.java index da47e36eba..464f918efa 100644 --- a/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractOptionsField.java +++ b/modules/desktop/src/com/haulmont/cuba/desktop/gui/components/DesktopAbstractOptionsField.java @@ -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 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()); } diff --git a/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesMetaProperty.java b/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesMetaProperty.java index 6c02e628ed..9122516995 100644 --- a/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesMetaProperty.java +++ b/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesMetaProperty.java @@ -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; + } } diff --git a/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesUtils.java b/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesUtils.java index ebf6526668..1d92962f4a 100644 --- a/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesUtils.java +++ b/modules/global/src/com/haulmont/cuba/core/app/dynamicattributes/DynamicAttributesUtils.java @@ -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 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; diff --git a/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttribute.java b/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttribute.java index 3bb412f7d4..6f191a813a 100644 --- a/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttribute.java +++ b/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttribute.java @@ -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 getEnumerationOptions() { + public List getEnumerationOptions() { Preconditions.checkState(getDataTypeAsPropertyType() == PropertyType.ENUMERATION, "Only enumeration attributes have options"); String enumeration = getEnumeration(); String[] values = StringUtils.split(enumeration, ','); - List options = new LinkedList<>(); - for (String value : values) { - String trimmedValue = StringUtils.trimToNull(value); - options.add(new SetValueEntity(trimmedValue)); - } - return options; + return Arrays.asList(values); } } diff --git a/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttributeValue.java b/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttributeValue.java index 0f478e849a..9dd16a782a 100644 --- a/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttributeValue.java +++ b/modules/global/src/com/haulmont/cuba/core/entity/CategoryAttributeValue.java @@ -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; diff --git a/modules/global/src/com/haulmont/cuba/core/sys/SetValueEntity.java b/modules/global/src/com/haulmont/cuba/core/sys/SetValueEntity.java deleted file mode 100644 index 537e658c75..0000000000 --- a/modules/global/src/com/haulmont/cuba/core/sys/SetValueEntity.java +++ /dev/null @@ -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; - -/** - *

$Id$

- * - * @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; - } -} diff --git a/modules/global/src/cuba-metadata.xml b/modules/global/src/cuba-metadata.xml index 3570854c4a..a16f05545f 100644 --- a/modules/global/src/cuba-metadata.xml +++ b/modules/global/src/cuba-metadata.xml @@ -14,7 +14,6 @@ com.haulmont.cuba.core.entity.diff.EntityDiff com.haulmont.cuba.core.entity.diff.EntityPropertyDiff com.haulmont.cuba.core.global.LockInfo - com.haulmont.cuba.core.sys.SetValueEntity com.haulmont.cuba.security.entity.EntityLogAttr com.haulmont.cuba.security.entity.UserSessionEntity diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/AbstractFieldFactory.java b/modules/gui/src/com/haulmont/cuba/gui/components/AbstractFieldFactory.java index a4c44e0469..d7c0aaa0e9 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/AbstractFieldFactory.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/AbstractFieldFactory.java @@ -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); diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/RuntimePropertiesFrame.java b/modules/gui/src/com/haulmont/cuba/gui/components/RuntimePropertiesFrame.java index a3611aa231..00bd731a53 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/RuntimePropertiesFrame.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/RuntimePropertiesFrame.java @@ -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 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 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 fields, final Datasource ds) { - Collection 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 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 loadFields() { + protected java.util.List createFieldsForAttributes() { + @SuppressWarnings("unchecked") Collection metaProperties = rds.getPropertiesFilteredByCategory(); java.util.List fields = new ArrayList<>(); for (MetaProperty property : metaProperties) { @@ -268,6 +179,109 @@ public class RuntimePropertiesFrame extends AbstractWindow { return fields; } + protected void addFieldsToFieldGroup(FieldGroup newRuntimeFieldGroup, List 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 fields, final Datasource ds) { + @SuppressWarnings("unchecked") + Collection 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()) { diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/Param.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/Param.java index d7659c42ff..fee96a3e8a 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/Param.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/Param.java @@ -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()); } diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/AbstractCondition.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/AbstractCondition.java index a36c3ae578..29ca84a52e 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/AbstractCondition.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/AbstractCondition.java @@ -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 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 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(); diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/DynamicAttributesCondition.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/DynamicAttributesCondition.java index 073225379b..20f22a2c56 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/DynamicAttributesCondition.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/condition/DynamicAttributesCondition.java @@ -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 diff --git a/modules/gui/src/com/haulmont/cuba/gui/components/filter/edit/DynamicAttributesConditionFrame.java b/modules/gui/src/com/haulmont/cuba/gui/components/filter/edit/DynamicAttributesConditionFrame.java index 45a47b7aad..7f94ae261d 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/components/filter/edit/DynamicAttributesConditionFrame.java +++ b/modules/gui/src/com/haulmont/cuba/gui/components/filter/edit/DynamicAttributesConditionFrame.java @@ -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 ConditionFramegetValue()); - 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 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 categories = dataService.loadList(context); + DynamicAttributes dynamicAttributes = AppBeans.get(DynamicAttributes.NAME); + Collection categories = dynamicAttributes.getCategoriesForMetaClass(condition.getDatasource().getMetaClass()); UUID catId = condition.getCategoryId(); Category selectedCategory = null; - Map categoriesMap = new TreeMap(); - if (categories.size() == 1 && (catId == null || ObjectUtils.equals(catId, categories.get(0).getId()))) { - Category category = categories.get(0); + Map 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 getMetaClassNames() { - String metaClassName = condition.getDatasource().getMetaClass().getName(); - List metaClassNames = new ArrayList<>(); - metaClassNames.add(metaClassName); - MetaClass currentMetaClass = metadata.getClass(metaClassName); - if (currentMetaClass == null) - return metaClassNames; - Collection 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 attributes = dataService.loadList(context); UUID attrId = condition.getCategoryAttributeId(); CategoryAttribute selectedAttribute = null; Map 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 ops = new LinkedList<>(Op.availableOps(clazz)); operationLookup.setOptionsList(ops); Op operator = condition.getOperator(); if (operator != null) { diff --git a/modules/gui/src/com/haulmont/cuba/gui/data/DynamicAttributesEntity.java b/modules/gui/src/com/haulmont/cuba/gui/data/DynamicAttributesEntity.java index 74cb8465fd..7133d7e06e 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/data/DynamicAttributesEntity.java +++ b/modules/gui/src/com/haulmont/cuba/gui/data/DynamicAttributesEntity.java @@ -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); diff --git a/modules/gui/src/com/haulmont/cuba/gui/data/impl/RuntimePropsDatasourceImpl.java b/modules/gui/src/com/haulmont/cuba/gui/data/impl/RuntimePropsDatasourceImpl.java index b8f4a89656..63021a543e 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/data/impl/RuntimePropsDatasourceImpl.java +++ b/modules/gui/src/com/haulmont/cuba/gui/data/impl/RuntimePropsDatasourceImpl.java @@ -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()); } + @SuppressWarnings("unchecked") Map 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(); } } diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTableLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTableLoader.java index 6e134a0736..394bc9cc9e 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTableLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractTableLoader.java @@ -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); diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FieldGroupLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FieldGroupLoader.java index cc875d869e..411a00b80c 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FieldGroupLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FieldGroupLoader.java @@ -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)) { diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractOptionsField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractOptionsField.java index fa3845763e..94e4ba9c6e 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractOptionsField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebAbstractOptionsField.java @@ -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