blob: 398b95a367e23e90edb50c0dd6480c7a30e135dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
package com.itmill.toolkit.tests.tickets;
import com.itmill.toolkit.Application;
import com.itmill.toolkit.data.Item;
import com.itmill.toolkit.data.Property.ValueChangeEvent;
import com.itmill.toolkit.data.Property.ValueChangeListener;
import com.itmill.toolkit.data.util.IndexedContainer;
import com.itmill.toolkit.data.util.ObjectProperty;
import com.itmill.toolkit.ui.Button;
import com.itmill.toolkit.ui.OrderedLayout;
import com.itmill.toolkit.ui.Table;
import com.itmill.toolkit.ui.Window;
import com.itmill.toolkit.ui.Button.ClickEvent;
import com.itmill.toolkit.ui.Button.ClickListener;
public class Ticket2242 extends Application implements ValueChangeListener {
private Object tableValue = null;
private Table t;
private String valueDataSource = "-";
private ObjectProperty prop;
@Override
public void init() {
Window w = new Window(getClass().getSimpleName());
setMainWindow(w);
// setTheme("tests-tickets");
createUI((OrderedLayout) w.getLayout());
}
private void createUI(OrderedLayout layout) {
Button b = new Button("Change container datasource",
new ClickListener() {
public void buttonClick(ClickEvent event) {
for (int i = 0; i < 5; i++) {
t.setContainerDataSource(createContainer());
// prop.setValue("ipsum");
}
}
});
layout.addComponent(b);
t = new Table("A table");
prop = new ObjectProperty(valueDataSource);
t.setPropertyDataSource(prop);
t.setSelectable(true);
t.setImmediate(true);
t.setPageLength(5);
t.setContainerDataSource(createContainer());
tableValue = t.getValue();
t.addListener(this);
layout.addComponent(t);
}
private IndexedContainer createContainer() {
IndexedContainer ic = new IndexedContainer();
ic.addContainerProperty("a", String.class, null);
for (String s : new String[] { "Lorem", "ipsum", "dolor", "sit",
"amet", "consectetuer" }) {
Item item = ic.addItem(s);
item.getItemProperty("a").setValue(s);
}
return ic;
}
private static class TestObject {
public TestObject(int a, String b, Long c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
private int a;
private String b;
private Long c;
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
public Long getC() {
return c;
}
public void setC(Long c) {
this.c = c;
}
}
public void valueChange(ValueChangeEvent event) {
System.out.println("Value change from " + tableValue + " to "
+ t.getValue());
tableValue = t.getValue();
}
}
|