Search in sources :

Example 1 with WeakItemChangeListener

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();
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener) Date(java.util.Date)

Example 2 with WeakItemChangeListener

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();
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)

Example 3 with WeakItemChangeListener

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);
    }
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)

Example 4 with WeakItemChangeListener

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();
    }
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) MetaClass(com.haulmont.chile.core.model.MetaClass)

Example 5 with WeakItemChangeListener

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);
    }
}
Also used : WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) MetaClass(com.haulmont.chile.core.model.MetaClass) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)

Aggregations

WeakItemChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemChangeListener)16 WeakItemPropertyChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)14 MetaClass (com.haulmont.chile.core.model.MetaClass)7 Property (com.vaadin.data.Property)3 Enumeration (com.haulmont.chile.core.datatypes.Enumeration)2 CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)2 Date (java.util.Date)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)1 MessageTools (com.haulmont.cuba.core.global.MessageTools)1 TextInputField (com.haulmont.cuba.gui.components.TextInputField)1 ItemWrapper (com.haulmont.cuba.web.gui.data.ItemWrapper)1 java.awt (java.awt)1