Exemplo n.º 1
0
  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();
    }
  }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public String getItemInnerHtml(DataRow dr) {
   StringBuffer sb = new StringBuffer();
   for (int j = 0; j < this.a1.size(); j++) {
     sb.append(this.a1.get(j));
     if (j < this.a2.size()) {
       sb.append(dr.getString(this.a2.get(j).toString()));
     }
   }
   return sb.toString();
 }
Exemplo n.º 4
0
 public static void treeDataBind(TreeAction ta) {
   String id = ta.getParam("ID");
   ZCFullTextSchema ft = new ZCFullTextSchema();
   ft.setID(id);
   if (XString.isEmpty(id)) {
     ta.getParams().put("CatalogType", OperateType.INSERT);
     Catalog.treeDataBind(ta);
   } else {
     ft.fill();
     if (!ft.getRelaText().equalsIgnoreCase("-1")) {
       ta.getParams().put("IDs", ft.getRelaText());
     }
   }
   if ("Article".equals(ta.getParam("Type"))) {
     ta.getParams().put("CatalogType", OperateType.INSERT);
     Catalog.treeDataBind(ta);
   }
   if ("Image".equals(ta.getParam("Type"))) {
     ta.getParams().put("CatalogType", 4);
     ImageLib.treeDataBind(ta);
   }
   if ("Video".equals(ta.getParam("Type"))) {
     ta.getParams().put("CatalogType", OperateType.DELETE_AND_BACKUP);
     VideoLib.treeDataBind(ta);
   }
   if ("Audio".equals(ta.getParam("Type"))) {
     ta.getParams().put("CatalogType", 6);
     AudioLib.treeDataBind(ta);
   }
   if ((ta.getDataSource() != null) && (XString.isEmpty(ta.getParam("ParentID")))) {
     DataTable dt = ta.getDataSource();
     dt.insertRow(new Object[dt.getColCount()], 0);
     dt.set(0, 0, "-1");
     dt.set(0, 1, "0");
     dt.set(0, 2, "1");
     dt.set(0, 3, "<font class='red'>全部</font>");
     DataRow dr = dt.getDataRow(0);
     TreeItem root = ta.getItem(0);
     TreeItem item = new TreeItem();
     item.setData(dr);
     item.setAction(ta);
     item.setID(dr.getString(ta.getIdentifierColumnName()));
     item.setParentID(root.getID());
     item.setLevel(root.getLevel() + 1);
     item.setParent(root);
     item.setIcon("Icons/treeicon09.gif");
     item.setLast(false);
     try {
       item.parseHtml(ta.getItemInnerHtml(dr));
     } catch (Exception e) {
       e.printStackTrace();
     }
     ta.getItemList().add(1, item);
     if ("Article".equals(ta.getParam("Type"))) {
       List items = ta.getItemList();
       for (int i = 1; i < items.size(); i++) {
         item = (TreeItem) items.get(i);
         if ("Y".equals(item.getData().getString("SingleFlag")))
           item.setIcon("Icons/treeicon11.gif");
       }
     }
   }
 }
Exemplo n.º 5
0
  private static String getColumn(DataRow dr, ZDMemberSchema member, String realField) {
    String columnName = dr.getString("Name");
    String columnCode = dr.getString("Code");
    String inputType = dr.getString("InputType");
    String verifyType = dr.getString("VerifyType");
    String listOption = dr.getString("ListOption");
    String defaultValue = dr.getString("DefaultValue");
    String isMandatory = dr.getString("IsMandatory");
    String maxLength = dr.getString("MaxLength");
    String HTML = dr.getString("HTML");
    String verifyStr = "verify='" + columnName + "|";
    if ("Y".equals(isMandatory)) {
      verifyStr = verifyStr + "NotNull";
    }
    if (!STRING.equals(verifyType)) {
      if (NUMBER.equals(verifyType)) verifyStr = verifyStr + "&&Number";
      else if (INT.equals(verifyType)) verifyStr = verifyStr + "&&Int";
      else if (EMAIL.equals(verifyType)) verifyStr = verifyStr + "&&Email";
    }
    if ((XString.isNotEmpty(maxLength)) && (!"0".equals(maxLength)))
      verifyStr = verifyStr + "&&Length<" + maxLength + "'";
    else {
      verifyStr = verifyStr + "'";
    }

    if ((member != null) && (realField != null)) {
      Mapx map = member.toMapx();
      defaultValue = map.getString(realField);
      if (XString.isEmpty(defaultValue)) {
        defaultValue = "";
      }
    }

    columnCode = "_MC_" + columnCode;
    StringBuffer sb = new StringBuffer();
    sb.append("<tr><td height='25' align='right' >");
    sb.append(columnName);
    sb.append(":</td><td align='left' >");

    if (inputType.equals(Input)) {
      sb.append(
          "<input type='text' size='26' id='"
              + columnCode
              + "' name='"
              + columnCode
              + "' value='"
              + defaultValue
              + "' "
              + verifyStr
              + " />");
    }

    if (inputType.equals(Text)) {
      sb.append(
          "<textarea style='width:"
              + dr.getString("ColSize")
              + "px;height:"
              + dr.getString("RowSize")
              + "px' id='"
              + columnCode
              + "' name='"
              + columnCode
              + "' "
              + verifyStr
              + ">"
              + defaultValue
              + "</textarea>");
    }

    if (inputType.equals(Selecter)) {
      SelectTag select = new SelectTag();
      select.setId(columnCode);
      if ("Y".equals(isMandatory)) {
        select.setVerify(columnName + "|NotNull");
      }
      String[] array = listOption.split("\\n");
      sb.append(select.getHtml(HtmlUtil.arrayToOptions(array, defaultValue, true)));
    }

    if (inputType.equals(Radio)) {
      String[] array = listOption.split("\\n");
      if ((XString.isEmpty(defaultValue)) && (array.length > 0)) {
        defaultValue = array[0];
      }
      sb.append(HtmlUtil.arrayToRadios(columnCode, array, defaultValue));
    }

    if (inputType.equals(Checkbox)) {
      String[] array = listOption.split("\\n");
      defaultValue = defaultValue.replaceAll("  ", ",");
      defaultValue = defaultValue.replaceAll(" ", ",");
      defaultValue = defaultValue.replaceAll("  ", ",");
      defaultValue = defaultValue.replaceAll(" ", ",");
      defaultValue = defaultValue.replaceAll(",,", ",");
      defaultValue = defaultValue.replaceAll(",,", ",");
      defaultValue = defaultValue.replaceAll(",", ",");
      String[] checkedArray = defaultValue.split(",");
      sb.append(HtmlUtil.arrayToCheckboxes(columnCode, array, checkedArray));
    }

    if (inputType.equals(DateInput)) {
      sb.append(
          "<input name='"
              + columnCode
              + "' id='"
              + columnCode
              + "' value='"
              + defaultValue
              + "' type='text'  size='20' xtype='Date' "
              + verifyStr
              + " />");
    }

    if (inputType.equals(TimeInput)) {
      sb.append(
          "<input name='"
              + columnCode
              + "' id='"
              + columnCode
              + "' value='"
              + defaultValue
              + "' type='text' size='10' xtype='Time' "
              + verifyStr
              + " />");
    }

    if (inputType.equals(HTMLInput)) {
      sb.append(HTML);
    }
    sb.append("</td></tr>");
    return sb.toString();
  }