Example usage for com.vaadin.v7.ui Table getContainerDataSource

List of usage examples for com.vaadin.v7.ui Table getContainerDataSource

Introduction

In this page you can find the example usage for com.vaadin.v7.ui Table getContainerDataSource.

Prototype

@Override
public Container getContainerDataSource() 

Source Link

Document

Gets the viewing data-source container.

Usage

From source file:de.symeda.sormas.ui.caze.AbstractTableField.java

License:Open Source License

/**
 * Property serves as a source for the items in the table.
 * A copy is created of all entries in the edit, so that the source data is not overwritten until the commit.
 *//*from w ww  . j a va2s .  co m*/
@SuppressWarnings("unchecked")
@Override
public void setPropertyDataSource(Property newDataSource) {

    if (newDataSource == dataSource || (newDataSource != null && newDataSource.equals(dataSource))) {
        return;
    }

    dataSource = newDataSource;

    Collection<E> entries = dataSource.getValue();
    if (entries == null) {
        throw new IllegalArgumentException("dataSource cannot be null");
    }

    Collection<E> clonedEntries;
    if (entries instanceof List) {
        clonedEntries = new ArrayList<>(entries.size());
    } else if (entries instanceof Set) {
        clonedEntries = new HashSet<>(entries.size());
    } else {
        throw new IllegalArgumentException("dataSource value must be List or Set: " + entries.getClass());
    }

    // Make a copy of all entries so that they can be freely edited
    // important: all fields must be placed on writeThrough!
    for (E entry : entries) {
        clonedEntries.add(cloneEntry(entry));
    }

    container = new BeanItemContainer<>(getEntryType(), clonedEntries);

    getContent();
    Table tbl = getTable();
    if (tbl.getContainerDataSource() != null) {
        // keep the visible Columns
        Object[] visibleColumns = tbl.getVisibleColumns();
        tbl.setContainerDataSource(container, Arrays.asList(visibleColumns));
    } else {
        tbl.setContainerDataSource(container);
    }
    applyTablePageLength();

    updateColumns();

    fireValueChange(false);

    // not set, we manage our own dataSource
    // super.setPropertyDataSource (newDataSource);
}