package com.sinosoft.lz.common; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import model.setup.constant.ConstantTreeNode; import com.persistence.service.PersistenceFactory; import com.persistence.service.SysPersistence; import com.persistence.service.exception.PersistenceException; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.sysmodel.datamodel.xmlmodel.able.SysModel; import com.toolkit.tree.DIVTree; import com.toolkit.tree.TreeNode; public class RefTableTree extends DIVTree{ /** The referenceclass name. */ String referenceclassName = ""; String keyField = ""; String displayName = ""; String parentField = ""; String condition = ""; String order = ""; int referenceclassid = 0; private String path = ""; SysModel sysModel = ModelFactory.getSysmodel(); private SysPersistence sysPersistenceObject = PersistenceFactory.getInstance(sysModel); public RefTableTree(HttpServletRequest req) { path = req.getContextPath(); referenceclassid = Integer.valueOf( req.getParameter("referenceclassid") == null ? "99" : (String) req .getParameter("referenceclassid")).intValue(); referenceclassName = sysModel.getMdpClassByClassID(referenceclassid).getName(); keyField = req.getParameter("storeCode") == null ? "" : (String) req .getParameter("storeCode"); displayName = req.getParameter("displayName") == null ? "" : (String) req .getParameter("displayName"); parentField = req.getParameter("parentCode") == null ? "" : (String) req .getParameter("parentCode"); condition = req.getParameter("condition") == null ? "" : (String) req .getParameter("condition"); order = req.getParameter("order") == null ? " " : (String) req.getParameter("order"); } /* * (non-Javadoc) * * @see com.nxs.commons.tree.DIVTree#getLinkTarget() */ public String getLinkTarget() { // TODO Auto-generated method stub return null; } /* * (non-Javadoc) * * @see com.nxs.commons.tree.DIVTree#getTreeImagePath() */ public String getTreeImagePath() { return path + "/images/tree_images/"; } /* * (non-Javadoc) * * @see com.nxs.commons.tree.DIVTree#getChildTreeNode(java.lang.String) */ @SuppressWarnings({ "rawtypes", "unchecked" }) public List getChildTreeNode(String nodeID) { StringBuffer sb = new StringBuffer(); sb.append("select " + keyField + "," + displayName + " from " + referenceclassName + " where 1=1 "); if (!parentField.equals("")) { sb.append(" and " + parentField + "='" + nodeID + "'"); if (nodeID == null) sb.append(" and " + parentField + " is null"); } if (!condition.equals("")) sb.append(" and " + condition); sb.append(" " + order); ArrayList vect = null; try { vect = sysPersistenceObject.getSearchResult(referenceclassid, sb.toString()); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } ArrayList al = new ArrayList(); for (int i = 0; i < vect.size(); i++) { String[] array_element = (String[]) vect.get(i); ConstantTreeNode constantTreeNode = new ConstantTreeNode(array_element, referenceclassName, path, ""); constantTreeNode.MouseEventName = "onclick"; constantTreeNode.NodeOnMouseEvent = "returnValue(this);"; al.add(constantTreeNode); } return al; } /* * (non-Javadoc) * * @see com.nxs.commons.tree.DIVTree#getCurrentTreeNode(java.lang.String) */ @SuppressWarnings("rawtypes") public TreeNode getCurrentTreeNode(String nodeID) { StringBuffer sb = new StringBuffer(); sb.append("select " + keyField + (displayName.equals("") ? "" : ("," + displayName)) + " from " + referenceclassName + " "); sb.append(" where " + keyField + (nodeID == null ? (" is null") : ("='" + nodeID + "' "))); // sb.append((condition.equals("")?"":(" and "+condition))); ArrayList vect = null; try { vect = sysPersistenceObject.getSearchResult(referenceclassid, sb.toString()); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (vect.size() > 0) { ConstantTreeNode constantTreeNode = new ConstantTreeNode((String[]) vect.get(0), referenceclassName, path, ""); // &@ // �˴�ע��,������Ҫ�޸�TestNode // ��ʵ�� @& constantTreeNode.MouseEventName = "onclick"; constantTreeNode.NodeOnMouseEvent = "returnValue(this);"; return constantTreeNode; } return null; } /* * (non-Javadoc) * * @see com.nxs.commons.tree.DIVTree#hasChild(com.nxs.commons.tree.TreeNode) */ @SuppressWarnings("rawtypes") public boolean hasChild(TreeNode currentNode) { if (parentField.equals("")) return false; else { String sql = "select count(*) from " + referenceclassName + " where " + parentField + "='" + currentNode.getNodeID() + "'"; System.out.print(sql); ArrayList vect = null; try { vect = sysPersistenceObject.getSearchResult(referenceclassid, sql); } catch (PersistenceException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (vect.size() > 0) { String[] temp = (String[]) vect.get(0); return temp[0].equals("0") ? false : true; } else return false; } } }