1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.common.ui.client.configurable.mvc.binding;
17
18 import java.util.Iterator;
19 import java.util.List;
20
21 import org.kuali.student.common.assembly.data.Data;
22 import org.kuali.student.common.assembly.data.Metadata;
23 import org.kuali.student.common.assembly.data.QueryPath;
24 import org.kuali.student.common.assembly.data.Data.DataType;
25 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityFieldConfiguration;
26 import org.kuali.student.common.ui.client.configurable.mvc.multiplicity.MultiplicityTable;
27 import org.kuali.student.common.ui.client.mvc.DataModel;
28
29 import com.google.gwt.core.client.GWT;
30
31
32
33
34 public class MultiplicityTableBinding extends ModelWidgetBindingSupport<MultiplicityTable> {
35
36
37
38
39
40
41 public void setModelValue(MultiplicityTable table, DataModel model, String path) {
42
43 GWT.log("Method setModelValue not implemented for MultiplicityTable");
44 }
45
46
47
48
49
50
51 public void setWidgetValue(MultiplicityTable table, DataModel model, String path) {
52 table.initTable();
53
54 path = path.trim();
55 if (path.startsWith(QueryPath.getPathSeparator())) {
56 path = path.substring(QueryPath.getPathSeparator().length());
57 }
58
59 QueryPath qPath = QueryPath.parse(path);
60 Data data = null;
61 if (model != null) {
62 data = model.get(qPath);
63 }
64
65 if (data != null) {
66 Iterator<Data.Property> iter1 = data.iterator();
67 if (iter1.hasNext()) {
68 table.buildHeaders();
69
70
71 while (iter1.hasNext()) {
72 Data.Property prop = iter1.next();
73 Object value = prop.getValue();
74
75 if (value instanceof String) {
76
77 Metadata metadata = model.getMetadata(qPath);
78 String dataValue = null;
79 if(metadata!=null&&metadata.getInitialLookup()!=null){
80 QueryPath translatedPath = QueryPath.concat("_runtimeData", prop.getKey().toString(), "id-translation");
81 dataValue = data.query(translatedPath);
82 }
83
84 if (dataValue == null)
85 dataValue = (String)value;
86
87 table.addNextCell(dataValue);
88 table.nextRow();
89 }
90 else {
91 Data rowData = prop.getValue();
92
93
94 for (Integer row : table.getConfig().getFields().keySet()) {
95 List<MultiplicityFieldConfiguration> fieldConfigs = table.getConfig().getFields().get(row);
96 for (MultiplicityFieldConfiguration fieldConfig : fieldConfigs) {
97
98 QueryPath fullPath = QueryPath.parse(fieldConfig.getFieldPath());
99 QueryPath fieldPath = translatePath(path, fullPath, model);
100
101 Object o = rowData.query(fieldPath);
102 if (o != null) {
103
104
105 if (o instanceof Data) {
106 Data cellData = (Data) o;
107
108
109 if (cellData != null && cellData.size() > 0) {
110 StringBuilder sb = new StringBuilder();
111 Iterator<Data.Property> iter = cellData.realPropertyIterator();
112 while (iter.hasNext()) {
113 Data.Property p = iter.next();
114 Data d = p.getValue();
115 String key = table.getConfig().getConcatenatedFields().get(fullPath.toString());
116 sb.append(d.get(key)).append(", ");
117 }
118 sb.deleteCharAt(sb.lastIndexOf(", "));
119 table.addNextCell((sb.toString()));
120 } else {
121 table.addEmptyCell();
122 }
123 }
124
125 else {
126 table.addNextCell((o.toString()));
127 }
128 } else {
129 table.addEmptyCell();
130 }
131 }
132 table.nextRow();
133 }
134 }
135 }
136 }
137 }
138 }
139
140
141
142
143
144
145
146
147
148
149
150 private QueryPath translatePath(String path, QueryPath fullPath, DataModel model) {
151 QueryPath parentPath = QueryPath.parse(path);
152 int i = parentPath.size();
153
154 Metadata metadata = model.getMetadata(fullPath);
155 QueryPath fieldPath = null;
156
157 if(metadata!=null&&metadata.getInitialLookup()!=null){
158 if (metadata.getDataType().equals(DataType.STRING)) {
159 QueryPath translatedPath = fullPath.subPath(0, fullPath.size()-1);
160 translatedPath.add(new Data.StringKey("_runtimeData"));
161 translatedPath.add(new Data.StringKey((String)fullPath.get(fullPath.size() - 1).get()));
162 translatedPath.add(new Data.StringKey("id-translation"));
163 fieldPath = translatedPath.subPath(i, translatedPath.size());
164 }
165 else {
166 fieldPath = fullPath.subPath(i, fullPath.size());
167 }
168 }
169 else {
170 fieldPath = fullPath.subPath(i, fullPath.size());
171 }
172
173 if (fieldPath.get(0).toString().equals(QueryPath.getWildCard())) {
174 fieldPath.remove(0);
175 }
176 return fieldPath;
177 }
178 }