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.lang3.StringEscapeUtils;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42
43 import com.vaadin.ui.Component;
44 import com.vaadin.v7.data.Container;
45 import com.vaadin.v7.data.Property;
46 import com.vaadin.v7.data.Validator;
47 import com.vaadin.v7.data.util.HierarchicalContainer;
48 import com.vaadin.v7.shared.ui.treetable.TreeTableState;
49 import com.vaadin.v7.ui.TreeTable;
50
51
52
53
54 public class MagnoliaTreeTable extends TreeTable {
55
56 private static Logger log = LoggerFactory.getLogger(MagnoliaTreeTable.class);
57
58 public MagnoliaTreeTable(Container dataSource) {
59 super(null, dataSource);
60 addStyleName("v-magnolia-table");
61 setCacheRate(4);
62 }
63
64 public MagnoliaTreeTable() {
65 this(new HierarchicalContainer());
66 }
67
68
69
70
71
72
73 @Override
74 public int indexOfId(Object itemId) {
75 return super.indexOfId(itemId);
76 }
77
78 @Override
79 protected String formatPropertyValue(Object rowId, Object colId, Property<?> property) {
80 String result = super.formatPropertyValue(rowId, colId, property);
81 return StringEscapeUtils.escapeHtml4(result);
82 }
83
84 @Override
85 public void changeVariables(Object source, Map<String, Object> variables) {
86 super.changeVariables(source, variables);
87 if (variables.containsKey("selectAll")) {
88 boolean selectAll = (Boolean) variables.get("selectAll");
89 if (selectAll) {
90 Collection<?> ids = getItemIds();
91 for (final Object id : ids) {
92 select(id);
93 }
94 } else {
95 setValue(null);
96 }
97 }
98
99 if (variables.containsKey("toggleSelection")) {
100 boolean selected = (Boolean) variables.get("toggleSelection");
101 String key = String.valueOf(variables.get("toggledRowId"));
102 final Object id = itemIdMapper.get(key);
103 if (selected) {
104 select(id);
105 } else {
106 unselect(id);
107 }
108 }
109 }
110
111
112
113
114 @Override
115 public void registerComponent(Component component) {
116 super.registerComponent(component);
117 }
118
119
120
121
122
123 @Override
124 protected TreeTableState getState() {
125 return (TreeTableState) getState(false);
126 }
127
128
129
130
131 @Override
132 public Collection<Validator> getValidators() {
133 return null;
134 }
135
136
137
138
139 @Deprecated
140 public boolean isDescendantOf(final Object itemId, final Object parentId) {
141 Hierarchical container = getContainerDataSource();
142 Object id = itemId;
143 while (!container.isRoot(id)) {
144 id = container.getParent(id);
145 if (id.equals(parentId)) {
146 return true;
147 }
148 }
149 return false;
150 }
151 }