| 1 | package com.itmill.toolkit.ui; |
|---|
| 2 | |
|---|
| 3 | import com.itmill.toolkit.Application; |
|---|
| 4 | import com.itmill.toolkit.data.Item; |
|---|
| 5 | import com.itmill.toolkit.data.util.IndexedContainer; |
|---|
| 6 | |
|---|
| 7 | public 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 | } |
|---|