Search in sources :

Example 11 with WeakItemChangeListener

use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener 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();
}
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) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 12 with WeakItemChangeListener

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

Example 13 with WeakItemChangeListener

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

Example 14 with WeakItemChangeListener

use of com.haulmont.cuba.gui.data.impl.WeakItemChangeListener 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);
    }
}
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) Date(java.util.Date)

Example 15 with WeakItemChangeListener

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