java 树形结构设计(七) Struts + Hibernate

step 11、构建 树形结构类

 

java 代码
  1. /**  
  2.  * 地理信息数结构显示  
  3.  */  
  4. package com.winchannel.common.tree;   
  5.   
  6. import java.util.ArrayList;   
  7. import java.util.List;   
  8.   
  9. /**  
  10.  * @author huguoqing  
  11.  *  
  12.  */  
  13. public class GeographyTreeViewManager {   
  14.   
  15.     public String strTreeStylePath;   
  16.     protected boolean bVerticalLine;   
  17.     protected GeographyTreeItem root;   
  18.     protected List childList;   
  19.        
  20.     public GeographyTreeViewManager()   
  21.     {   
  22.         strTreeStylePath = "/images/treeview/treeview_default/";   
  23.         bVerticalLine = true;   
  24.         root = null;   
  25.         childList = new ArrayList();   
  26.         root = new GeographyTreeItem(null);   
  27.         root.setDisplayChildren(true);   
  28.     }   
  29.   
  30.     public GeographyTreeViewManager(String strRoot)   
  31.     {   
  32.         strTreeStylePath = "/images/treeview/treeview_default/";   
  33.         bVerticalLine = true;   
  34.         root = null;   
  35.         childList = new ArrayList();   
  36.         root = new GeographyTreeItem(strRoot);   
  37.         root.setDisplayChildren(true);   
  38.     }   
  39.   
  40.     public GeographyTreeViewManager(GeographyTreeItem root)   
  41.     {   
  42.         strTreeStylePath = "/images/treeview/treeview_default/";   
  43.         bVerticalLine = true;   
  44.         this.root = null;   
  45.         childList = new ArrayList();   
  46.         this.root = root;   
  47.         root.setDisplayChildren(true);   
  48.     }   
  49.     /**  
  50.      * 设置树结构样式及图标存放路径  
  51.      * @param strPath  
  52.      */  
  53.     public void setTreeStylePath(String strPath)   
  54.     {   
  55.         strTreeStylePath = strPath;   
  56.     }   
  57.     /**  
  58.      * 获取树结构样式及图标存放路径  
  59.      * @return  
  60.      */  
  61.     public String getTreeStylePath()   
  62.     {   
  63.         return strTreeStylePath;   
  64.     }   
  65.     /**  
  66.      *   
  67.      * @param bLine  
  68.      */  
  69.     public void setVerticalLine(boolean bLine)   
  70.     {   
  71.         bVerticalLine = bLine;   
  72.     }   
  73.     /**  
  74.      *   
  75.      * @return boolean  
  76.      */  
  77.     public boolean getVerticalLine()   
  78.     {   
  79.         return bVerticalLine;   
  80.     }   
  81.     /**  
  82.      *   
  83.      * @return   
  84.      */  
  85.     public GeographyTreeItem getRoot()   
  86.     {   
  87.         return root;   
  88.     }   
  89.   
  90.     public void addItem(GeographyTreeItem item)   
  91.     {   
  92.         root.addChild(item);   
  93.     }   
  94.   
  95.     public String getScript()   
  96.     {   
  97.         StringBuffer stHTML = new StringBuffer(10000);   
  98.         stHTML.append("<!--   TreeView component -->/\r/\n");   
  99.         stHTML.append("<LINK href=\"" + strTreeStylePath + "treeview.css\" rel=stylesheet>/\r/\n");   
  100.         stHTML.append("/\r/\n");   
  101.         stHTML.append("<SCRIPT language=JavaScript>/\r/\n");   
  102.         stHTML.append("《!--/\r/\n");   
  103.         stHTML.append("var treeview_ob_tb, treeview_ob_url, treeview_selected_node_id;/\r/\n");   
  104.         stHTML.append("function treeview_ob_wk(os, url) {/\r/\n");   
  105.         stHTML.append("/\tvar ot = os.parentNode.nextSibling.firstChild.nextSibling;/\r/\n");   
  106.         stHTML.append("/\tvar lensrc = (os.src.length - 8);/\r/\n");   
  107.         stHTML.append("/\tvar s = os.src.substr(lensrc, 8);/\r/\n");   
  108.         stHTML.append("/\tif (s == /\"inus.gif/\") {/\r/\n");   
  109.         stHTML.append("/\t/\tot.style.display = /\"none/\";/\r/\n");   
  110.         stHTML.append("/\t/\tos.src = /\"" + strTreeStylePath + "plusik.gif/\";/\r/\n");   
  111.         stHTML.append("/\t}/\r/\n");   
  112.         stHTML.append("/\tif (s == /\"usik.gif/\") {/\r/\n");   
  113.         stHTML.append("/\t/\tot.style.display = /\"block/\";/\r/\n");   
  114.         stHTML.append("/\t/\tos.src = /\"" + strTreeStylePath + "minus.gif/\";/\r/\n");   
  115.         stHTML.append("/\t/\tif (url != /\"/\") {/\r/\n");   
  116.         stHTML.append("/\t/\t/\tvar s = os.parentNode.nextSibling.firstChild.nextSibling.innerText;/\r/\n");   
  117.         stHTML.append("/\t/\t/\tif (s != /\"正读取数据,请稍候 .../\") {/\r/\n");   
  118.         stHTML.append("/\t/\t/\t/\treturn;/\r/\n");   
  119.         stHTML.append("/\t/\t/\t}/\r/\n");   
  120.         stHTML.append("/\t/\t/\ttreeview_ob_url = url;/\r/\n");   
  121.         stHTML.append("/\t/\t/\ttreeview_ob_tb = os;/\r/\n");   
  122.         stHTML.append("            oDownload.startDownload(treeview_ob_url, treeview_ob_tm);/\r/\n");   
  123.         stHTML.append("/\t/\t/\t//window.setTimeout(/\"treeview_ob_tm()/\", 100);/\r/\n");   
  124.         stHTML.append("/\t/\t}/\r/\n");   
  125.         stHTML.append("/\t}/\r/\n");   
  126.         stHTML.append("/\tif (s == /\"ik_l.gif/\") {/\r/\n");   
  127.         stHTML.append("/\t/\tot.style.display = /\"block/\";/\r/\n");   
  128.         stHTML.append("/\t/\tos.src = /\"" + strTreeStylePath + "minus_l.gif/\";/\r/\n");   
  129.         stHTML.append("/\t/\tif (url != /\"/\") {/\r/\n");   
  130.         stHTML.append("/\t/\t/\tvar s = os.parentNode.nextSibling.firstChild.nextSibling.innerText;/\r/\n");   
  131.         stHTML.append("/\t/\t/\tif (s != /\"正读取数据,请稍候 .../\") {/\r/\n");   
  132.         stHTML.append("/\t/\t/\t/\treturn;/\r/\n");   
  133.         stHTML.append("/\t/\t/\t}/\r/\n");   
  134.         stHTML.append("/\t/\t/\ttreeview_ob_url = url;/\r/\n");   
  135.         stHTML.append("/\t/\t/\ttreeview_ob_tb = os;/\r/\n");   
  136.         stHTML.append("            oDownload.startDownload(treeview_ob_url, treeview_ob_tm);/\r/\n");   
  137.         stHTML.append("/\t/\t/\t//window.setTimeout(/\"treeview_ob_tm()/\", 100);/\r/\n");   
  138.         stHTML.append("/\t/\t}/\r/\n");   
  139.         stHTML.append("/\t}/\r/\n");   
  140.         stHTML.append("/\tif (s == /\"us_l.gif/\") {/\r/\n");   
  141.         stHTML.append("/\t/\tot.style.display = /\"none/\";/\r/\n");   
  142.         stHTML.append("/\t/\tos.src = /\"" + strTreeStylePath + "plusik_l.gif/\";/\r/\n");   
  143.         stHTML.append("/\t}/\r/\n");   
  144.         stHTML.append("}/\r/\n");   
  145.         stHTML.append("/\r/\n");   
  146.         stHTML.append("function treeview_ob_tm(s) {/\r/\n");   
  147.         stHTML.append("/\t//var xmlhttp = new ActiveXObject(/\"Microsoft.XMLHTTP/\");/\r/\n");   
  148.         stHTML.append("/\t//xmlhttp.open(/\"GET/\", treeview_ob_url, false);/\r/\n");   
  149.         stHTML.append("/\t//xmlhttp.send(/\"/\");/\r/\n");   
  150.         stHTML.append("/\t//treeview_ob_tb.parentNode.nextSibling.firstChild.nextSibling.outerHTML = xmlhttp.responseText;/\r/\n");   
  151.         stHTML.append("/\ttreeview_ob_tb.parentNode.nextSibling.firstChild.nextSibling.outerHTML = s;/\r/\n");   
  152.         stHTML.append("}/\r/\n");   
  153.         stHTML.append("/\r/\n");   
  154.         stHTML.append("function treeview_ob_ft(os) {/\r/\n");   
  155.            
  156.         //stHTML.append("/\talert(/\"柴外/\");/\r/\n");   
  157.            
  158.         stHTML.append("/\tif (typeof op != /\"undefined/\") {/\r/\n");   
  159.         stHTML.append("/\t/\top.style.backgroundColor = bg;/\r/\n");   
  160.         stHTML.append("/\t/\top.style.border = /\"none/\";/\r/\n");   
  161.         stHTML.append("    }/\r/\n");   
  162.         stHTML.append("/\tbg = os.style.backgroundColor;/\r/\n");   
  163.         stHTML.append("/\tos.style.backgroundColor = /\"ccddee/\";/\r/\n");   
  164.         stHTML.append("/\tos.style.border = /\"0px solid #666666/\";/\r/\n");   
  165.         stHTML.append("/\ttreeview_selected_node_id = os.id;/\r/\n");   
  166.         stHTML.append("/\top = os;/\r/\n");   
  167.         stHTML.append("}/\r/\n");   
  168.         stHTML.append("/\r/\n");   
  169.         stHTML.append("function treeview_ob_modify(os) {/\r/\n");   
  170.         stHTML.append("/\ttreeview_ob_ft(os);/\r/\n");   
  171.         stHTML.append("/\tif(os == null || os.value == '')/\r/\n");   
  172.         stHTML.append("/\t{/\r/\n");   
  173.         stHTML.append("/\t/\treturn;/\r/\n");   
  174.         stHTML.append("/\t}/\r/\n");   
  175.         stHTML.append("/\t_edit();/\r/\n");   
  176.         stHTML.append("}/\r/\n");   
  177.         stHTML.append("/\r/\n");   
  178.         stHTML.append("function treeview_ob_os(e){/\r/\n");   
  179.         stHTML.append("/\tvar os = e.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.firstChild.firstChild;/\r/\n");   
  180.         stHTML.append("/\tif (os != null) {/\r/\n");   
  181.         stHTML.append("/\tif ((typeof os != /\"undefined/\") && (os.tagName == /\"IMG/\")) {/\r/\n");   
  182.         stHTML.append("/\t/\tvar lensrc = (os.src.length - 8);/\r/\n");   
  183.         stHTML.append("/\t/\tvar s = os.src.substr(lensrc, 8);/\r/\n");   
  184.         stHTML.append("/\t/\tif ((s == /\"inus.gif/\") || (s == /\"usik.gif/\") || (s == /\"us_l.gif/\") || (s == /\"ik_l.gif/\")) {/\r/\n");   
  185.         stHTML.append("/\t/\t/\te.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.firstChild.firstChild.click();/\r/\n");   
  186.         stHTML.append("/\t/\t}/\r/\n");   
  187.         stHTML.append("/\t}/\r/\n");   
  188.         stHTML.append("/\telse {/\r/\n");   
  189.         stHTML.append("/\t/\ttreeview_ob_os(e.parentNode);/\r/\n");   
  190.         stHTML.append("/\t}/\r/\n");   
  191.         stHTML.append("}}/\r/\n");   
  192.         stHTML.append("/\r/\n");   
  193.         stHTML.append("//--》/\r/\n");   
  194.         stHTML.append("</SCRIPT>/\r/\n");   
  195.         return stHTML.toString();   
  196.     }   
  197.   
  198.     public String getRootHTML()   
  199.     {   
  200.         StringBuffer stHTML = new StringBuffer(10000);   
  201.         stHTML.append(root.getHTML(strTreeStylePath, bVerticalLine));   
  202.         stHTML.append("<!-- End Of TreeView-->/\r/\n");   
  203.         return stHTML.toString();   
  204.     }   
  205.   
  206.     public String getHTML()   
  207.     {   
  208.         StringBuffer stHTML = new StringBuffer(10000);   
  209.         stHTML.append(getScript());   
  210.         stHTML.append(getRootHTML());   
  211.         return stHTML.toString();   
  212.     }   
  213.   
  214.     public static void main(String argv[])   
  215.     {   
  216.         GeographyTreeViewManager tvm = new GeographyTreeViewManager();   
  217.         GeographyTreeItem item = new GeographyTreeItem("a1");   
  218.         item.addChild(new GeographyTreeItem("a1_1"));   
  219.         item.addChild(new GeographyTreeItem("a1_2"));   
  220.         item.addChild(new GeographyTreeItem("a1_3"));   
  221.         item.addChild(new GeographyTreeItem("a1_4"));   
  222.         item.addChild(new GeographyTreeItem("a1_5"));   
  223.         GeographyTreeItem item2 = new GeographyTreeItem("a2");   
  224.         GeographyTreeItem item2_1 = new GeographyTreeItem("a2_1");   
  225.         item2_1.addChild(new GeographyTreeItem("a2_1_1"));   
  226.         item2.addChild(item2_1);   
  227.         item2.addChild(new GeographyTreeItem("a2_2"));   
  228.         tvm.addItem(item);   
  229.         tvm.addItem(item2);   
  230.         System.out.println(tvm.getHTML());   
  231.     }   
  232.   
  233. }   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值