Package org.zkoss.zk.ui

Examples of org.zkoss.zk.ui.Component


   * @param includingEquals whether to return true if a equals B
   */
  private
  boolean isAncestor(Collection coll, Component comp, boolean includingEquals) {
    for (Iterator it = coll.iterator(); it.hasNext();) {
      final Component c = (Component)it.next();
      if ((includingEquals || c != comp) && Components.isAncestor(c, comp))
        return true;
    }
    return false;
  }
View Full Code Here


    //0. Correct the UUID at the client first
    if (_idChgd != null) {
      for (Iterator it = _idChgd.entrySet().iterator(); it.hasNext();) {
        final Map.Entry me = (Map.Entry)it.next();
        final Component comp = (Component)me.getKey();
        if (!_attached.contains(comp))
          responses.add(new AuUuid(comp, (String)me.getValue()));
      }
      _idChgd = null; //just in case
    }

    //1. process dead comonents, cropping and the removed page
    final Map croppingInfos;
    {
      //1a. handle _detached to remove unncessary detach
      doDetached();
        //after call, _detached is merged to _moved

      //1b. handle _moved
      //The reason to remove first: some insertion might fail if the old
      //componetns are not removed yet
      //Also, we have to remove both parent and child because, at
      //the client, they might not be parent-child relationship
      Set removed = doMoved(responses);
        //after called, _moved is cleared (add to _attached if necessary)
        //And, AuRemove is generated (we have to generate AuRemove first,
        //since UUID might be reused)

      //1c. remove reduntant
      removeRedundant(_invalidated);
      removeRedundant(_attached);
      removeCrossRedundant();

      //1d. process Cropper
      croppingInfos = doCrop();

      //1d. prepare removed pages and optimize for invalidate or removed pages
      checkPageRemoved(removed); //maintain _pgRemoved for pages being removed
    }

    //2. Process removed and invalid pages
    //2a. clean up _invalidated and others belonging to invalid pages
    if (_pgInvalid != null && _pgInvalid.isEmpty()) _pgInvalid = null;
    if (_pgRemoved != null && _pgRemoved.isEmpty()) _pgRemoved = null;
    if (_pgInvalid != null || _pgRemoved != null) {
      clearInInvalidPage(_invalidated);
      clearInInvalidPage(_attached);
      clearInInvalidPage(_smartUpdated.keySet());
    }

    //2b. remove pages. Note: we don't need to generate rm, becausee they
    //are included pages.
    if (_pgRemoved != null) {
      final DesktopCtrl dtctl = (DesktopCtrl)_exec.getDesktop();
      for (final Iterator it = _pgRemoved.iterator(); it.hasNext();)
        dtctl.removePage((Page)it.next());
    }

    //3. generate response for invalidated pages
    if (_pgInvalid != null) {
      for (final Iterator it = _pgInvalid.iterator(); it.hasNext();) {
        final Page page = (Page)it.next();
        responses.add(new AuOuter(page, redraw(page)));
      }
    }

/*    if (log.finerable())
      log.finer("After removing redudant: invalidated: "+_invalidated
      +"\nAttached: "+_attached+"\nSmartUpd:"+_smartUpdated);
*/
    //4. process special interfaces

    //5. generate replace for invalidated
    for (Iterator it = _invalidated.iterator(); it.hasNext();) {
      final Component comp = (Component)it.next();
      responses.add(new AuOuter(comp, redraw(comp)));
    }

    _ending = true; //no more addSmartUpdate...

    //6. add attached components (including setParent)
    //Due to cyclic references, we have to process all siblings
    //at the same time
    final List desktops = new LinkedList();
    final Component[] attached = (Component[])
      _attached.toArray(new Component[_attached.size()]);
    for (int j = 0; j < attached.length; ++j) {
      final Component comp = attached[j];
      //Note: attached comp might change from another page to
      //the one being created. In this case, no need to add
      if (comp != null) {
        final Page page = comp.getPage();
        if (page != null && _exec.isAsyncUpdate(page)) {
          final Component parent = comp.getParent();
          final Set newsibs = new LinkedHashSet(32);
          newsibs.add(comp);
          desktops.add(newsibs);

          for (int k = j + 1; k < attached.length; ++k) {
            final Component ck = attached[k];
            if (ck != null && ck.getParent() == parent) {
              newsibs.add(ck);
              attached[k] = null;
            }
          }
        }
View Full Code Here

   */
  private void doDetached() {
    l_out:
    for (Iterator it = _detached.entrySet().iterator(); it.hasNext();) {
      final Map.Entry me = (Map.Entry)it.next();
      Component p = (Component)me.getValue();
      for (;p != null; p = p.getParent())
        if (_moved.contains(p) || _detached.containsKey(p)
        || _invalidated.contains(p) || _attached.contains(p))
          continue l_out; //don't merge (ingore it)

      _moved.add(me.getKey()); //merge
View Full Code Here

   */
  private Set doMoved(List responses) {
    //Remove components that have to removed from the client
    final Set removed = new LinkedHashSet();
    for (Iterator it = _moved.iterator(); it.hasNext();) {
      final Component comp = (Component)it.next();
      final Page page = comp.getPage();
      if (page == null) {
        removed.add(comp);

        if (_responses != null) _responses.remove(comp);
        _invalidated.remove(comp);
View Full Code Here

   * parent is changed).
   */
  private static
  void addResponsesForCreatedPerSiblings(List responses, Set newsibs,
  Map croppingInfos) throws IOException {
    final Component parent;
    final Page page;
    {
      final Component comp = (Component)newsibs.iterator().next();
      parent = comp.getParent();
      page = comp.getPage();
    }
    Collection sibs;
    if (parent != null) {
      sibs = getAvailableAtClient(parent, croppingInfos);
      if (sibs == null) //no cropping
        sibs = parent.getChildren();
      else if (sibs.size() > 1 && !(sibs instanceof LinkedHashSet)) {
//        log.warning("Use LinkedHashSet instead of "+sibs.getClass());
        final Set s = new LinkedHashSet(sibs.size() * 2);
        for (Iterator it = parent.getChildren().iterator(); it.hasNext();) {
          final Object o = it.next();
          if (sibs.remove(o)) {
            s.add(o);
            if (sibs.isEmpty())
              break;
          }
        }
        sibs = s;
      }
    } else {
      sibs = page.getRoots();
    }
//    if (D.ON && log.finerable()) log.finer("All sibs: "+sibs+" newsibs: "+newsibs);

    /* Algorithm:
  1. Locate a sibling, say <a>, that already exists.
  2. Then, use AuInsertBefore for all sibling before <a>,
    and AuInsertAfter for all after anchor.
  3. If anchor is not found, use AuAppendChild for the first
    and INSERT_AFTER for the rest
    */
    final List before = new LinkedList();
    Component anchor = null;
    final ComponentCtrl parentCtrl = (ComponentCtrl)parent;
    final Object parentxc =
      parentCtrl != null ? parentCtrl.getExtraCtrl(): null;
    for (Iterator it = sibs.iterator(); it.hasNext();) {
      final Component comp = (Component)it.next();
      if (anchor != null) {
        if (newsibs.remove(comp)) {
          responses.add(new AuInsertAfter(anchor, redraw(comp)));
          if (newsibs.isEmpty())
            return; //done (all newsibs are processed)
          anchor = comp;
        } else {
          anchor = comp;
        }
      } else if (newsibs.remove(comp)) {
        before.add(comp)
      } else {
        //Generate before in the reverse order and INSERT_BEFORE
        anchor = comp;
        for (ListIterator i2 = before.listIterator(before.size());
        i2.hasPrevious();) {
          final Component c = (Component)i2.previous();
          responses.add(new AuInsertBefore(anchor, redraw(c)));
          anchor = c;
        }
        if (newsibs.isEmpty())
          return; //done (all newsibs are processed)
        anchor = comp;
      }
    }
    assert D.OFF || (anchor == null && newsibs.isEmpty()): "anchor="+anchor+" newsibs="+newsibs+" sibs="+sibs;

    //all siblings are changed (and none of them is processed)
    final Iterator it = before.iterator();
    if (it.hasNext()) {
      anchor = (Component)it.next();
      responses.add(
        parent != null ?
          new AuAppendChild(parent, redraw(anchor)):
          new AuAppendChild(page, redraw(anchor)));

      while (it.hasNext()) {
        final Component comp = (Component)it.next();
        responses.add(new AuInsertAfter(anchor, redraw(comp)));
        anchor = comp;
      }
    }
  }
View Full Code Here

  /** Removes redundant components (i.e., an descendant of another).
   */
  private static void removeRedundant(Set comps) {
    rudLoop:
    for (Iterator j = comps.iterator(); j.hasNext();) {
      final Component cj = (Component)j.next();
      for (Iterator k = comps.iterator(); k.hasNext();) {
        final Component ck = (Component)k.next();
        if (ck != cj && Components.isAncestor(ck, cj)) {
          j.remove();
          continue rudLoop;
        }
      }
View Full Code Here

   * and _attached.
   */
  private void removeCrossRedundant() {
    invLoop:
    for (Iterator j = _invalidated.iterator(); j.hasNext();) {
      final Component cj = (Component)j.next();

      for (Iterator k = _attached.iterator(); k.hasNext();) {
        final Component ck = (Component)k.next();
        if (Components.isAncestor(ck, cj)) { //includes ck == cj
          j.remove();
          continue invLoop;
        } else if (Components.isAncestor(cj, ck)) {
          k.remove();
        }
      }
    }
    suLoop:
    for (Iterator j = _smartUpdated.keySet().iterator(); j.hasNext();) {
      final Component cj = (Component)j.next();

      for (Iterator k = _invalidated.iterator(); k.hasNext();) {
        final Component ck = (Component)k.next();


        if (Components.isAncestor(ck, cj)) {
          j.remove();
          continue suLoop;
        }
      }
      for (Iterator k = _attached.iterator(); k.hasNext();) {
        final Component ck = (Component)k.next();
        if (Components.isAncestor(ck, cj)) {
          j.remove();
          continue suLoop;
        }
      }
View Full Code Here

   * include another page.
   * @return the previous owner
   * @since 5.0.0
   */
  public Component setOwner(Component comp) {
    Component old = _owner;
    _owner = comp;
    return old;
  }
View Full Code Here

 
  /** Load all value from data beans to UI components. */
  public void loadAll() {
    init();
    for (final Iterator it = _compBindingMap.keySet().iterator(); it.hasNext(); ) {
      final Component comp = (Component) it.next();
      loadComponent0(comp);
    }
  }
View Full Code Here

 
  /** Save all values from UI components to beans. */
  public void saveAll() {
    init();
    for (final Iterator it = _compBindingMap.keySet().iterator(); it.hasNext(); ) {
      final Component comp = (Component) it.next();
      saveComponent(comp);
    }
  }
View Full Code Here

TOP

Related Classes of org.zkoss.zk.ui.Component

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.