8d9dc5851228455436af2c7aafb13cfd904f05cf.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package com.sinosoft.lz.common;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.servlet.http.HttpServletRequest;
  5. import model.setup.constant.ConstantTreeNode;
  6. import com.persistence.service.PersistenceFactory;
  7. import com.persistence.service.SysPersistence;
  8. import com.persistence.service.exception.PersistenceException;
  9. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  10. import com.sysmodel.datamodel.xmlmodel.able.SysModel;
  11. import com.toolkit.tree.DIVTree;
  12. import com.toolkit.tree.TreeNode;
  13. public class RefTableTree extends DIVTree{
  14. /** The referenceclass name. */
  15. String referenceclassName = "";
  16. String keyField = "";
  17. String displayName = "";
  18. String parentField = "";
  19. String condition = "";
  20. String order = "";
  21. int referenceclassid = 0;
  22. private String path = "";
  23. SysModel sysModel = ModelFactory.getSysmodel();
  24. private SysPersistence sysPersistenceObject = PersistenceFactory.getInstance(sysModel);
  25. public RefTableTree(HttpServletRequest req) {
  26. path = req.getContextPath();
  27. referenceclassid = Integer.valueOf(
  28. req.getParameter("referenceclassid") == null ? "99" : (String) req
  29. .getParameter("referenceclassid")).intValue();
  30. referenceclassName = sysModel.getMdpClassByClassID(referenceclassid).getName();
  31. keyField = req.getParameter("storeCode") == null ? "" : (String) req
  32. .getParameter("storeCode");
  33. displayName = req.getParameter("displayName") == null ? "" : (String) req
  34. .getParameter("displayName");
  35. parentField = req.getParameter("parentCode") == null ? "" : (String) req
  36. .getParameter("parentCode");
  37. condition = req.getParameter("condition") == null ? "" : (String) req
  38. .getParameter("condition");
  39. order = req.getParameter("order") == null ? " " : (String) req.getParameter("order");
  40. }
  41. /*
  42. * (non-Javadoc)
  43. *
  44. * @see com.nxs.commons.tree.DIVTree#getLinkTarget()
  45. */
  46. public String getLinkTarget() {
  47. // TODO Auto-generated method stub
  48. return null;
  49. }
  50. /*
  51. * (non-Javadoc)
  52. *
  53. * @see com.nxs.commons.tree.DIVTree#getTreeImagePath()
  54. */
  55. public String getTreeImagePath() {
  56. return path + "/images/tree_images/";
  57. }
  58. /*
  59. * (non-Javadoc)
  60. *
  61. * @see com.nxs.commons.tree.DIVTree#getChildTreeNode(java.lang.String)
  62. */
  63. @SuppressWarnings({ "rawtypes", "unchecked" })
  64. public List getChildTreeNode(String nodeID) {
  65. StringBuffer sb = new StringBuffer();
  66. sb.append("select " + keyField + "," + displayName + " from " + referenceclassName
  67. + " where 1=1 ");
  68. if (!parentField.equals("")) {
  69. sb.append(" and " + parentField + "='" + nodeID + "'");
  70. if (nodeID == null)
  71. sb.append(" and " + parentField + " is null");
  72. }
  73. if (!condition.equals(""))
  74. sb.append(" and " + condition);
  75. sb.append(" " + order);
  76. ArrayList vect = null;
  77. try {
  78. vect = sysPersistenceObject.getSearchResult(referenceclassid, sb.toString());
  79. } catch (PersistenceException e) {
  80. // TODO Auto-generated catch block
  81. e.printStackTrace();
  82. }
  83. ArrayList al = new ArrayList();
  84. for (int i = 0; i < vect.size(); i++) {
  85. String[] array_element = (String[]) vect.get(i);
  86. ConstantTreeNode constantTreeNode = new ConstantTreeNode(array_element,
  87. referenceclassName, path, "");
  88. constantTreeNode.MouseEventName = "onclick";
  89. constantTreeNode.NodeOnMouseEvent = "returnValue(this);";
  90. al.add(constantTreeNode);
  91. }
  92. return al;
  93. }
  94. /*
  95. * (non-Javadoc)
  96. *
  97. * @see com.nxs.commons.tree.DIVTree#getCurrentTreeNode(java.lang.String)
  98. */
  99. @SuppressWarnings("rawtypes")
  100. public TreeNode getCurrentTreeNode(String nodeID) {
  101. StringBuffer sb = new StringBuffer();
  102. sb.append("select " + keyField + (displayName.equals("") ? "" : ("," + displayName))
  103. + " from " + referenceclassName + " ");
  104. sb.append(" where " + keyField + (nodeID == null ? (" is null") : ("='" + nodeID + "' ")));
  105. // sb.append((condition.equals("")?"":(" and "+condition)));
  106. ArrayList vect = null;
  107. try {
  108. vect = sysPersistenceObject.getSearchResult(referenceclassid, sb.toString());
  109. } catch (PersistenceException e) {
  110. // TODO Auto-generated catch block
  111. e.printStackTrace();
  112. }
  113. if (vect.size() > 0) {
  114. ConstantTreeNode constantTreeNode = new ConstantTreeNode((String[]) vect.get(0),
  115. referenceclassName, path, ""); // &@
  116. // �˴�ע��,������Ҫ�޸�TestNode
  117. // ��ʵ�� @&
  118. constantTreeNode.MouseEventName = "onclick";
  119. constantTreeNode.NodeOnMouseEvent = "returnValue(this);";
  120. return constantTreeNode;
  121. }
  122. return null;
  123. }
  124. /*
  125. * (non-Javadoc)
  126. *
  127. * @see com.nxs.commons.tree.DIVTree#hasChild(com.nxs.commons.tree.TreeNode)
  128. */
  129. @SuppressWarnings("rawtypes")
  130. public boolean hasChild(TreeNode currentNode) {
  131. if (parentField.equals(""))
  132. return false;
  133. else {
  134. String sql = "select count(*) from " + referenceclassName + " where " + parentField
  135. + "='" + currentNode.getNodeID() + "'";
  136. System.out.print(sql);
  137. ArrayList vect = null;
  138. try {
  139. vect = sysPersistenceObject.getSearchResult(referenceclassid, sql);
  140. } catch (PersistenceException e) {
  141. // TODO Auto-generated catch block
  142. e.printStackTrace();
  143. }
  144. if (vect.size() > 0) {
  145. String[] temp = (String[]) vect.get(0);
  146. return temp[0].equals("0") ? false : true;
  147. } else
  148. return false;
  149. }
  150. }
  151. }