?? treeviewrender.java
字號:
package com.yuanchung.organize.treeview;
import java.util.List;
import org.apache.log4j.Logger;
import com.yuanchung.sales.exception.SystemException;
import com.yuanchung.sales.model.Treeview;
public class TreeViewRender {
private static Logger logger = Logger.getLogger(TreeViewRender.class);
// public static String renderTest() {
// StringBuffer content = new StringBuffer();
// try{
// content.append("d = new dTree('d');");
// List<Treeview> tvList = TreeViewMgr.getAllTreeByParentId(1);
// for(int i =0 ; i < tvList.size();i++){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "','javascript:d.o(1)');");
// }
// content.append("document.write(d);");
// }catch(Exception e){
// e.printStackTrace();
// }
// return content.toString();
// }
// //?????????
// public static String diguiTree(String treeStr, int parentId) {
//
// StringBuffer content = new StringBuffer();
//
// List<Treeview> tvList = TreeViewMgr.getAllTreeByParentId(parentId);
// for(int i =0 ; i < tvList.size();i++){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "','javascript:goToMail(" + tvList.get(i).getId() + ")');");
// }
// return content.toString();
// }
private static TreeViewMgr treeViewMgr = new TreeViewMgr();
/**
*
* @param treeStr
* @param parentId
* @return
* @throws SystemException
*/
public static String renderStatic(String treeStr, int parentId)
throws SystemException {
StringBuffer content = new StringBuffer(treeStr);
System.out.println("cccccccccccccccccccccccccccccc");
Treeview root = null;
if (parentId == 1) {// ?????
System.out.println("????" + parentId);
content.append("d = new dTree('d');");
// ???????
root = TreeViewMgr.findByParentId(parentId);
content.append("d.add(" + root.getId() + ",1,'" + root.getName()
+ "','/sales/admin/treeView.do?method=infoUser&id="
+ root.getId() + "','','main');" + "\n");
if (canExpand(root.getId())) {
// ??????
content.append(renderStatic(content.toString(), root.getId()));
}
} else {
// ???????е?????
List<Treeview> tvList = treeViewMgr.getAllTreeByParentId(parentId);
System.out.println("???????" + tvList.size());
for (int i = 0; i < tvList.size(); i++) {
System.out.println("????" + tvList.get(i).getId());
content.append("d.add(" + tvList.get(i).getId() + ","
+ tvList.get(i).getParentId() + ",'"
+ tvList.get(i).getName()
+ "','/sales/admin/treeView.do?method=infoUser&id="
+ tvList.get(i).getId() + "','','main');" + "\n");
if (canExpand(tvList.get(i).getId())) {
// ??????
content.append(renderStatic(content.toString(), tvList.get(
i).getId()));
}
}
}
System.out.println(content.toString());
return content.toString();
}
// ?ж???????????
public static boolean canExpand(int nodeId) {
System.out.println("bbbbbbbbbbbbbbbbbbbbbbbbbb");
try {
List nodeList = treeViewMgr.getAllTreeByParentId(nodeId);
if (nodeList.size() > 0) {
return true;
} else {
return false;
}
} catch (Exception re) {
return false;
}
}
// ???????
public static String openTree(String treeStr, int parentId)
throws SystemException {
StringBuffer content = new StringBuffer(treeStr);
System.out.println("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
Treeview root = null;
if (parentId == 1) {// ?????
logger.debug("節點從1開始.......");
content.append("d = new dTree('d');");
// ???????
root = TreeViewMgr.findByParentId(parentId);
content.append("d.add(" + root.getId() + "," + root.getParentId()
+ ",'" + root.getName() + "',\"javascript:initDept('"
+ root.getId() + "','" + root.getName() + "');\");" + "\n");
if (canExpand(root.getId())) {
// ??????
content.append(openTree(content.toString(), root.getId()));
}
} else {
// ???????е?????
System.out.println("節點從不是1開始開始.......");
List<Treeview> tvList = treeViewMgr.getAllTreeByParentId(parentId);
for (int i = 0; i < tvList.size(); i++) {
System.out.println("????" + tvList.get(i).getIsLeader());
if (tvList.get(i).getIsLeader().equals(0)) {// ???????
logger.debug("?????????");
content.append("d.add(" + tvList.get(i).getId() + ","
+ tvList.get(i).getParentId() + ",'"
+ tvList.get(i).getName()
+ "',\"javascript:initDept('"
+ tvList.get(i).getId() + "', '"
+ tvList.get(i).getName() + "');\");" + "\n");
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" +
// tvList.get(i).getName() + "','','','mainframe');"+"\n");
} else {
content.append("d.add(" + tvList.get(i).getId() + ","
+ tvList.get(i).getParentId() + ",'"
+ tvList.get(i).getName() + "','','','mainframe');"
+ "\n");
logger.debug("??λ??????");
}
if (canExpand(tvList.get(i).getId())) {
// ??????
content.append(openTree(content.toString(), tvList.get(i)
.getId()));
}
}
}
System.out.println("這個總的內容是什么啊?" + content.toString());
return content.toString();
}
// public static String renderStatic(TreeviewElement treeElmt, boolean
// bHidden) {
// StringBuffer content = new StringBuffer();
// content.append("<li id=" + treeElmt.getID() + ">");//???li???
// if (bHidden &&
// treeElmt.canExpand())//??????????????????????,?????????????????showHide???
// content.append("<img src=/wbflow/images/plus.gif onClick=\"showHide('"
// + treeElmt.getID() + "')\">");
// else if (treeElmt.canExpand())//?????????,?????????????????showHide???
// content.append("<img src=/wbflow/images/minus.gif onClick=\"showHide('"
// + treeElmt.getID() + "')\">");
// else//????????????
// content.append("<img src=/wbflow/images/blank.gif>");
// if(treeElmt.getActiveFlag() == Constants.ACTIVEFLAG_NO){
// content.append("<img src=/wbflow/images/folder1.gif><a
// href=\"javascript:goToMail(" + treeElmt.getID() + ")\" ");//????????????
// }else{
// content.append("<img src=/wbflow/images/folder.gif><a
// href=\"javascript:goToMail(" + treeElmt.getID() + ")\" ");//??????????
// }
// if (treeElmt.canExpand())//??????????????????showHide???
// content.append("ondblclick=\"showHide('" + treeElmt.getID() + "')\"");
// content.append(">" + treeElmt.getNodeName() + "</a>");
// if (treeElmt.canExpand()) {//???????????????UL??????????
// content.append("<ul");
// if (bHidden)
// content.append(" style=\"display:none;\" ");
// content.append(">");
// TreeviewElement[] elmts = treeElmt.getChildren();//???????????
// for (int i = 0; i < elmts.length; i++)
// content.append(renderStatic(elmts[i], bHidden));//?????????????
// content.append("</ul>");
// }
// content.append("</li>");//???????<li>???
// return content.toString();
// }
// public static String selectTree() throws SystemException {
// StringBuffer content = new StringBuffer();
//
// content.append("d = new dTree('d');");
// List<TreeView> tvList = new TreeViewDaoImpl().getAllTreeByParentId(1);
// for(int i =0 ; i < tvList.size();i++){
// if(tvList.get(i).getActiveFlag() == Constants.ACTIVEFLAG_NO){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "',\"javascript:selectPosition('" + tvList.get(i).getId() + "','" +
// OrgnMgr.getTreeOrgnList(tvList.get(i).getId()) + "')\");");
// }else{
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() + "');");
// }
// }
// content.append("document.write(d);");
// return content.toString();
// }
//
// public static String selectTree(int parentId, int flag) throws
// SystemException {
// StringBuffer content = new StringBuffer();
//
// content.append("d = new dTree('d');");
// if (parentId != 1) {
// TreeView root = TreeViewMgr.findById(parentId);
// if (root != null)
// content.append("d.add(" + root.getId() + ",1,'" + root.getName() +
// "','javascript:;');");
// }
// List<TreeView> tvList = new
// TreeViewDaoImpl().getAllTreeByParentId(parentId);
// for(int i =0 ; i < tvList.size();i++){
// if(tvList.get(i).getActiveFlag() == Constants.ACTIVEFLAG_NO){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "',\"javascript:selectPosition('" + tvList.get(i).getId() + "','" +
// OrgnMgr.getTreeOrgnList(tvList.get(i).getId()) + "')\");");
// }else{
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() + "');");
// }
// }
// content.append("document.write(d);");
// return content.toString();
// }
// public static String selectTree(TreeViewElement treeElmt, boolean
// bHidden) {
// StringBuffer content = new StringBuffer();
// content.append("<li id=" + treeElmt.getID() + ">");//???li???
// if (bHidden &&
// treeElmt.canExpand())//??????????????????????,?????????????????showHide???
// content.append("<img src=/wbflow/images/plus.gif onClick=\"showHide('"
// + treeElmt.getID() + "')\">");
// else if (treeElmt.canExpand())//?????????,?????????????????showHide???
// content.append("<img src=/wbflow/images/minus.gif onClick=\"showHide('"
// + treeElmt.getID() + "')\">");
// else//????????????
// content.append("<img src=/wbflow/images/blank.gif>");
// if(treeElmt.getActiveFlag() == Constants.ACTIVEFLAG_NO){
// content.append("<img src=/wbflow/images/folder1.gif><a
// href=\"javascript:selectPosition('" + treeElmt.getID() + "','" +
// treeElmt.getNodeName() + "')\" ");//??????????
// }else{
// content.append("<img src=/wbflow/images/folder.gif><a href=\"#\"
// ");//??????????
// }
// if (treeElmt.canExpand())//??????????????????showHide???
// content.append("onclick=\"showHide('" + treeElmt.getID() + "')\"");
// content.append(">" + treeElmt.getNodeName() + "</a>");
// if (treeElmt.canExpand()) {//???????????????UL??????????
// content.append("<ul");
// if (bHidden)
// content.append(" style=\"display:none;\" ");
// content.append(">");
// TreeViewElement[] elmts = treeElmt.getChildren();//???????????
// for (int i = 0; i < elmts.length; i++)
// content.append(selectTree(elmts[i], bHidden));//?????????????
// content.append("</ul>");
// }
// content.append("</li>");//???????<li>???
// return content.toString();
// }
// public static String selectTree(int isDept) {
// StringBuffer content = new StringBuffer();
//
// content.append("d = new dTree('d');");
// List<TreeView> tvList = new TreeViewDaoImpl().getAllTreeByParentId(1);
// for(int i =0 ; i < tvList.size();i++){
// if(tvList.get(i).getActiveFlag() == Constants.ACTIVEFLAG_NO){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "',\"javascript:selectPosition('" + tvList.get(i).getId() + "','" +
// tvList.get(i).getName() + "')\");");
// }else{
// if(isDept == Constants.IS_SELECT_DEPT_YES){
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() +
// "',\"javascript:selectPosition('" + tvList.get(i).getId() + "','" +
// tvList.get(i).getName() + "')\");");
// }else{
// content.append("d.add(" + tvList.get(i).getId() + "," +
// tvList.get(i).getParentId()+ ",'" + tvList.get(i).getName() + "');");
// }
// }
// }
// content.append("document.write(d);");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -