use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener in project cuba by cuba-platform.
the class DesktopTimeField method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
this.datasource = datasource;
if (datasource == null) {
setValue(null);
return;
}
resolveMetaPropertyPath(datasource.getMetaClass(), property);
itemChangeListener = e -> {
if (updatingInstance) {
return;
}
Date 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(metaPropertyPath.toString())) {
updateComponent(e.getValue());
fireChangeListeners(e.getValue());
}
};
// noinspection unchecked;
datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) {
if (property.equals(metaPropertyPath.toString())) {
Date value = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
updateComponent(value);
fireChangeListeners(value);
}
}
initRequired(metaPropertyPath);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
initBeanValidator();
}
use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener in project cuba by cuba-platform.
the class DesktopCheckBox method setDatasource.
@SuppressWarnings("unchecked")
@Override
public void setDatasource(Datasource datasource, String property) {
this.datasource = datasource;
if (datasource == null) {
setValue(null);
return;
}
resolveMetaPropertyPath(datasource.getMetaClass(), property);
itemChangeListener = e -> {
if (updatingInstance)
return;
Boolean value = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
if (value == null) {
value = false;
}
updateComponent(value);
fireChangeListeners(value);
};
datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
itemPropertyChangeListener = e -> {
if (updatingInstance) {
return;
}
if (e.getProperty().equals(metaPropertyPath.toString())) {
Object value = e.getValue();
if (e.getValue() == null) {
value = false;
}
updateComponent(value);
fireChangeListeners(value);
}
};
datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
if (datasource.getItemIfValid() != null) {
Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
if (!Objects.equals(prevValue, newValue)) {
updateComponent(newValue);
fireChangeListeners(newValue);
}
}
if (metaProperty.isReadOnly()) {
setEditable(false);
}
initBeanValidator();
}
use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener in project cuba by cuba-platform.
the class DesktopLabel method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
this.datasource = datasource;
if (datasource == null) {
setValue(null);
return;
}
resolveMetaPropertyPath(datasource.getMetaClass(), property);
valueFormatter.setMetaProperty(metaProperty);
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(metaPropertyPath.toString())) {
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);
}
}
use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener in project cuba by cuba-platform.
the class WebAbstractField 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;
final MetaClass metaClass = datasource.getMetaClass();
resolveMetaPropertyPath(metaClass, property);
initFieldConverter();
itemWrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath));
component.setPropertyDataSource(itemWrapper.getItemProperty(metaPropertyPath));
initRequired(metaPropertyPath);
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();
}
}
use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener in project cuba by cuba-platform.
the class WebDateField 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();
}
timeZone = null;
disableBeanValidator();
}
if (datasource != null) {
// noinspection unchecked
this.datasource = datasource;
MetaClass metaClass = datasource.getMetaClass();
resolveMetaPropertyPath(metaClass, property);
if (metaProperty.getRange().isDatatype() && metaProperty.getRange().asDatatype().getJavaClass().equals(Date.class) && timeZone == null) {
MetadataTools metadataTools = AppBeans.get(MetadataTools.class);
Boolean ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(metaProperty, IgnoreUserTimeZone.class);
if (!Boolean.TRUE.equals(ignoreUserTimeZone)) {
timeZone = userSession.getTimeZone();
dateField.setTimeZone(timeZone);
}
}
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 (!isBuffered() && 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);
initDateFormat(metaProperty);
if (metaProperty.isReadOnly()) {
setEditable(false);
}
initBeanValidator();
setDateRangeByProperty(metaProperty);
}
}
Aggregations