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