Clover Coverage Report - Kuali Student 1.2-M4-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Jul 20 2011 11:14:35 EDT
../../../../../../../img/srcFileCovDistChart0.png 41% of files have more coverage
63   167   28   3.32
18   135   0.44   9.5
19     1.47  
2    
 
  TreeStringBinding       Line # 15 43 0% 12 62 0% 0.0
  TreeStringBinding.StringTreeStructure       Line # 93 20 0% 16 38 0% 0.0
 
No Tests
 
1    package org.kuali.student.lum.common.client.lo;
2   
3    import com.google.gwt.user.client.ui.Label;
4   
5    import org.kuali.student.common.assembly.data.Data;
6    import org.kuali.student.common.ui.client.configurable.mvc.binding.ModelWidgetBindingSupport;
7    import org.kuali.student.common.ui.client.mvc.DataModel;
8    import org.kuali.student.common.ui.client.widgets.menus.KSListPanel;
9   
10    import java.util.*;
11   
12    /**
13    * @author Igor
14    */
 
15    public class TreeStringBinding extends ModelWidgetBindingSupport<KSListPanel> {
16   
 
17  0 toggle @Override
18    public void setModelValue(KSListPanel widget, DataModel model, String path) {
19  0 throw new UnsupportedOperationException("Method is not supported");
20    }
21   
 
22  0 toggle @Override
23    public void setWidgetValue(KSListPanel listPanel, DataModel model, String path) {
24  0 listPanel.clear();
25  0 Data loData = model.get(path);
26  0 if (loData != null) {
27  0 StringTreeStructure rootModel = new StringTreeStructure();
28  0 transform(loData, rootModel);
29  0 bind(rootModel, listPanel);
30    }
31    }
32   
 
33  0 toggle private void transform(Data loData, StringTreeStructure rootModel) {
34  0 for (Data.Property property : loData) {
35  0 Data loDisplayInfoData = property.getValue();
36  0 LoDisplayInfoHelper loDisplayInfoHelper = new LoDisplayInfoHelper(loDisplayInfoData);
37  0 LoInfoHelper loInfoHelper = new LoInfoHelper(loDisplayInfoHelper.getLoInfo());
38  0 RichTextHelper descriptionHelper = new RichTextHelper(loInfoHelper.getDesc());
39  0 Data categoriesData = loDisplayInfoHelper.getCategoryInfoList();
40  0 List<String> categories = new ArrayList<String>();
41   
42  0 if (null != categoriesData) {
43  0 Iterator<Data.Property> itr = categoriesData.realPropertyIterator();
44   
45  0 while (itr.hasNext()) {
46  0 Data.Property catProp = itr.next();
47  0 Data catData = catProp.getValue();
48  0 LoCategoryInfoHelper category = new LoCategoryInfoHelper(catData);
49  0 categories.add(category.getName());
50    }
51    }
52   
53  0 int index = 0;
54  0 String sequence = loInfoHelper.getSequence();
55  0 if (sequence != null) {
56  0 index = Integer.parseInt(sequence);
57    }
58  0 StringTreeStructure childModel = new StringTreeStructure(index, descriptionHelper.getPlain(), categories);
59  0 transform(loDisplayInfoHelper.getDisplayInfoList(), childModel);
60  0 rootModel.addChild(childModel);
61    }
62    }
63   
 
64  0 toggle private void bind(StringTreeStructure stringTreeStructure, KSListPanel ksListPanel) {
65  0 stringTreeStructure.sortChildren();
66  0 List<StringTreeStructure> firstLevelChildren = stringTreeStructure.getChildren();
67  0 for (StringTreeStructure firstLevelChild : firstLevelChildren) {
68  0 addElement(firstLevelChild, ksListPanel);
69    }
70    }
71   
 
72  0 toggle private void addElement(StringTreeStructure element, KSListPanel listPanel) {
73  0 if (element.hasChildren()) {
74  0 KSListPanel subPanel = new KSListPanel();
75  0 element.sortChildren();
76  0 for (StringTreeStructure child : element.getChildren()) {
77  0 addElement(child, subPanel);
78    }
79  0 if (!element.getCategories().isEmpty()) {
80  0 listPanel.add(subPanel, element.getValue() + element.getCategoriesString());
81    } else {
82  0 listPanel.add(subPanel, element.getValue());
83    }
84    } else {
85  0 if (!element.getCategories().isEmpty()) {
86  0 listPanel.add(new Label(element.getValue() + element.getCategoriesString()));
87    } else {
88  0 listPanel.add(new Label(element.getValue()));
89    }
90    }
91    }
92   
 
93    private static class StringTreeStructure {
94   
95    private String value;
96    private int index;
97   
98    private List<StringTreeStructure> children = new ArrayList<StringTreeStructure>();
99    private List<String> categories = new LinkedList<String>();
100   
 
101  0 toggle public StringTreeStructure(int index, String value, List<String> categories) {
102  0 this.setIndex(index);
103  0 this.value = value;
104  0 this.categories = categories;
105    }
106   
 
107  0 toggle public void sortChildren() {
108  0 Collections.sort(children, new Comparator<StringTreeStructure>() {
109   
 
110  0 toggle @Override
111    public int compare(StringTreeStructure o1, StringTreeStructure o2) {
112  0 return o1.getIndex() - o2.getIndex();
113    }
114    });
115    }
116   
 
117  0 toggle public StringTreeStructure() {}
118   
 
119  0 toggle public List<String> getCategories() {
120  0 return categories;
121    }
122   
 
123  0 toggle public String getValue() {
124  0 return value;
125    }
126   
 
127  0 toggle public void setValue(String value) {
128  0 this.value = value;
129    }
130   
 
131  0 toggle public List<StringTreeStructure> getChildren() {
132  0 return children;
133    }
134   
 
135  0 toggle public void setChildren(List<StringTreeStructure> children) {
136  0 this.children = children;
137    }
138   
 
139  0 toggle public void addChild(StringTreeStructure child) {
140  0 children.add(child);
141    }
142   
 
143  0 toggle public boolean hasChildren() {
144  0 return !children.isEmpty();
145    }
146   
 
147  0 toggle public void setIndex(int index) {
148  0 this.index = index;
149    }
150   
 
151  0 toggle public int getIndex() {
152  0 return index;
153    }
154   
 
155  0 toggle public String getCategoriesString() {
156  0 String result = " (";
157  0 for (int i = 0; i < categories.size(); i++) {
158  0 if (i != categories.size() - 1) {
159  0 result = result + categories.get(i) + ", ";
160    } else {
161  0 result = result + categories.get(i) + ")";
162    }
163    }
164  0 return result;
165    }
166    }
167    }