use of com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener in project cuba by cuba-platform.
the class DesktopFileUploadField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
this.datasource = datasource;
if (datasource == null) {
setValue(null);
return;
}
MetaClass metaClass = datasource.getMetaClass();
resolveMetaPropertyPath(metaClass, property);
itemChangeListener = e -> {
if (updatingInstance)
return;
FileDescriptor descriptor = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
updateComponent(descriptor);
fireChangeListeners(descriptor);
};
// noinspection unchecked
datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
itemPropertyChangeListener = e -> {
if (updatingInstance)
return;
if (e.getProperty().equals(metaPropertyPath.toString())) {
updateComponent((FileDescriptor) e.getValue());
fireChangeListeners(e.getValue());
}
};
// noinspection unchecked
datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
initRequired(metaPropertyPath);
if ((datasource.getState() == Datasource.State.VALID) && (datasource.getItem() != null)) {
Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
FileDescriptor fileDescriptor = (FileDescriptor) newValue;
updateComponent(fileDescriptor);
fireChangeListeners(newValue);
}
if (metaProperty.isReadOnly()) {
setEditable(false);
}
handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
// noinspection unchecked
this.datasource.addItemChangeListener(new WeakItemChangeListener(this.datasource, securityItemChangeListener));
initBeanValidator();
}
use of com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener in project cuba by cuba-platform.
the class DesktopImage 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) {
metaPropertyPath = null;
impl.setImage((java.awt.Image) null);
// noinspection unchecked
this.datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
weakItemPropertyChangeListener = null;
// noinspection unchecked
this.datasource.removeItemChangeListener(weakItemChangeListener);
weakItemChangeListener = null;
this.datasource = null;
}
if (datasource != null) {
// noinspection unchecked
this.datasource = datasource;
metaPropertyPath = AppBeans.get(MetadataTools.class).resolveMetaPropertyPathNN(datasource.getMetaClass(), property);
updateComponent();
itemPropertyChangeListener = e -> {
if (e.getProperty().equals(metaPropertyPath.toString())) {
updateComponent();
}
};
weakItemPropertyChangeListener = new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener);
// noinspection unchecked
this.datasource.addItemPropertyChangeListener(weakItemPropertyChangeListener);
itemChangeListener = e -> updateComponent();
weakItemChangeListener = new WeakItemChangeListener(datasource, itemChangeListener);
// noinspection unchecked
datasource.addItemChangeListener(weakItemChangeListener);
}
}
use of com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener in project cuba by cuba-platform.
the class DesktopPickerField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
checkDatasourceProperty(datasource, property);
this.datasource = datasource;
// null datasource is not supported for this class
/*if (datasource == null) {
setValue(null);
return;
}*/
resolveMetaPropertyPath(datasource.getMetaClass(), property);
itemChangeListener = e -> {
if (updatingInstance) {
return;
}
Object value = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
updateComponent(value);
fireChangeListeners(value);
};
// noinspection unchecked
datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
itemPropertyChangeListener = e -> {
if (updatingInstance) {
return;
}
if (e.getProperty().equals(metaProperty.getName())) {
updateComponent(e.getValue());
fireChangeListeners(e.getValue());
}
};
// noinspection unchecked
datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
if ((datasource.getState() == Datasource.State.VALID) && (datasource.getItem() != null)) {
Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
updateComponent(newValue);
fireChangeListeners(newValue);
}
initRequired(metaPropertyPath);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
handleFilteredAttributes(this, this.datasource, metaPropertyPath);
securityItemChangeListener = e -> handleFilteredAttributes(this, this.datasource, metaPropertyPath);
// noinspection unchecked
this.datasource.addItemChangeListener(new WeakItemChangeListener(this.datasource, securityItemChangeListener));
initBeanValidator();
}
use of com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener in project cuba by cuba-platform.
the class WebDatePicker 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(weakItemChangeListener);
weakItemChangeListener = null;
// noinspection unchecked
this.datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
weakItemPropertyChangeListener = 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);
component.addValueChangeListener(event -> {
if (!checkRange(component.getValue())) {
return;
}
updateInstance();
});
itemChangeListener = e -> {
if (updatingInstance) {
return;
}
Date value = getEntityValue(e.getItem());
setValueToFields(value);
fireValueChanged(value);
};
weakItemChangeListener = new WeakItemChangeListener(datasource, itemChangeListener);
// noinspection unchecked
datasource.addItemChangeListener(weakItemChangeListener);
itemPropertyChangeListener = e -> {
if (updatingInstance) {
return;
}
if (e.getProperty().equals(metaPropertyPath.toString())) {
setValueToFields((Date) e.getValue());
fireValueChanged(e.getValue());
}
};
weakItemPropertyChangeListener = new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener);
// noinspection unchecked
datasource.addItemPropertyChangeListener(weakItemPropertyChangeListener);
if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) {
if (property.equals(metaPropertyPath.toString())) {
Date value = getEntityValue(datasource.getItem());
setValueToFields(value);
fireValueChanged(value);
}
}
initRequired(metaPropertyPath);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
initBeanValidator();
setDateRangeByProperty(metaProperty);
}
}
use of com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener in project cuba by cuba-platform.
the class WebImage 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) {
metaPropertyPath = null;
component.setSource(null);
// noinspection unchecked
this.datasource.removeItemPropertyChangeListener(weakItemPropertyChangeListener);
weakItemPropertyChangeListener = null;
// noinspection unchecked
this.datasource.removeItemChangeListener(weakItemChangeListener);
weakItemChangeListener = null;
this.datasource = null;
}
if (datasource != null) {
// noinspection unchecked
this.datasource = datasource;
metaPropertyPath = AppBeans.get(MetadataTools.class).resolveMetaPropertyPathNN(datasource.getMetaClass(), property);
updateComponent();
itemPropertyChangeListener = e -> {
if (e.getProperty().equals(metaPropertyPath.toString())) {
updateComponent();
}
};
weakItemPropertyChangeListener = new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener);
// noinspection unchecked
this.datasource.addItemPropertyChangeListener(weakItemPropertyChangeListener);
itemChangeListener = e -> updateComponent();
weakItemChangeListener = new WeakItemChangeListener(datasource, itemChangeListener);
// noinspection unchecked
datasource.addItemChangeListener(weakItemChangeListener);
}
}
Aggregations