Example usage for com.vaadin.v7.data Container containsId

List of usage examples for com.vaadin.v7.data Container containsId

Introduction

In this page you can find the example usage for com.vaadin.v7.data Container containsId.

Prototype

public boolean containsId(Object itemId);

Source Link

Document

Tests if the Container contains the specified Item.

Usage

From source file:com.haulmont.cuba.web.widgets.CubaComboBox.java

License:Apache License

@Override
public void setContainerDataSource(Container newDataSource) {
    // CAUTION - copied from super method

    Object oldValue = getValue();

    if (newDataSource == null) {
        newDataSource = new IndexedContainer();
    }// w w w  .ja  va  2s. co  m

    getCaptionChangeListener().clear();

    if (items != newDataSource) {

        // Removes listeners from the old datasource
        if (items != null) {
            if (items instanceof Container.ItemSetChangeNotifier) {
                ((Container.ItemSetChangeNotifier) items).removeItemSetChangeListener(this);
            }
            if (items instanceof Container.PropertySetChangeNotifier) {
                ((Container.PropertySetChangeNotifier) items).removePropertySetChangeListener(this);
            }
        }

        // Assigns new data source
        items = newDataSource;

        // Clears itemIdMapper also
        itemIdMapper.removeAll();

        // Adds listeners
        if (items != null) {
            if (items instanceof Container.ItemSetChangeNotifier) {
                ((Container.ItemSetChangeNotifier) items).addItemSetChangeListener(this);
            }
            if (items instanceof Container.PropertySetChangeNotifier) {
                ((Container.PropertySetChangeNotifier) items).addPropertySetChangeListener(this);
            }
        }

        /*
         * We expect changing the data source should also clean value. See
         * #810, #4607, #5281
         */
        // Haulmont API
        // #PL-3098
        if (!newDataSource.containsId(oldValue))
            setValue(null);

        markAsDirty();
    }
}