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.lang.reflect.Field;
37 import java.util.Collection;
38 import java.util.Map;
39
40 import org.apache.commons.lang.StringEscapeUtils;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 import com.vaadin.data.Container;
45 import com.vaadin.data.Property;
46 import com.vaadin.data.Validator;
47 import com.vaadin.shared.ui.treetable.TreeTableState;
48 import com.vaadin.ui.TreeTable;
49
50
51
52
53 public class MagnoliaTreeTable extends TreeTable {
54
55 private static Logger log = LoggerFactory.getLogger(MagnoliaTreeTable.class);
56
57 public MagnoliaTreeTable() {
58 addStyleName("v-magnolia-table");
59 setCacheRate(4);
60 }
61
62 @Override
63 protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
64 String result = super.formatPropertyValue(rowId, colId, property);
65 return StringEscapeUtils.escapeHtml(result);
66 }
67
68 @Override
69 public void changeVariables(Object source, Map<String, Object> variables) {
70 super.changeVariables(source, variables);
71 if (variables.containsKey("selectAll")) {
72 boolean selectAll = (Boolean) variables.get("selectAll");
73 if (selectAll) {
74 Collection<?> ids = getItemIds();
75 for (final Object id : ids) {
76 select(id);
77 }
78 } else {
79 setValue(null);
80 }
81 }
82
83 if (variables.containsKey("toggleSelection")) {
84 boolean selected = (Boolean) variables.get("toggleSelection");
85 String key = String.valueOf(variables.get("toggledRowId"));
86 final Object id = itemIdMapper.get(key);
87 if (selected) {
88 select(id);
89 } else {
90 unselect(id);
91 }
92 }
93 }
94
95
96
97
98
99 @Override
100 protected TreeTableState getState() {
101 return (TreeTableState) getState(false);
102 }
103
104
105
106
107 @Override
108 public Collection<Validator> getValidators() {
109 return null;
110 }
111
112 @Override
113 public void setContainerDataSource(Container newDataSource) {
114 super.setContainerDataSource(newDataSource);
115
116
117 try {
118 Field f = TreeTable.class.getDeclaredField("containerSupportsPartialUpdates");
119 f.setAccessible(true);
120 f.setBoolean(this, true);
121 } catch (Exception e) {
122 log.warn("Could not enable partial-updates in tree.", e);
123 }
124 }
125 }