]> source.dussan.org Git - vaadin-framework.git/blob
6b15367d6b424bbf8b1145c4af045fdf5dd09fcc
[vaadin-framework.git] /
1 package com.vaadin.tests.components.treetable;
2
3 import com.vaadin.server.VaadinRequest;
4 import com.vaadin.tests.components.AbstractTestUI;
5 import com.vaadin.v7.data.util.BeanItemContainer;
6 import com.vaadin.v7.data.util.ContainerHierarchicalWrapper;
7 import com.vaadin.v7.ui.Tree.ExpandEvent;
8 import com.vaadin.v7.ui.Tree.ExpandListener;
9 import com.vaadin.v7.ui.TreeTable;
10
11 @SuppressWarnings("serial")
12 public class TreeTableContainerHierarchicalWrapper extends AbstractTestUI {
13
14     TreeTable treetable = new TreeTable();
15     BeanItemContainer<Bean> beanContainer = new BeanItemContainer<Bean>(
16             Bean.class);
17     ContainerHierarchicalWrapper hierarchicalWrapper = new ContainerHierarchicalWrapper(
18             beanContainer);
19
20     @Override
21     protected void setup(VaadinRequest request) {
22         treetable = new TreeTable();
23         treetable.setImmediate(true);
24         treetable.setWidth("100%");
25         treetable.setHeight(null);
26         treetable.setPageLength(0);
27         treetable.setContainerDataSource(hierarchicalWrapper);
28
29         treetable.addExpandListener(new ExpandListener() {
30             @Override
31             public void nodeExpand(ExpandEvent event) {
32                 Bean parent = ((Bean) event.getItemId());
33                 if (!hierarchicalWrapper.hasChildren(parent)) {
34                     for (int i = 1; i <= 5; i++) {
35                         Bean newChild = new Bean(parent.getId() + "-" + i);
36                         beanContainer.addBean(newChild);
37                         hierarchicalWrapper.setParent(newChild, parent);
38                     }
39                 }
40
41             }
42         });
43
44         for (int i = 0; i < 3; i++) {
45             beanContainer.addBean(new Bean("Item " + i));
46         }
47
48         addComponent(treetable);
49     }
50
51     public class Bean {
52         public static final String PROP_ID = "id";
53         private String id;
54
55         public Bean() {
56             // empty
57         }
58
59         public Bean(String id) {
60             this.id = id;
61         }
62
63         public void setId(String id) {
64             this.id = id;
65         }
66
67         public String getId() {
68             return id;
69         }
70     }
71
72     @Override
73     protected String getTestDescription() {
74         return "Tests that TreeTable with ContainerHierarchicalWrapper is updated correctly when the setParent() is called for the item just added";
75     }
76
77     @Override
78     protected Integer getTicketNumber() {
79         return 15421;
80     }
81
82 }