blob: 5ea354ea2b7d0200d895438a26b7374a3d1f7dad (
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
117
118
119
120
121
|
package com.vaadin.tests.components.grid;
import java.util.ArrayList;
import java.util.List;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.renderers.NumberRenderer;
public class GridDetailsDetach extends AbstractTestUI {
private Grid currentGrid;
@Override
protected void setup(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setSpacing(false);
layout.setMargin(false);
layout.setSizeFull();
Button button = new Button("Test");
layout.addComponent(button);
layout.setExpandRatio(button, 0f);
currentGrid = generateGrid();
final VerticalLayout gridContainer = new VerticalLayout();
gridContainer.setSpacing(false);
gridContainer.setMargin(false);
gridContainer.addComponent(currentGrid);
button.addClickListener(event -> gridContainer
.replaceComponent(currentGrid, new Label("Foo")));
layout.addComponent(new Button("Reattach Grid", event -> {
gridContainer.removeAllComponents();
gridContainer.addComponent(currentGrid);
}));
layout.addComponent(gridContainer);
layout.setExpandRatio(gridContainer, 1f);
addComponent(layout);
}
private Grid<GridExampleBean> generateGrid() {
List<GridExampleBean> items = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
items.add(new GridExampleBean("Bean " + i, i * i, i / 10d));
}
final Grid<GridExampleBean> grid = new Grid<>();
grid.setItems(items);
grid.addColumn(GridExampleBean::getName);
grid.addColumn(GridExampleBean::getAmount, new NumberRenderer());
grid.addColumn(GridExampleBean::getCount, new NumberRenderer());
grid.setSizeFull();
grid.setSelectionMode(SelectionMode.NONE);
grid.setDetailsGenerator(item -> {
VerticalLayout layout = new VerticalLayout(
new Label("Extra data for " + item.getName()));
layout.setMargin(true);
return layout;
});
grid.addItemClickListener(event -> {
GridExampleBean item = event.getItem();
grid.setDetailsVisible(item, !grid.isDetailsVisible(item));
});
return grid;
}
public class GridExampleBean {
private String name;
private int count;
private double amount;
public GridExampleBean() {
}
public GridExampleBean(String name, int count, double amount) {
this.name = name;
this.count = count;
this.amount = amount;
}
public String getName() {
return name;
}
public int getCount() {
return count;
}
public double getAmount() {
return amount;
}
public void setName(String name) {
this.name = name;
}
public void setCount(int count) {
this.count = count;
}
public void setAmount(double amount) {
this.amount = amount;
}
}
}
|