Beispiel #1
0
 private Listgroup newListgroup(ListitemRenderer renderer) {
   Listgroup group = null;
   if (renderer instanceof ListgroupRendererExt)
     group = ((ListgroupRendererExt) renderer).newListgroup(_listbox);
   if (group == null) {
     group = new Listgroup();
     group.applyProperties();
   }
   return group;
 }
Beispiel #2
0
  public void setMultiple(Listgroup group, boolean value) {
    for (Iterator<Listitem> it = group.getItems().iterator(); it.hasNext(); ) {
      Listitem item = it.next();
      if (((Listcell) item.getFirstChild()).getFirstChild() != null) {
        item.setSelected(value);
        ((Checkbox) ((Listcell) item.getFirstChild()).getFirstChild()).setChecked(value);
        habilitarButtons(!value);
      }
    }

    if (idZBtnDuplicar != null) {
      if (((Checkbox) group.getFirstChild().getFirstChild()).isChecked())
        idZBtnDuplicar.setDisabled(true);
    }
  }
Beispiel #3
0
  /** Creates an new and unloaded listitem. */
  protected final Listitem newUnloadedItem(ListitemRenderer renderer, int index) {
    final ListModel model = _listbox.getModel();
    Listitem item = null;
    if (model instanceof GroupsListModel) {
      final GroupsListModel gmodel = (GroupsListModel) model;
      final GroupDataInfo info = gmodel.getDataInfo(index);
      switch (info.type) {
        case GroupDataInfo.GROUP:
          item = newListgroup(renderer);
          ((Listgroup) item).setOpen(!info.close);
          break;
        case GroupDataInfo.GROUPFOOT:
          item = newListgroupfoot(renderer);
          break;
        default:
          item = newListitem(renderer);
      }
    } else {
      item = newListitem(renderer);
    }
    ((LoadStatus) item.getExtraCtrl()).setLoaded(false);
    ((LoadStatus) item.getExtraCtrl()).setIndex(index);

    newUnloadedCell(renderer, item);
    return item;
  }
Beispiel #4
0
  public void setSelected(Listgroup group, Checkbox check) {
    int i = 0;
    for (Iterator<Listitem> it = group.getItems().iterator(); it.hasNext(); ) {
      Checkbox c = ((Checkbox) ((Listcell) (it.next()).getFirstChild()).getFirstChild());
      if (c.isChecked()) i++;
    }
    if (i == group.getItems().size()) {
      check.setChecked(true);
      habilitarButtons(false);
    } else if (i < group.getItems().size() && i != 0) {
      check.setChecked(false);
      habilitarButtons(false);
    } else if (i == 0) {
      check.setChecked(false);
      habilitarButtons(true);
    }

    if (idZBtnDuplicar != null) {
      if (i == 1) idZBtnDuplicar.setDisabled(false);
      else idZBtnDuplicar.setDisabled(true);
    }
  }
Beispiel #5
0
  /**
   * Retrieves the children available at the client within the given range.
   *
   * @param itemOnly whether to return only {@link Listitem} and derives.
   * @since 5.0.10
   */
  protected Set<? extends Component> getAvailableAtClient(int offset, int limit, boolean itemOnly) {
    if (!isCropper()) return null;

    final Set<Component> avail = new LinkedHashSet<Component>(32);
    if (!itemOnly) {
      avail.addAll(_listbox.getHeads());
      final Listfoot listfoot = _listbox.getListfoot();
      if (listfoot != null) avail.add(listfoot);
      final Paging paging = _listbox.getPagingChild();
      if (paging != null) avail.add(paging);
      final Frozen frozen = _listbox.getFrozen();
      if (frozen != null) avail.add(frozen);
    }

    int pgsz = limit;
    int ofs = offset;
    if (_listbox.getItemCount() > 0) {
      Component item = _listbox.getItems().get(0);
      while (item != null) {
        if (pgsz == 0) break;
        if (item.isVisible() && item instanceof Listitem) {
          if (--ofs < 0) {
            --pgsz;
            avail.add(item);
          }
        }
        if (item instanceof Listgroup) {
          final Listgroup g = (Listgroup) item;
          if (!g.isOpen()) {
            for (int j = 0, len = g.getItemCount(); j < len; j++)
              item = (Listitem) item.getNextSibling();
          }
        }
        if (item != null) item = item.getNextSibling();
      }
    }
    return avail;
  }
Beispiel #6
0
  public void render(final Listitem item, final Object data, final int index) throws Exception {
    final Listbox listbox = (Listbox) item.getParent();
    final int size = listbox.getModel().getSize();
    // B70-ZK-2555: in order to handle dynamic template name
    final String subtype =
        item instanceof Listgroup ? "group" : item instanceof Listgroupfoot ? "groupfoot" : null;
    final Template tm = resolveTemplate(listbox, item, data, index, size, "model", subtype);
    if (tm == null) {
      item.setLabel(Objects.toString(data));
      item.setValue(data);
    } else {
      final ForEachStatus iterStatus =
          new AbstractForEachStatus() { // provide iteration status in this context
            private static final long serialVersionUID = 1L;

            public int getIndex() {
              return index;
            }

            public Object getCurrent() {
              return data;
            }

            public Integer getEnd() {
              return size;
            }
          };

      final String var = (String) tm.getParameters().get(EACH_ATTR);
      final String varnm = var == null ? EACH_VAR : var; // var is not specified, default to "each"
      final String itervar = (String) tm.getParameters().get(STATUS_ATTR);
      final String itervarnm =
          itervar == null
              ? (var == null ? EACH_STATUS_VAR : varnm + STATUS_POST_VAR)
              : itervar; // provide default value if not specified

      // bug 1188, EL when nested var and itervar
      Object oldVar = listbox.getAttribute(varnm);
      Object oldIter = listbox.getAttribute(itervarnm);
      listbox.setAttribute(varnm, data);
      listbox.setAttribute(itervarnm, iterStatus);

      final Component[] items = filterOutShadows(listbox, tm.create(listbox, item, null, null));

      // Bug ZK-2789: do not use setAttribute when actually trying to removeAttribute
      if (oldVar != null) {
        listbox.setAttribute(varnm, oldVar);
      } else {
        listbox.removeAttribute(varnm);
      }
      if (oldIter != null) {
        listbox.setAttribute(itervarnm, oldIter);
      } else {
        listbox.removeAttribute(itervarnm);
      }

      if (items.length != 1)
        throw new UiException("The model template must have exactly one item, not " + items.length);

      final Listitem nli = (Listitem) items[0];
      nli.setAttribute(BinderCtrl.VAR, varnm); // for the converter to get the value

      // ZK-2552
      recordRenderedIndex(listbox, items.length);
      nli.setAttribute(AbstractRenderer.IS_TEMPLATE_MODEL_ENABLED_ATTR, true);

      nli.setAttribute(
          AbstractRenderer.CURRENT_INDEX_RESOLVER_ATTR,
          new IndirectBinding() {
            public Binder getBinder() {
              return BinderUtil.getBinder(nli, true);
            }

            @SuppressWarnings("unchecked")
            public void setValue(BindELContext ctx, Object value) {
              int idx = BindListitemRenderer.this.getRenderedIndex(listbox, nli.getIndex());
              ListModel<?> listmodel = listbox.getListModel();
              if (idx >= 0 && idx < listmodel.getSize()) {
                if (listmodel instanceof ListModelArray) {
                  ((ListModelArray<Object>) listmodel).set(idx, value);
                } else if (listmodel instanceof ListModelList<?>) {
                  ((ListModelList<Object>) listmodel).set(idx, value);
                }
              } else {
                // out of range, should ignore to compatible with old version(when we didn't
                // implement save) or throw exception?
              }
            }

            public Component getComponent() {
              return nli;
            }

            public Object getValue(BindELContext ctx) {
              return listbox
                  .getModel()
                  .getElementAt(
                      BindListitemRenderer.this.getRenderedIndex(listbox, nli.getIndex()));
            }
          });
      addItemReference(
          listbox, nli, index, varnm); // kept the reference to the data, before ON_BIND_INIT

      nli.setAttribute(itervarnm, iterStatus);

      // sync open state
      if (nli instanceof Listgroup && item instanceof Listgroup) {
        ((Listgroup) nli).setOpen(((Listgroup) item).isOpen());
      }

      // ZK-1787 When the viewModel tell binder to reload a list, the other component that bind a
      // bean in the list will reload again
      // move TEMPLATE_OBJECT (was set in resoloveTemplate) to current for check in
      // addTemplateTracking
      Object obj = item.removeAttribute(TemplateResolver.TEMPLATE_OBJECT);
      // Bug ZK-2789: do not use setAttribute when actually trying to removeAttribute
      if (obj != null) {
        nli.setAttribute(TemplateResolver.TEMPLATE_OBJECT, obj);
      } else {
        nli.removeAttribute(TemplateResolver.TEMPLATE_OBJECT);
      }

      // add template dependency
      addTemplateTracking(listbox, nli, data, index, size);

      if (nli.getValue() == null) // template might set it
      nli.setValue(data);
      item.setAttribute(Attributes.MODEL_RENDERAS, nli);
      // indicate a new item is created to replace the existent one
      item.detach();
    }
  }