大家如果感兴趣可以放问这个网址
http://www.ybloy.com/post/2009/07/16/Liste98092e5bd92e7949fe68890e4b88be68b89e58897e8a1a8e6a091.aspx
里面有实现过后的效果和代码的注释。
javaCode
1 //=================begin-取得类型树=================
2 private List<SysAuditotypecategory> cTreeList(List<SysAuditotypecategory> aList){
3 List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
4 List<SysAuditotypecategory> topList = new ArrayList<SysAuditotypecategory>();
5 List<SysAuditotypecategory> tempList = new ArrayList<SysAuditotypecategory>();
6
7 for (SysAuditotypecategory sacty : aList) {
8 if(sacty.getParent()==null){
9 topList.add(sacty);
10 }else {
11 tempList.add(sacty);
12 }
13 }
14
15 for (int i=0;i<topList.size();i++) {
16 SysAuditotypecategory sacty = topList.get(i);
17 returnList.add(cTreeNode(sacty, "", (i+1<topList.size())));
18 returnList.addAll(cTreeNodeList(tempList,sacty.getId(),(i+1<topList.size())?"│":" "));
19 }
20 return returnList;
21 }
22
23 private List<SysAuditotypecategory> cTreeNodeList(List<SysAuditotypecategory> inList,Long parentid,String headString){
24 List<SysAuditotypecategory> tempList1 = new ArrayList<SysAuditotypecategory>();
25 List<SysAuditotypecategory> tempList2 = new ArrayList<SysAuditotypecategory>();
26 List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
27
28 for(int i=0;i<inList.size();i++){
29 SysAuditotypecategory sacty = inList.get(i);
30 if(sacty.getParent().getId() == parentid){
31 tempList1.add(sacty);
32 }else {
33 tempList2.add(sacty);
34 }
35 }
36
37 if(tempList1.size()>0){
38 for(int i=0;i<tempList1.size();i++){
39 SysAuditotypecategory sacty1 = tempList1.get(i);
40 returnList.add(cTreeNode(sacty1, headString, (i+1<tempList1.size())));
41
42 if(tempList2.size()>0){
43 returnList.addAll(cTreeNodeList(tempList2,sacty1.getId(),headString+((i+1<tempList1.size())?"│":" ")));
44 }
45 }
46 }
47
48 return returnList;
49 }
50
51 private SysAuditotypecategory cTreeNode(SysAuditotypecategory satcy,String headString,boolean havenext) {
52 satcy.setCategoryname(headString.concat((havenext?"├":"└"))+satcy.getCategoryname());
53 return satcy;
54 }
1 //=================begin-取得类型树=================
2 private List<SysAuditotypecategory> cTreeList(List<SysAuditotypecategory> aList){
3 List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
4 List<SysAuditotypecategory> topList = new ArrayList<SysAuditotypecategory>();
5 List<SysAuditotypecategory> tempList = new ArrayList<SysAuditotypecategory>();
6
7 for (SysAuditotypecategory sacty : aList) {
8 if(sacty.getParent()==null){
9 topList.add(sacty);
10 }else {
11 tempList.add(sacty);
12 }
13 }
14
15 for (int i=0;i<topList.size();i++) {
16 SysAuditotypecategory sacty = topList.get(i);
17 returnList.add(cTreeNode(sacty, "", (i+1<topList.size())));
18 returnList.addAll(cTreeNodeList(tempList,sacty.getId(),(i+1<topList.size())?"│":" "));
19 }
20 return returnList;
21 }
22
23 private List<SysAuditotypecategory> cTreeNodeList(List<SysAuditotypecategory> inList,Long parentid,String headString){
24 List<SysAuditotypecategory> tempList1 = new ArrayList<SysAuditotypecategory>();
25 List<SysAuditotypecategory> tempList2 = new ArrayList<SysAuditotypecategory>();
26 List<SysAuditotypecategory> returnList = new ArrayList<SysAuditotypecategory>();
27
28 for(int i=0;i<inList.size();i++){
29 SysAuditotypecategory sacty = inList.get(i);
30 if(sacty.getParent().getId() == parentid){
31 tempList1.add(sacty);
32 }else {
33 tempList2.add(sacty);
34 }
35 }
36
37 if(tempList1.size()>0){
38 for(int i=0;i<tempList1.size();i++){
39 SysAuditotypecategory sacty1 = tempList1.get(i);
40 returnList.add(cTreeNode(sacty1, headString, (i+1<tempList1.size())));
41
42 if(tempList2.size()>0){
43 returnList.addAll(cTreeNodeList(tempList2,sacty1.getId(),headString+((i+1<tempList1.size())?"│":" ")));
44 }
45 }
46 }
47
48 return returnList;
49 }
50
51 private SysAuditotypecategory cTreeNode(SysAuditotypecategory satcy,String headString,boolean havenext) {
52 satcy.setCategoryname(headString.concat((havenext?"├":"└"))+satcy.getCategoryname());
53 return satcy;
54 }