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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
package com.vaadin.tests.components.table;
import com.vaadin.data.Container;
import com.vaadin.data.Item;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.AbstractSelect.ItemDescriptionGenerator;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Component;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
public class TableItemDescriptionGeneratorTest extends TestBase {
private final String TEXT_PROPERTY_ID = "Text";
private final String GEN_WIDGET_PROPERTY_ID = "Generated component";
private final String WIDGET_PROPERTY_ID = "Component";
private CheckBox componentDescription;
private CheckBox tableCellItemDescription;
private CheckBox tableRowItemDescription;
@Override
protected void setup() {
final Table table = createTable();
table.setId("table");
componentDescription = new CheckBox("Tooltip on components");
componentDescription.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
table.setContainerDataSource(createContainer(componentDescription
.getValue()));
}
});
componentDescription.setImmediate(true);
componentDescription.setValue(true);
tableCellItemDescription = new CheckBox("Tooltip on table cells");
tableCellItemDescription
.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
table.refreshRowCache();
}
});
tableCellItemDescription.setImmediate(true);
tableCellItemDescription.setValue(true);
tableRowItemDescription = new CheckBox("Tooltip on table Rows");
tableRowItemDescription
.addValueChangeListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
table.refreshRowCache();
}
});
tableRowItemDescription.setImmediate(true);
tableRowItemDescription.setValue(true);
addComponent(componentDescription);
addComponent(tableCellItemDescription);
addComponent(tableRowItemDescription);
addComponent(table);
table.setItemDescriptionGenerator(new ItemDescriptionGenerator() {
@Override
public String generateDescription(Component source, Object itemId,
Object propertyId) {
if (propertyId == null && tableRowItemDescription.getValue()) {
return "Row description " + itemId;
} else if (tableCellItemDescription.getValue()) {
return "Cell description " + itemId + "," + propertyId;
}
return null;
}
});
table.addGeneratedColumn(GEN_WIDGET_PROPERTY_ID,
new Table.ColumnGenerator() {
@Override
public Component generateCell(Table source, Object itemId,
Object columnId) {
TextField lbl = new TextField();
if (componentDescription.getValue()) {
lbl.setDescription("Textfield's own description");
}
return lbl;
}
});
}
protected Table createTable() {
return new Table();
}
@Override
protected String getDescription() {
return "Cells and rows should have tooltips";
}
@Override
protected Integer getTicketNumber() {
return 5414;
}
private Container createContainer(boolean description) {
IndexedContainer container = new IndexedContainer();
container.addContainerProperty(TEXT_PROPERTY_ID, String.class, "");
container.addContainerProperty(WIDGET_PROPERTY_ID, Component.class,
null);
// container.addContainerProperty(COLUMN3_PROPERTY_ID, String.class,
// "");
for (int i = 0; i < 5; i++) {
Item item = container.addItem("item " + i);
item.getItemProperty(TEXT_PROPERTY_ID).setValue("Text " + i);
Button b = new Button("Button " + i);
if (description) {
b.setDescription("Button " + i + " description");
}
item.getItemProperty(WIDGET_PROPERTY_ID).setValue(b);
// item.getItemProperty(COLUMN3_PROPERTY_ID).setValue("last" + i);
}
return container;
}
}
|