]> source.dussan.org Git - vaadin-framework.git/blob
1d962edafeb696152ec04f38409d76c3b79c1dd8
[vaadin-framework.git] /
1 package com.vaadin.tests.components.table;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import com.vaadin.server.VaadinRequest;
7 import com.vaadin.tests.components.AbstractTestUI;
8 import com.vaadin.ui.Button;
9 import com.vaadin.ui.VerticalLayout;
10 import com.vaadin.v7.data.util.BeanItemContainer;
11 import com.vaadin.v7.ui.Table;
12
13 public class ColumnWidthsAfterChangeTableColumnsCountOrOrder
14         extends AbstractTestUI {
15
16     protected static final String BUTTON_CHANGE_ORDER_AND_WIDTH_ID = "buttonChangeOrderAndWidth";
17     protected static final String BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH = "buttonChangeColumnCountAndWidth";
18     protected static final int NEW_COLUMN_WIDTH = 17;
19
20     @Override
21     protected void setup(VaadinRequest request) {
22         List<TestBean> beanList = new ArrayList<TestBean>();
23         beanList.add(new TestBean(1, "name1", "descr1"));
24         beanList.add(new TestBean(2, "name2", "descr2"));
25         beanList.add(new TestBean(3, "name3", "descr3"));
26         beanList.add(new TestBean(4, "name4", "descr4"));
27         beanList.add(new TestBean(5, "name5", "descr5"));
28
29         BeanItemContainer<TestBean> container = new BeanItemContainer<TestBean>(
30                 TestBean.class, beanList);
31
32         VerticalLayout layout = new VerticalLayout();
33
34         final Table table = new Table("Test Table");
35         table.setContainerDataSource(container);
36         table.setVisibleColumns(new Object[] { "id", "name", "descr" });
37         layout.addComponent(table);
38
39         Button buttonChangeOrderAndWidth = new Button("Change order and width",
40                 new Button.ClickListener() {
41                     @Override
42                     public void buttonClick(Button.ClickEvent clickEvent) {
43                         table.setVisibleColumns(
44                                 new Object[] { "name", "descr", "id" });
45                         table.setColumnWidth("descr", NEW_COLUMN_WIDTH);
46                     }
47                 });
48         buttonChangeOrderAndWidth.setId(BUTTON_CHANGE_ORDER_AND_WIDTH_ID);
49
50         Button buttonChangeColumnCountAndWidth = new Button(
51                 "Change columns count and width", new Button.ClickListener() {
52                     @Override
53                     public void buttonClick(Button.ClickEvent clickEvent) {
54                         table.setVisibleColumns(
55                                 new Object[] { "name", "descr" });
56                         table.setColumnWidth("descr", NEW_COLUMN_WIDTH);
57                     }
58                 });
59         buttonChangeColumnCountAndWidth
60                 .setId(BUTTON_CHANGE_COLUMN_COUNT_AND_WIDTH);
61
62         layout.addComponent(buttonChangeOrderAndWidth);
63         layout.addComponent(buttonChangeColumnCountAndWidth);
64
65         addComponents(layout);
66     }
67
68     public class TestBean {
69         private int id;
70         private String name;
71         private String descr;
72
73         public TestBean(int id, String name, String descr) {
74             this.id = id;
75             this.name = name;
76             this.descr = descr;
77         }
78
79         public int getId() {
80             return id;
81         }
82
83         public void setId(int id) {
84             this.id = id;
85         }
86
87         public String getName() {
88             return name;
89         }
90
91         public void setName(String name) {
92             this.name = name;
93         }
94
95         public String getDescr() {
96             return descr;
97         }
98
99         public void setDescr(String descr) {
100             this.descr = descr;
101         }
102
103         @Override
104         public String toString() {
105             return "TestBean{" + "id=" + id + ", name='" + name + '\''
106                     + ", descr='" + descr + '\'' + '}';
107         }
108     }
109
110     @Override
111     protected String getTestDescription() {
112         return "Tests that properties of columns are changed correctly after changing column's order/count";
113     }
114
115     @Override
116     protected Integer getTicketNumber() {
117         return 9781;
118     }
119
120 }