1 | |
package org.kuali.student.common.ui.client.configurable.mvc.binding; |
2 | |
|
3 | |
import java.util.Iterator; |
4 | |
|
5 | |
import org.kuali.student.common.ui.client.mvc.DataModel; |
6 | |
import org.kuali.student.core.assembly.data.Data; |
7 | |
import org.kuali.student.core.assembly.data.Data.Property; |
8 | |
|
9 | |
import com.google.gwt.core.client.GWT; |
10 | |
import com.google.gwt.user.client.ui.HasText; |
11 | |
|
12 | 0 | public class ListToTextBinding implements ModelWidgetBinding<HasText> { |
13 | |
|
14 | |
private String innerObjectKey; |
15 | |
|
16 | 0 | public ListToTextBinding(String innerObjectKey) { |
17 | 0 | this.innerObjectKey = innerObjectKey; |
18 | 0 | } |
19 | |
|
20 | 0 | public ListToTextBinding() { |
21 | 0 | } |
22 | |
|
23 | |
@Override |
24 | |
public void setModelValue(HasText widget, DataModel model, String path) { |
25 | 0 | GWT.log("ListToTextBindings cannot be used for setting into the model!"); |
26 | 0 | } |
27 | |
|
28 | |
@Override |
29 | |
public void setWidgetValue(HasText widget, DataModel model, String path) { |
30 | 0 | widget.setText(getStringList(model, path)); |
31 | 0 | } |
32 | |
|
33 | |
public String getStringList(DataModel model, String path) { |
34 | 0 | Data data = model.get(path); |
35 | 0 | String resultString = ""; |
36 | 0 | if(data!=null){ |
37 | 0 | Iterator<Property> iter = data.realPropertyIterator(); |
38 | |
|
39 | 0 | while(iter.hasNext()){ |
40 | 0 | Property prop = iter.next(); |
41 | 0 | if (prop.getKey() instanceof Integer){ |
42 | 0 | Integer number = (Integer)prop.getKey(); |
43 | 0 | Object value = data.get(number); |
44 | 0 | if(value instanceof Data){ |
45 | 0 | DataModel m = new DataModel(); |
46 | 0 | m.setRoot((Data)value); |
47 | 0 | Object innerObject = m.get(innerObjectKey); |
48 | 0 | resultString = resultString + innerObject.toString() + ", "; |
49 | 0 | } |
50 | |
else{ |
51 | 0 | resultString = resultString + value.toString() + ", "; |
52 | |
} |
53 | |
} |
54 | 0 | } |
55 | |
} |
56 | 0 | if(!resultString.isEmpty()){ |
57 | 0 | resultString = resultString.trim(); |
58 | 0 | resultString = resultString.substring(0, resultString.length() - 1); |
59 | |
} |
60 | 0 | return resultString; |
61 | |
} |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public void setInnerObjectKey(String innerObjectKey) { |
69 | 0 | this.innerObjectKey = innerObjectKey; |
70 | 0 | } |
71 | |
|
72 | |
public String getInnerObjectKey() { |
73 | 0 | return innerObjectKey; |
74 | |
} |
75 | |
|
76 | |
} |