blob: 5749912f434760024f76780cefcf25e007bdfadb (
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
package com.vaadin.tests.components.table;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.server.VaadinRequest;
import com.vaadin.shared.ui.MarginInfo;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.Table.CacheUpdateException;
public class SetDataSourceWithPropertyIds extends AbstractTestUI {
@Override
protected String getTestDescription() {
return "It should be possible to set a dataSource without generating columns that were never intended to be visible.<br>"
+ "First initialization happens before the table is attached.";
}
@Override
protected Integer getTicketNumber() {
return 10419;
}
private static final String TABLE_NAME = "JOBS";
private static final String[] PK_COLUMN_NAMES = new String[] { "JOB_ID" };
private static final String SEQUENCE_NAME = "";
private static final String VERSION_COLUMN_NAME = "";
Table table = new Table();
BeanItemContainer<JobsBean> jobContainer = new BeanItemContainer(
JobsBean.class);
Label label = new Label();
@Override
protected void setup(VaadinRequest request) {
getLayout().setSpacing(true);
getLayout().setMargin(new MarginInfo(true, false, false, false));
Button button = new Button("Toggle editability");
button.setId("button");
button.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(Button.ClickEvent clickEvent) {
refreshTable();
}
});
label.setSizeUndefined();
label.setId("label");
table.setId("table");
refreshTable();
addComponent(button);
addComponent(label);
addComponent(table);
}
private void refreshTable() {
// error only occurs when table is editable and already attached
table.setEditable(table.getParent() == null || !table.isEditable());
jobContainer.removeAllItems();
jobContainer.addAll(getBeanList());
try {
table.setContainerDataSource(jobContainer);
table.setVisibleColumns(new String[] { "jobId" });
label.setValue("no Exception");
} catch (CacheUpdateException e) {
ArrayList<String> propertyIds = new ArrayList<String>();
propertyIds.add("jobId");
table.setContainerDataSource(jobContainer, propertyIds);
label.setValue("Exception caught");
}
}
private List<JobsBean> getBeanList() {
List<JobsBean> list = new ArrayList<JobsBean>();
JobsBean jobsBean = new JobsBean();
jobsBean.setJobId("1");
list.add(jobsBean);
return list;
}
public class JobsBean<T> implements Serializable {
private static final long serialVersionUID = 1932918476339138393L;
protected String jobId;
protected String jobTitle;
protected Long minSalary;
protected Long maxSalary;
private T auxiliaryData;
public T getAuxiliaryData() {
return auxiliaryData;
}
public void setAuxiliaryData(final T pAuxiliaryData) {
auxiliaryData = pAuxiliaryData;
}
public String getTableName() {
return TABLE_NAME;
}
public String[] getPrimaryKeyColumnNames() {
return PK_COLUMN_NAMES;
}
public String getSequenceName() {
return SEQUENCE_NAME;
}
public String getVersionColumnName() {
return VERSION_COLUMN_NAME;
}
public String getJobId() {
return jobId;
}
public void setJobId(final String pJobId) {
jobId = pJobId;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(final String pJobTitle) {
jobTitle = pJobTitle;
}
public Long getMinSalary() {
return minSalary;
}
public void setMinSalary(final Long pMinSalary) {
minSalary = pMinSalary;
}
public Long getMaxSalary() {
return maxSalary;
}
public void setMaxSalary(final Long pMaxSalary) {
maxSalary = pMaxSalary;
}
@Override
public boolean equals(Object pObject) {
if (this == pObject) {
return true;
}
if (!(pObject instanceof JobsBean)) {
return false;
}
JobsBean other = (JobsBean) pObject;
return getJobId().equals(other.getJobId());
}
@Override
public int hashCode() {
return getJobId().hashCode();
}
}
}
|