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