| 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 |
| 14 |
|
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 12 |
Complexity Density: 0.28 |
|
| 15 |
|
public class TreeStringBinding extends ModelWidgetBindingSupport<KSListPanel> { |
| 16 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 17 |
0
|
@Override... |
| 18 |
|
public void setModelValue(KSListPanel widget, DataModel model, String path) { |
| 19 |
0
|
throw new UnsupportedOperationException("Method is not supported"); |
| 20 |
|
} |
| 21 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 22 |
0
|
@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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 4 |
Complexity Density: 0.19 |
|
| 33 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 64 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 72 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 16 |
Complexity Density: 0.8 |
|
| 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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 101 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 107 |
0
|
public void sortChildren() {... |
| 108 |
0
|
Collections.sort(children, new Comparator<StringTreeStructure>() { |
| 109 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 110 |
0
|
@Override... |
| 111 |
|
public int compare(StringTreeStructure o1, StringTreeStructure o2) { |
| 112 |
0
|
return o1.getIndex() - o2.getIndex(); |
| 113 |
|
} |
| 114 |
|
}); |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 117 |
0
|
public StringTreeStructure() {}... |
| 118 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 119 |
0
|
public List<String> getCategories() {... |
| 120 |
0
|
return categories; |
| 121 |
|
} |
| 122 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 123 |
0
|
public String getValue() {... |
| 124 |
0
|
return value; |
| 125 |
|
} |
| 126 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
0
|
public void setValue(String value) {... |
| 128 |
0
|
this.value = value; |
| 129 |
|
} |
| 130 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 131 |
0
|
public List<StringTreeStructure> getChildren() {... |
| 132 |
0
|
return children; |
| 133 |
|
} |
| 134 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 135 |
0
|
public void setChildren(List<StringTreeStructure> children) {... |
| 136 |
0
|
this.children = children; |
| 137 |
|
} |
| 138 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 139 |
0
|
public void addChild(StringTreeStructure child) {... |
| 140 |
0
|
children.add(child); |
| 141 |
|
} |
| 142 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 143 |
0
|
public boolean hasChildren() {... |
| 144 |
0
|
return !children.isEmpty(); |
| 145 |
|
} |
| 146 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 147 |
0
|
public void setIndex(int index) {... |
| 148 |
0
|
this.index = index; |
| 149 |
|
} |
| 150 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 151 |
0
|
public int getIndex() {... |
| 152 |
0
|
return index; |
| 153 |
|
} |
| 154 |
|
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 155 |
0
|
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 |
|
} |