Ticket #1973: Ticket1973_2.java

File Ticket1973_2.java, 1.7 kB (added by Risto Yrjana, 4 months ago)
Line 
1package com.itmill.toolkit.ui;
2
3import com.itmill.toolkit.Application;
4import com.itmill.toolkit.data.Item;
5import com.itmill.toolkit.data.util.IndexedContainer;
6
7public class ToolkitTest extends Application {
8
9    Window main = new Window();
10    Table table = new Table();
11
12    public void init() {
13        setMainWindow(main);
14
15        final IndexedContainer container1 = new IndexedContainer();
16        container1.addContainerProperty("text", String.class, null);
17        container1.addContainerProperty("layout", Component.class, null);
18
19        final IndexedContainer container2 = new IndexedContainer();
20        container2.addContainerProperty("text", String.class, null);
21        container2.addContainerProperty("layout", Component.class, null);
22
23        fill(container1, 100);
24
25        table.setContainerDataSource(container1);
26
27        Button refreshTable = new Button("Change table container");
28        refreshTable.addListener(new Button.ClickListener() {
29            public void buttonClick(Button.ClickEvent e) {
30                for (int i = 0; i < 5; i++) {
31                    table.setContainerDataSource(container2);
32                    table.setContainerDataSource(container1);
33                }
34            }
35        });
36
37        main.addComponent(table);
38        main.addComponent(refreshTable);
39    }
40
41    public void fill(IndexedContainer container, int size) {
42        for (int i = 0; i < size; i++) {
43            int randInt = (int) (Math.random() * 100);
44            Item item = container.addItem(new Integer(i));
45            OrderedLayout layout = new OrderedLayout();
46            layout.addComponent(new Button("Test " + randInt));
47            item.getItemProperty("layout").setValue(layout);
48        }
49    }
50}