blob: 7b544ec9b0c447d30a3b83a8639ba2f42fe6d51b (
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
package com.vaadin.tests.tickets;
import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.server.Sizeable;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Layout;
import com.vaadin.ui.UI.LegacyWindow;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
/**
* Test class for ticket 1983
*/
public class Ticket1983 extends Application.LegacyApplication {
@Override
public void init() {
LegacyWindow main = new LegacyWindow("Test for ticket 1983");
main.setContent(new TestLayout());
setMainWindow(main);
}
private static class TestLayout extends HorizontalSplitPanel {
boolean isLong = true;
final Table table = new MyTable();
final String propId = "col";
final String propId2 = "col2";
public TestLayout() {
setSplitPosition(200, Sizeable.UNITS_PIXELS);
setLocked(true);
final HorizontalSplitPanel leftSide = initLeftSide();
setFirstComponent(leftSide);
final Layout rightSide = new VerticalLayout();
rightSide.setHeight("100%");
setSecondComponent(rightSide);
}
private HorizontalSplitPanel initLeftSide() {
final HorizontalSplitPanel leftSide = new HorizontalSplitPanel();
leftSide.setHeight("100%");
final IndexedContainer dataSource = new IndexedContainer();
dataSource.addContainerProperty(propId, String.class, null);
dataSource.addContainerProperty(propId2, String.class, null);
final Object itemId = dataSource.addItem();
dataSource
.getItem(itemId)
.getItemProperty(propId)
.setValue(
"Very long value that makes a scrollbar appear for sure");
dataSource
.getItem(itemId)
.getItemProperty(propId2)
.setValue(
"Very long value that makes a scrollbar appear for sure");
for (int i = 0; i < 150; i++) {
Object id = dataSource.addItem();
dataSource
.getItem(id)
.getItemProperty(propId)
.setValue(
(i == 100 ? "Very long value that makes a scrollbar appear for sure"
: "Short"));
dataSource.getItem(id).getItemProperty(propId2)
.setValue("Short");
}
table.setSizeFull();
table.setContainerDataSource(dataSource);
table.setVisibleColumns(new Object[] { propId });
leftSide.setSecondComponent(table);
Button button = new Button("Change col value to short");
button.addListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent event) {
// Change the column value to a short one --> Should remove
// the scrollbar
if (isLong) {
dataSource.getItem(itemId).getItemProperty(propId)
.setValue("Short value");
dataSource.getItem(itemId).getItemProperty(propId2)
.setValue("Short value");
isLong = false;
} else {
dataSource
.getItem(itemId)
.getItemProperty(propId)
.setValue(
"Very long value that makes a scrollbar appear for sure");
dataSource
.getItem(itemId)
.getItemProperty(propId2)
.setValue(
"Very long value that makes a scrollbar appear for sure");
isLong = true;
}
// Works the same way with or without repaint request
table.markAsDirty();
}
});
VerticalLayout ol = new VerticalLayout();
ol.addComponent(button);
leftSide.setFirstComponent(ol);
CheckBox checkBox = new CheckBox("Two col");
checkBox.addListener(new ValueChangeListener() {
@Override
public void valueChange(ValueChangeEvent event) {
if ((Boolean) event.getProperty().getValue()) {
table.setVisibleColumns(new Object[] { propId, propId2 });
} else {
table.setVisibleColumns(new Object[] { propId });
}
}
});
ol.addComponent(checkBox);
return leftSide;
}
}
static class MyTable extends Table {
MyTable() {
alwaysRecalculateColumnWidths = true;
}
}
}
|