ArrayContainer wrapper

I’ve been thinking of publishing this simple, yet often useful wrapper for a while. And damn, Sami made
an almost identical wrapper
today as well… :huh:

Anyhow, here’s my version. You can use it easily, for example:

    // An array
    Integer[] numbers = {4, 8, 15, 16, 23, 42};
    
    // The wrapper
    ArrayContainer<Integer> numberCtn = new ArrayContainer<Integer> (numbers);

    // The column property ID is used by Table as the default for
    // column header. It is by default "0".
    numberCtn.setColumnPropertyId("Number");

    // Use the wrapper as the data source for the table
    Table numbersTbl = new Table("Integers", numberCtn);
    mainWindow.addComponent(numbersTbl);

See the

11230.jar (6.94 KB)

I added a
LazyContainer
class suggested by Sami. It allows fully dynamic generation of container data from a callback interface. It’s also a much easier alternative to
Table.ColumnGenerator
for calculating the values of one column from another.

// 100,000 rows and 2 columns
LazyContainer lazydata = new LazyContainer(100000, 2, new LazyContainer.Provider() {
    public Object getData(int row, int column) {
        if (column == 0)
            return row;
        else if (column == 1)
            return ((double)row)*((double)row);
        else
            return null;
    }
});
	
Table table = new Table("Data from a Lazy Container", lazydata);
table.setColumnHeaders(new String[] {"Index", "Power of Index"});
	
mainWindow.addComponent(table);

Notice that a Table is unable to hold more than about 500,000 items. The exact limit depends on the font size, because the table content is rendered as a very tall HTML layer.

For more details, see the:

[list]

[]

Project home page

[
]

Online Demo

[*]

API Documentation

[/list]The
LazyContainer
is included in the new [tt]
arraycontainer-0.1.1.jar
[/tt].

Created
http://dev.vaadin.com/ticket/4220
for the above mentioned 500.000 rows limitation.