private void bindData() throws Exception { if (this.DataSource == null) { throw new RuntimeException("必须在bindData方法中设定DataSource"); } this.items.clear(); this.root = new TreeItem(); this.root.setID("_TreeRoot"); this.root.setParentID(""); this.root.setRoot(true); this.root.setText(this.rootText); this.root.setAction(this); this.root.setLevel(0); this.root.setAttribute("onMouseOver", this.onMouseOver); this.root.setAttribute("onContextMenu", this.onContextMenu); this.root.setAttribute("onClick", this.onClick); this.root.setAttribute("onMouseOut", this.onMouseOut); this.items.add(this.root); Mapx map = new Mapx(); for (int i = 0; i < this.DataSource.getRowCount(); i++) map.put( this.DataSource.getString(i, this.IdentifierColumnName), this.DataSource.getString(i, this.ParentIdentifierColumnName)); try { TreeItem last = null; for (int i = 0; i < this.DataSource.getRowCount(); i++) { DataRow dr = this.DataSource.getDataRow(i); String parentID = dr.getString(this.ParentIdentifierColumnName); if ((XString.isEmpty(parentID)) || (!map.containsKey(parentID))) { TreeItem item = new TreeItem(); item.setData(dr); item.parseHtml(getItemInnerHtml(dr)); item.setAction(this); item.setID(dr.getString(this.IdentifierColumnName)); item.setParentID(parentID); if (this.lazyLoad) { item.setLevel(this.parentLevel + 1); item.setLevelStr((String) getParams().get("LevelStr")); } else { item.setLevel(1); } item.setParent(this.root); this.items.add(item); addChild(item); last = item; } } if (last != null) last.setLast(true); } catch (Exception e) { e.printStackTrace(); } }
public static long getCurrentSiteID() { String id = (String) User.getValue("_CurrentSiteID"); if (XString.isEmpty(id)) { if ("admin".equals(User.getUserName())) { LogUtil.error("请在站点管理->站点列表下先创建站点"); return 0L; } LogUtil.error("用户:" + User.getUserName() + "没有任何站点的浏览权限,请先设置权限再登陆"); return 0L; } return Long.parseLong(id); }
public void addChild(TreeItem parent) throws Exception { boolean childFlag = false; TreeItem last = null; int index = -1; for (int i = this.items.size() - 1; i >= 0; i--) { if (this.items.get(i) == parent) { index = i; break; } } ArrayList list = new ArrayList(); for (int i = 0; i < this.DataSource.getRowCount(); i++) { DataRow dr = this.DataSource.getDataRow(i); String pid = dr.getString(this.ParentIdentifierColumnName); String id = dr.getString(this.IdentifierColumnName); if ((parent.getID().equals(pid)) && (!XString.isEmpty(id)) && (!id.equals(pid))) { childFlag = true; if ((parent.getLevel() >= this.level) && ((!this.lazyLoad) || (!this.expand))) { parent.setLazy(this.lazy); parent.setExpanded(false); parent.setBranch(childFlag); return; } TreeItem item = new TreeItem(); item.setData(dr); item.parseHtml(getItemInnerHtml(dr)); item.setAction(this); item.setID(dr.getString(this.IdentifierColumnName)); item.setParentID(parent.getID()); item.setLevel(parent.getLevel() + 1); item.setParent(parent); if (this.lazyLoad) { item.setLevelStr((String) getParams().get("LevelStr")); } list.add(item); this.items.add(index + list.size(), item); last = item; } } for (int i = 0; i < list.size(); i++) { addChild((TreeItem) list.get(i)); } if (last != null) { last.setLast(true); } if ((!this.lazy) && (parent.getLevel() + 1 == this.level)) { parent.setExpanded(false); } parent.setBranch(childFlag); }
public static void setCurrentSiteID(String siteID) { if (XString.isEmpty(siteID)) User.setValue("_CurrentSiteID", ""); else User.setValue("_CurrentSiteID", siteID); }