blob: fe91040f2f748a1a5d159d64976cd41cd7d9d673 (
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
|
package com.vaadin.tests.tickets;
import java.util.Collection;
import java.util.HashSet;
import com.vaadin.LegacyApplication;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
public class Ticket3146 extends LegacyApplication {
Table table;
TextField result;
@Override
public void init() {
LegacyWindow mainWindow = new LegacyWindow("Test");
table = new Table();
table.addContainerProperty("Items", String.class, null);
table.addItem(new String[] { "a" }, "a");
table.addItem(new String[] { "b" }, "b");
table.addItem(new String[] { "c" }, "c");
for (int i = 1; i < 100; ++i) {
table.addItem(new String[] { "Item " + i }, "Item " + i);
}
table.setMultiSelect(true);
table.setSelectable(true);
table.setImmediate(true);
table.setHeight("200px");
table.setWidth("200px");
mainWindow.addComponent(table);
Button clearButton = new Button("Clear selection",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
clearSelection();
}
});
mainWindow.addComponent(clearButton);
Button clearButton2 = new Button("Clear selection 2",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
clearSelection2();
}
});
mainWindow.addComponent(clearButton2);
Button clearButton3 = new Button("Clear selection 3",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
clearSelection3();
}
});
mainWindow.addComponent(clearButton3);
Button printButton = new Button("Print selection",
new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
printSelection();
}
});
mainWindow.addComponent(printButton);
result = new TextField();
result.setHeight("200px");
result.setWidth("200px");
mainWindow.addComponent(result);
setMainWindow(mainWindow);
}
void clearSelection() {
table.setValue(null);
}
void clearSelection2() {
table.setValue(new HashSet<Object>());
}
void clearSelection3() {
table.unselect("a");
table.unselect("b");
table.unselect("c");
}
void printSelection() {
String selection = "";
for (Object item : (Collection<?>) table.getValue()) {
selection = selection + item + ' ';
}
result.setValue(selection);
}
}
|