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 package info.magnolia.ui.vaadin.grid;
35
36 import java.util.Collection;
37 import java.util.Map;
38
39 import org.apache.commons.lang.StringEscapeUtils;
40
41 import com.vaadin.data.Property;
42 import com.vaadin.ui.Table;
43
44
45
46
47 public class MagnoliaTable extends Table {
48
49 public MagnoliaTable() {
50 addStyleName("v-magnolia-table");
51 }
52
53 @Override
54 protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
55 String result = super.formatPropertyValue(rowId, colId, property);
56 return StringEscapeUtils.escapeHtml(result);
57 }
58
59 @Override
60 public void changeVariables(Object source, Map<String, Object> variables) {
61 super.changeVariables(source, variables);
62 if (variables.containsKey("selectAll")) {
63 boolean selectAll = (Boolean) variables.get("selectAll");
64 if (selectAll) {
65 Collection<?> ids = getItemIds();
66 for (final Object id : ids) {
67 select(id);
68 }
69 } else {
70 setValue(null);
71 }
72 }
73
74 if (variables.containsKey("toggleSelection")) {
75 boolean selected = (Boolean) variables.get("toggleSelection");
76 String key = String.valueOf(variables.get("toggledRowId"));
77 final Object id = itemIdMapper.get(key);
78 if (selected) {
79 select(id);
80 } else {
81 unselect(id);
82 }
83 }
84 }
85 }