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

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

Introduction

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

Prototype

public void setContainerDataSource(Container newDataSource, Collection<?> visibleIds) 

Source Link

Document

Sets the container data source and the columns that will be visible.

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.  jav a 2  s.  com
@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);
}