예제 #1
0
파일: Treechildren.java 프로젝트: dije/zk
 /**
  * Returns the number of child {@link Treeitem} including all descendants. The same as {@link
  * #getItems}.size().
  *
  * <p>Note: the performance is no good.
  */
 public int getItemCount() {
   int sz = 0;
   for (Iterator it = getChildren().iterator(); it.hasNext(); ++sz) {
     final Treeitem item = (Treeitem) it.next();
     final Treechildren tchs = item.getTreechildren();
     if (tchs != null) sz += tchs.getItemCount();
   }
   return sz;
 }
예제 #2
0
    @Override
    public void onEvent(Event event) throws Exception {
      try {
        if (node == null) return;

        // 过滤不需要处理的节点
        Treechildren mytreechildren = treeitem.getTreechildren();
        // 无子节点或者是处于收缩状态的节点
        if (mytreechildren == null
            || mytreechildren.getChildren().size() > 0
            || treeitem.isOpen() == false) return;
        // 是监测器节点的情况
        if (INode.MONITOR.equals(node.getType())) {
          return;
        }

        List<EccTreeItem> sons = node.getChildRen();
        // 查找其儿子
        if (sons != null && sons.size() > 0) {

          for (EccTreeItem son : sons) {
            if (son == null) continue;
            // 如果是监视器 -- 页节点
            if (INode.ENTITY.equals(son.getType())) {
              if (this.tree.getMonitorType() != null) {
                //								MonitorInfo monitorinfo =
                // this.tree.getTreemodel().getView().getMonitorInfo(son.getValue());
                EntityInfo entityInfo =
                    this.tree.getTreemodel().getView().getEntityInfo(son.getValue());
                if (!this.tree.getMonitorType().equals(entityInfo.getType())) {
                  continue;
                }
              }
              BaseTreeitem tii = getTreeitem(son);
              tii.setParent(mytreechildren);
            } else {
              if (existChildren(son)) {
                // 如果存在儿子
                BaseTreeitem tii = getTreeitem(son);
                tii.setParent(mytreechildren);
                Treechildren newtreechildren = new Treechildren();
                tii.appendChild(newtreechildren); // 给以可以展开的属性
                tii.addEventListener(
                    Events.ON_OPEN, new TreeitemOpenListener(tii, this.tree)); // 添加展开事件
              }
            }
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
        Messagebox.show(e.getMessage(), "错误", Messagebox.OK, Messagebox.ERROR);
      }
    }
예제 #3
0
  private void open(int level) {
    Treechildren treechildren = this.getTreechildren();

    for (int mylevel = 0; mylevel < level; mylevel++) {
      for (Object object : treechildren.getItems()) {
        if (object instanceof Treeitem) {
          Treeitem item = (Treeitem) object;
          item.setOpen(true);
          Events.sendEvent(item, new Event(Events.ON_OPEN, item));
          treechildren = item.getTreechildren();
          if (treechildren == null || treechildren.getChildren().size() == 0) {
            continue;
          }
          break;
        }
      }
    }
  }
예제 #4
0
  private void initTree(String virtualName) {
    // 取得view
    this.treemodel =
        EccTreeModel.getInstanceForAlertByViewName(getDesktop().getSession(), virtualName);
    this.treemodel.setDisplayMonitor(true);

    // 清除树里的节点
    clearTree();

    Treechildren treechildren = this.getTreechildren();
    treechildren.setParent(this);

    EccTreeItem root = this.treemodel.getRoot();
    if (root == null) return;

    // 缺省视图的时候,取第一个根
    if (VirtualView.DefaultView.equals(virtualName) || virtualName == null) {
      for (EccTreeItem item : root.getChildRen()) {
        root = item;
        break;
      }
    }

    // 显示第一层节点
    for (EccTreeItem item : root.getChildRen()) {
      try {
        BaseTreeitem ti = getTreeitem(item);
        ti.setParent(treechildren);
        if (existChildren(item)) {
          // 存在子节点,则添加可展开属性和展开事件
          Treechildren mytreechildren = new Treechildren();
          ti.appendChild(mytreechildren);
          ti.addEventListener(Events.ON_OPEN, new TreeitemOpenListener(ti, this));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    // 展开节点,如果是缺省视图,展开第一层
    if (VirtualView.DefaultView.equals(virtualName) || virtualName == null) {
      this.open(1);
    }
  }
예제 #5
0
 /**
  *
  * <li>功能描述:将树节点展开。
  *
  * @param chi void
  * @author DaLei
  */
 @SuppressWarnings("unchecked")
 private void openTree(Treechildren chi) {
   if (chi == null) return;
   List<Treeitem> tlist = chi.getChildren();
   for (int i = 0; i < tlist.size(); i++) {
     Treeitem item = (Treeitem) tlist.get(i);
     item.setOpen(true);
     openTree(item.getTreechildren());
   }
 }
예제 #6
0
 /**
  *
  * <li>功能描述:将树节点展开并默认打开某个部门用户。
  *
  * @param chi
  * @param dept void
  * @author DaLei
  */
 @SuppressWarnings("unchecked")
 private void openTree(Treechildren chi, WkTDept dept) {
   if (chi == null) return;
   List<Treeitem> tlist = chi.getChildren();
   for (int i = 0; i < tlist.size(); i++) {
     Treeitem item = (Treeitem) tlist.get(i);
     WkTDept d = (WkTDept) item.getValue();
     if (d.getKdId().intValue() == dept.getKdId().intValue()) {
       tree.setSelectedItem(item);
       if (uWindow == null) {
         openListWindow(d);
       } else {
         uWindow.initWindow(d);
       }
     }
     if (d.getKdLevel() == WkTDept.GRADE_SCH.intValue()) item.setOpen(true);
     else item.setOpen(false);
     openTree(item.getTreechildren(), dept);
   }
 }
예제 #7
0
  /** ************************************************************************************* */
  public void buildTreePorDemanda(
      Treechildren tree,
      List<MyItemTree> listaDatos,
      String etiqueta,
      String consulta,
      String ids,
      boolean treeItemRenderMovimiento)
      throws Exception {
    log.info(
        "Ejecutando metodo [ buildTree("
            + tree.getId()
            + ", No. Reg: "
            + listaDatos.size()
            + ") ]... ");

    Treechildren raiz = new Treechildren();
    tree.getChildren().clear();

    Treeitem ti = new Treeitem();
    Treerow tr = new Treerow();
    Treecell tcValor = new Treecell("");
    Treecell tcPadre = new Treecell("");
    Treecell tcNivel = new Treecell("0");
    Treecell tcLlave = new Treecell("0");
    Treecell tcEtiqueta = new Treecell(etiqueta);
    Treecell tcMovimiento = new Treecell("");
    Treecell tcIncluyeExcluye = new Treecell("");
    tcIncluyeExcluye.setVisible(false);
    tcMovimiento.setVisible(false);

    tr.setAttribute("valor", "");
    tr.setAttribute("padre", "");
    tr.setAttribute("nivel", 0);
    tr.setAttribute("llave", 0);
    tr.setAttribute("movimiento", "");
    tr.setAttribute("parametros", "");

    tr.appendChild(tcEtiqueta);
    tr.appendChild(tcValor);
    tr.appendChild(tcPadre);
    tr.appendChild(tcNivel);
    tr.appendChild(tcLlave);
    tr.appendChild(tcMovimiento);
    tr.appendChild(tcIncluyeExcluye);

    ti.appendChild(tr);
    ti.appendChild(raiz);
    tree.appendChild(ti);

    log.info("EDITAR : " + treeItemRenderMovimiento);

    for (final MyItemTree itemTree : listaDatos) {
      log.info("PARAMETROS : " + itemTree.getParametros());

      tcEtiqueta = new Treecell(itemTree.getEtiqueta());
      tcEtiqueta.setTooltiptext(itemTree.getEtiqueta());

      if (itemTree.getOtherValue() != null && itemTree.getOtherValue().toString().equals("N")) {
        tcEtiqueta.setStyle("color:#BDBDBD;font-weight: bold");
      }

      tcValor = new Treecell(itemTree.getValor() != null ? itemTree.getValor().trim() : null);
      tcPadre = new Treecell(itemTree.getPadre() != null ? itemTree.getPadre().trim() : null);
      tcNivel = new Treecell(itemTree.getNivel().toString());
      tcLlave = new Treecell(itemTree.getId() != null ? itemTree.getId().trim() : null);
      tcMovimiento =
          new Treecell(
              itemTree.getOtherValue() != null ? itemTree.getOtherValue().toString() : null);
      tcMovimiento.setVisible(false);
      tcIncluyeExcluye =
          new Treecell(itemTree.getParametros() != null ? itemTree.getParametros() : null);
      tcIncluyeExcluye.setVisible(false);

      tr = new Treerow();
      tr.setAttribute("valor", itemTree.getValor());
      tr.setAttribute("padre", itemTree.getPadre());
      tr.setAttribute("nivel", itemTree.getNivel());
      tr.setAttribute("llave", itemTree.getId());
      tr.setAttribute("movimiento", itemTree.getOtherValue());
      tr.setAttribute("parametros", itemTree.getParametros());

      if (itemTree.getParametros() != null) {
        if (itemTree.getParametros().equals("I")) {
          tr.setStyle("background-color:#E3F6CE");

        } else if (itemTree.getParametros().equals("E")) {
          tr.setStyle("background-color:#F6CECE");
        }
      }

      if (!treeItemRenderMovimiento) { // valida si se debe habilitar o no el componente
                                       // dragdroptree
        tr.setDroppable("true");
        tr.setDraggable("true");
      }

      tr.appendChild(tcEtiqueta);
      tr.appendChild(tcValor);
      tr.appendChild(tcPadre);
      tr.appendChild(tcNivel);
      tr.appendChild(tcLlave);
      tr.appendChild(tcMovimiento);
      tr.appendChild(tcIncluyeExcluye);

      ti = new Treeitem();
      ti.setAttribute("Consulta", consulta);
      ti.setAttribute("grupo", tree.getAttribute("grupo"));
      ti.setId(ids + itemTree.getId());
      ti.appendChild(tr);
      raiz.appendChild(ti);

      if (itemTree.getNumeroDescendientes() > 0) {
        cargarHijosTreePorDemanda(ti, itemTree.getId(), ids, treeItemRenderMovimiento);
      }
    }
  }
예제 #8
0
  public Treeitem cargarHijosTreePorDemanda(
      Treechildren padre, String[] sec, String ids, boolean treeItemRenderMovimiento)
      throws Exception {
    log.info("Ejecutando el metodo [Treeitem cargarHijosTreePorDemanda...]");

    Component itemSelected = null;
    List<Component> listItem = padre.getChildren();
    Map<String, Object> parameter = new HashMap<String, Object>();
    parameter.put("GRUPO", padre.getAttribute("grupo").toString());
    if (sec != null) {
      List<Component> arbol =
          ((Treechildren) ((Treeitem) listItem.get(0)).getChildren().get(1)).getChildren();
      for (int i = (sec.length - 1); i > 0; i--) {
        for (Component itemTree : arbol) {
          if (itemTree.getId().trim().equals(ids + sec[i])) {
            if (i == 1) {
              ((Treeitem) itemTree).setSelected(true);
              itemSelected = itemTree;
              break;
            } else {
              parameter.put("PADRE", sec[i]);
              List<MyItemTree> listaHijos =
                  (List<MyItemTree>)
                      ParametrizacionFac.getFacade()
                          .obtenerListado(itemTree.getAttribute("Consulta").toString(), parameter);
              Treechildren tchil = (Treechildren) itemTree.getChildren().get(1);
              tchil.getChildren().clear();
              for (MyItemTree myItemTree : listaHijos) {
                Treeitem tiHijo = new Treeitem();
                Treerow trow = new Treerow();
                Treecell tcEti = new Treecell(myItemTree.getEtiqueta());

                if (!treeItemRenderMovimiento) { // valida si se debe habilitar o no el componente
                                                 // dragdroptree
                  trow.setDroppable("true");
                  trow.setDraggable("true");
                }
                if (myItemTree.getParametros() != null) {
                  if (myItemTree.getParametros().equals("I")) {
                    trow.setStyle("background-color:#E3F6CE");

                  } else if (myItemTree.getParametros().equals("E")) {
                    trow.setStyle("background-color:#F6CECE");
                  }
                }
                if (myItemTree.getOtherValue() != null
                    && myItemTree.getOtherValue().toString().equals("N")) {
                  tcEti.setStyle("color:#BDBDBD;font-weight: bold");
                }

                tcEti.setTooltiptext(myItemTree.getEtiqueta());
                trow.appendChild(tcEti);
                trow.appendChild(
                    new Treecell(
                        myItemTree.getValor() != null ? myItemTree.getValor().trim() : null));
                trow.appendChild(
                    new Treecell(
                        myItemTree.getPadre() != null ? myItemTree.getPadre().trim() : null));
                trow.appendChild(new Treecell(myItemTree.getNivel().toString()));
                trow.appendChild(
                    new Treecell(myItemTree.getId() != null ? myItemTree.getId().trim() : null));
                trow.appendChild(
                    new Treecell(
                        myItemTree.getOtherValue() != null
                            ? myItemTree.getOtherValue().toString().trim()
                            : null));
                trow.appendChild(
                    new Treecell(
                        myItemTree.getParametros() != null
                            ? myItemTree.getParametros().trim()
                            : null));

                trow.setAttribute("valor", myItemTree.getValor());
                trow.setAttribute("padre", myItemTree.getPadre());
                trow.setAttribute("nivel", myItemTree.getNivel());
                trow.setAttribute("llave", myItemTree.getId());
                trow.setAttribute("movimiento", myItemTree.getOtherValue());
                trow.setAttribute("parametros", myItemTree.getParametros());

                tiHijo.appendChild(trow);
                tiHijo.setId(ids + myItemTree.getId());
                tiHijo.setAttribute("Consulta", itemTree.getAttribute("Consulta"));
                tiHijo.setAttribute("grupo", itemTree.getAttribute("grupo"));
                if (padre.hasFellow(ids + myItemTree.getId()))
                  padre.getFellow(ids + myItemTree.getId());
                tchil.appendChild(tiHijo);
                if (myItemTree.getNumeroDescendientes() > 0) {
                  cargarHijosTreePorDemanda(
                      tiHijo, myItemTree.getId(), ids, treeItemRenderMovimiento);
                }
              }
              ((Treeitem) itemTree).setOpen(true);
              arbol = ((Treechildren) itemTree.getChildren().get(1)).getChildren();
              break;
            }
          }
        }
      }
    } else {
      itemSelected = (Treeitem) listItem.get(0);
      ((Treeitem) listItem.get(0)).setSelected(true);
    }
    return ((Treeitem) itemSelected);
  }