PL-6252 Value listener for setting dynamic entity attributes values should be added to entity once more after editor commit

#PL-6252
This commit is contained in:
Eugeny Degtyarjov 2015-10-28 06:53:51 +00:00
parent d37c552799
commit 7ac831f3e6
2 changed files with 16 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import com.haulmont.chile.core.model.utils.InstanceUtils;
import com.haulmont.cuba.client.ClientConfig;
import com.haulmont.cuba.core.app.LockService;
import com.haulmont.cuba.core.entity.BaseGenericIdEntity;
import com.haulmont.cuba.core.entity.Categorized;
import com.haulmont.cuba.core.entity.Entity;
import com.haulmont.cuba.core.global.*;
import com.haulmont.cuba.gui.ComponentsHelper;
@ -156,7 +157,10 @@ public class EditorWindowDelegate extends WindowDelegate {
if (ds.getLoadDynamicAttributes() && item instanceof BaseGenericIdEntity) {
DynamicAttributesGuiTools dynamicAttributesGuiTools = AppBeans.get(DynamicAttributesGuiTools.NAME);
dynamicAttributesGuiTools.initDefaultAttributeValues((BaseGenericIdEntity) item, ds);
dynamicAttributesGuiTools.initDefaultAttributeValues((BaseGenericIdEntity) item);
if (item instanceof Categorized) {
dynamicAttributesGuiTools.addCategoryChangeListener(ds);
}
}
this.item = item;

View File

@ -68,7 +68,7 @@ public class DynamicAttributesGuiTools {
return categoryAttributes;
}
public void initDefaultAttributeValues(BaseGenericIdEntity item, Datasource ds) {
public void initDefaultAttributeValues(BaseGenericIdEntity item) {
Collection<CategoryAttribute> attributes =
dynamicAttributes.getAttributesForMetaClass(item.getMetaClass());
if (item.getDynamicAttributes() == null) {
@ -94,17 +94,18 @@ public class DynamicAttributesGuiTools {
item.setValue(code, currentTimestamp);
}
}
}
if (item instanceof Categorized) {
ds.addItemPropertyChangeListener(new Datasource.ItemPropertyChangeListener() {
@Override
public void itemPropertyChanged(Datasource.ItemPropertyChangeEvent e) {
if ("category".equals(e.getProperty())) {
initDefaultAttributeValues((BaseGenericIdEntity) e.getItem(), ds);
}
@SuppressWarnings("unchecked")
public void addCategoryChangeListener(Datasource ds) {
ds.addItemPropertyChangeListener(new Datasource.ItemPropertyChangeListener() {
@Override
public void itemPropertyChanged(Datasource.ItemPropertyChangeEvent e) {
if ("category".equals(e.getProperty())) {
initDefaultAttributeValues((BaseGenericIdEntity) e.getItem());
}
});
}
}
});
}
protected boolean attributeShouldBeShownOnTheScreen(String screen, String component, CategoryAttribute attribute) {