-
Notifications
You must be signed in to change notification settings - Fork 730
/
Tables.java
376 lines (334 loc) · 14.5 KB
/
Tables.java
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package com.vaadin.tests.themes.valo;
import com.vaadin.data.HasValue;
import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll;
import com.vaadin.event.dd.acceptcriteria.AcceptCriterion;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.tests.components.TestDateField;
import com.vaadin.ui.AbstractDateField;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.ProgressBar;
import com.vaadin.ui.Slider;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.themes.ValoTheme;
import com.vaadin.v7.data.Container;
import com.vaadin.v7.ui.ComboBox;
import com.vaadin.v7.ui.OptionGroup;
import com.vaadin.v7.ui.Table;
import com.vaadin.v7.ui.Table.Align;
import com.vaadin.v7.ui.Table.ColumnGenerator;
import com.vaadin.v7.ui.Table.RowHeaderMode;
import com.vaadin.v7.ui.Table.TableDragMode;
import com.vaadin.v7.ui.TextField;
import com.vaadin.v7.ui.TreeTable;
public class Tables extends VerticalLayout implements View {
final Container normalContainer = ValoThemeUI.generateContainer(200, false);
final Container hierarchicalContainer = ValoThemeUI.generateContainer(200,
true);
CheckBox hierarchical = new CheckBox("Hierarchical");
CheckBox footer = new CheckBox("Footer", true);
CheckBox sized = new CheckBox("Sized");
CheckBox expandRatios = new CheckBox("Expand ratios");
CheckBox stripes = new CheckBox("Stripes", true);
CheckBox verticalLines = new CheckBox("Vertical lines", true);
CheckBox horizontalLines = new CheckBox("Horizontal lines", true);
CheckBox borderless = new CheckBox("Borderless");
CheckBox headers = new CheckBox("Header", true);
CheckBox compact = new CheckBox("Compact");
CheckBox small = new CheckBox("Small");
CheckBox rowIndex = new CheckBox("Row index", false);
CheckBox rowIcon = new CheckBox("Row icon", false);
CheckBox rowCaption = new CheckBox("Row caption", false);
CheckBox componentsInCells = new CheckBox("Components in Cells", false);
Table table;
public Tables() {
setMargin(true);
setSpacing(true);
Label h1 = new Label("Tables");
h1.addStyleName(ValoTheme.LABEL_H1);
addComponent(h1);
HorizontalLayout wrap = new HorizontalLayout();
wrap.addStyleName(ValoTheme.LAYOUT_HORIZONTAL_WRAPPING);
wrap.setSpacing(true);
addComponent(wrap);
wrap.addComponents(hierarchical, footer, sized, expandRatios, stripes,
verticalLines, horizontalLines, borderless, headers, compact,
small, rowIndex, rowCaption, rowIcon, componentsInCells);
HasValue.ValueChangeListener<Boolean> update = event -> {
if (table == null) {
table = new Table();
table.setContainerDataSource(normalContainer);
addComponent(table);
}
if (hierarchical.getValue() && table instanceof Table) {
removeComponent(table);
table = new TreeTable();
table.setContainerDataSource(hierarchicalContainer);
addComponent(table);
} else if (!hierarchical.getValue() && table instanceof TreeTable) {
removeComponent(table);
table = new Table();
table.setContainerDataSource(normalContainer);
addComponent(table);
}
configure(table, footer.getValue(), sized.getValue(),
expandRatios.getValue(), stripes.getValue(),
verticalLines.getValue(), horizontalLines.getValue(),
borderless.getValue(), headers.getValue(),
compact.getValue(), small.getValue(), rowIndex.getValue(),
rowCaption.getValue(), rowIcon.getValue(),
componentsInCells.getValue());
};
hierarchical.addValueChangeListener(update);
footer.addValueChangeListener(update);
sized.addValueChangeListener(update);
expandRatios.addValueChangeListener(update);
stripes.addValueChangeListener(update);
verticalLines.addValueChangeListener(update);
horizontalLines.addValueChangeListener(update);
borderless.addValueChangeListener(update);
headers.addValueChangeListener(update);
compact.addValueChangeListener(update);
small.addValueChangeListener(update);
rowIndex.addValueChangeListener(update);
rowCaption.addValueChangeListener(update);
rowIcon.addValueChangeListener(update);
componentsInCells.addValueChangeListener(update);
footer.setValue(false);
}
static void configure(Table table, boolean footer, boolean sized,
boolean expandRatios, boolean stripes, boolean verticalLines,
boolean horizontalLines, boolean borderless, boolean headers,
boolean compact, boolean small, boolean rowIndex,
boolean rowCaption, boolean rowIcon, boolean componentsInRows) {
table.setSelectable(true);
table.setMultiSelect(true);
table.setSortEnabled(true);
table.setColumnCollapsingAllowed(true);
table.setColumnReorderingAllowed(true);
table.setPageLength(6);
table.addActionHandler(ValoThemeUI.getActionHandler());
table.setDragMode(TableDragMode.MULTIROW);
table.setDropHandler(new DropHandler() {
@Override
public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get();
}
@Override
public void drop(DragAndDropEvent event) {
Notification.show(event.getTransferable().toString());
}
});
table.setColumnAlignment(ValoThemeUI.DESCRIPTION_PROPERTY, Align.RIGHT);
table.setColumnAlignment(ValoThemeUI.INDEX_PROPERTY, Align.CENTER);
table.removeContainerProperty("textfield");
table.removeGeneratedColumn("textfield");
table.removeContainerProperty("button");
table.removeGeneratedColumn("button");
table.removeContainerProperty("label");
table.removeGeneratedColumn("label");
table.removeContainerProperty("checkbox");
table.removeGeneratedColumn("checkbox");
table.removeContainerProperty("datefield");
table.removeGeneratedColumn("datefield");
table.removeContainerProperty("combobox");
table.removeGeneratedColumn("combobox");
table.removeContainerProperty("optiongroup");
table.removeGeneratedColumn("optiongroup");
table.removeContainerProperty("slider");
table.removeGeneratedColumn("slider");
table.removeContainerProperty("progress");
table.removeGeneratedColumn("progress");
if (componentsInRows) {
table.addContainerProperty("textfield", TextField.class, null);
table.addGeneratedColumn("textfield", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
TextField tf = new TextField();
tf.setInputPrompt("Type here…");
// tf.addStyleName(ValoTheme.TABLE_COMPACT);
if ((Integer) itemId % 2 == 0) {
tf.addStyleName(ValoTheme.TABLE_BORDERLESS);
}
return tf;
}
});
table.addContainerProperty("datefield", TextField.class, null);
table.addGeneratedColumn("datefield", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
AbstractDateField<?, ?> tf = new TestDateField();
tf.addStyleName(ValoTheme.TABLE_COMPACT);
if ((Integer) itemId % 2 == 0) {
tf.addStyleName(ValoTheme.DATEFIELD_BORDERLESS);
}
return tf;
}
});
table.addContainerProperty("combobox", TextField.class, null);
table.addGeneratedColumn("combobox", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
ComboBox tf = new ComboBox();
tf.setInputPrompt("Select");
tf.addStyleName(ValoTheme.TABLE_COMPACT);
if ((Integer) itemId % 2 == 0) {
tf.addStyleName(ValoTheme.DATEFIELD_BORDERLESS);
}
return tf;
}
});
table.addContainerProperty("button", Button.class, null);
table.addGeneratedColumn("button", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
Button b = new Button("Button");
b.addStyleName(ValoTheme.BUTTON_SMALL);
return b;
}
});
table.addContainerProperty("label", TextField.class, null);
table.addGeneratedColumn("label", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
Label label = new Label("Label component");
label.setSizeUndefined();
label.addStyleName(ValoTheme.LABEL_BOLD);
return label;
}
});
table.addContainerProperty("checkbox", TextField.class, null);
table.addGeneratedColumn("checkbox", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
CheckBox cb = new CheckBox(null, true);
return cb;
}
});
table.addContainerProperty("optiongroup", TextField.class, null);
table.addGeneratedColumn("optiongroup", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
OptionGroup op = new OptionGroup();
op.addItem("Male");
op.addItem("Female");
op.addStyleName(ValoTheme.OPTIONGROUP_HORIZONTAL);
return op;
}
});
table.addContainerProperty("slider", TextField.class, null);
table.addGeneratedColumn("slider", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
Slider s = new Slider();
s.setValue(30.0);
return s;
}
});
table.addContainerProperty("progress", TextField.class, null);
table.addGeneratedColumn("progress", new ColumnGenerator() {
@Override
public Object generateCell(Table source, Object itemId,
Object columnId) {
ProgressBar bar = new ProgressBar();
bar.setValue(0.7f);
return bar;
}
});
}
table.setFooterVisible(footer);
if (footer) {
table.setColumnFooter(ValoThemeUI.CAPTION_PROPERTY, "caption");
table.setColumnFooter(ValoThemeUI.DESCRIPTION_PROPERTY,
"description");
table.setColumnFooter(ValoThemeUI.ICON_PROPERTY, "icon");
table.setColumnFooter(ValoThemeUI.INDEX_PROPERTY, "index");
}
if (sized) {
table.setWidth("400px");
table.setHeight("300px");
} else {
table.setSizeUndefined();
}
if (expandRatios) {
if (!sized) {
table.setWidth("100%");
}
}
table.setColumnExpandRatio(ValoThemeUI.CAPTION_PROPERTY,
expandRatios ? 1.0f : 0);
table.setColumnExpandRatio(ValoThemeUI.DESCRIPTION_PROPERTY,
expandRatios ? 1.0f : 0);
if (!stripes) {
table.addStyleName(ValoTheme.TABLE_NO_STRIPES);
} else {
table.removeStyleName(ValoTheme.TABLE_NO_STRIPES);
}
if (!verticalLines) {
table.addStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
} else {
table.removeStyleName(ValoTheme.TABLE_NO_VERTICAL_LINES);
}
if (!horizontalLines) {
table.addStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
} else {
table.removeStyleName(ValoTheme.TABLE_NO_HORIZONTAL_LINES);
}
if (borderless) {
table.addStyleName(ValoTheme.TABLE_BORDERLESS);
} else {
table.removeStyleName(ValoTheme.TABLE_BORDERLESS);
}
if (!headers) {
table.addStyleName(ValoTheme.TABLE_NO_HEADER);
} else {
table.removeStyleName(ValoTheme.TABLE_NO_HEADER);
}
if (compact) {
table.addStyleName(ValoTheme.TABLE_COMPACT);
} else {
table.removeStyleName(ValoTheme.TABLE_COMPACT);
}
if (small) {
table.addStyleName(ValoTheme.TABLE_SMALL);
} else {
table.removeStyleName(ValoTheme.TABLE_SMALL);
}
if (!rowIndex && !rowCaption && rowIcon) {
table.setRowHeaderMode(RowHeaderMode.HIDDEN);
}
if (rowIndex) {
table.setRowHeaderMode(RowHeaderMode.INDEX);
}
if (rowCaption) {
table.setRowHeaderMode(RowHeaderMode.PROPERTY);
table.setItemCaptionPropertyId(ValoThemeUI.CAPTION_PROPERTY);
} else {
table.setItemCaptionPropertyId(null);
}
if (rowIcon) {
table.setRowHeaderMode(RowHeaderMode.ICON_ONLY);
table.setItemIconPropertyId(ValoThemeUI.ICON_PROPERTY);
} else {
table.setItemIconPropertyId(null);
}
}
@Override
public void enter(ViewChangeEvent event) {
// TODO Auto-generated method stub
}
}