public class UserProjWorkloadQueryTreeNodeUtil {
@SuppressWarnings("unchecked")
public static String getJsonString(List<UserProjWorkloadQueryTreeNode> list) {
if (list == null || list.isEmpty()) {
return "";
}
StringBuffer sb = new StringBuffer();
if (list != null && !list.isEmpty()) {
boolean first = true;
for (UserProjWorkloadQueryTreeNode node : list) {
if (first) {
sb.append("[");
first = false;
} else {
sb.append(",");
}
if (node.isLeaf()) {
sb.append("{");
getQueryTreeNodeData(sb, node);
sb.append("}");
} else {
sb.append("{");
getQueryTreeNodeData(sb, node);
sb.append(",children:");
sb.append(getJsonString(node.getChildren()));
sb.append("}");
}
}
sb.append("]");
}
return sb.toString();
}
/**
* 将本节点的信息写到sb中.
*
* @param sb
* @param node
*/
private static void getQueryTreeNodeData(StringBuffer sb, UserProjWorkloadQueryTreeNode node) {
List<WorkloadRecord> attributes = node.getAttributes();
for (WorkloadRecord record : attributes) {
sb.append("\"").append(record.getRecordTitle()).append("\":\"").append(record.getDisplayString()).append(
"\",");
}
sb.append("\"id\":").append("\"").append(node.getId()).append("\",");
sb.append("\"entityId\":").append(node.getEntityId()).append(",");
sb.append("\"uiProvider\":").append("\"").append(node.getUiProvider()).append("\",");
sb.append("\"leaf\":").append(node.isLeaf()).append(",");
sb.append("\"task\":").append("\"").append(node.getIconCls()).append("\",");
sb.append("\"href\":").append("\"").append(node.getHref()).append("\",");
sb.append("\"type\":").append("\"").append(node.getType()).append("\",");
sb.append("\"hrefTarget\":").append("\"").append(node.getHrefTarget()).append("\",");
sb.append("\"singleClickExpand\":").append(node.isSingleClickExpand());
}
}