Package org.zkoss.zk.ui

Examples of org.zkoss.zk.ui.Component


      //setup all added bindings
      final Set varnameSet = new HashSet();
      final LinkedHashSet toBeDetached = new LinkedHashSet();
      for(final Iterator it = _compBindingMap.entrySet().iterator(); it.hasNext(); ) {
        final Entry me = (Entry) it.next();
        final Component comp = (Component) me.getKey();
        final Map attrMap = (Map) me.getValue();
        final Collection bindings = attrMap.values();
       
        //_var special case; meaning a template component
        if (attrMap.containsKey("_var")) {
          comp.setAttribute(ITEM, comp);
          final Component owner = getComponentCollectionOwner(comp);
          //bug#1888911 databind and Grid in Grid not work when no _var in inner Grid
          owner.setAttribute(IAMOWNER, Boolean.TRUE);
          setupTemplateComponent(comp, owner); //setup as template components
          String varname = ((Binding)attrMap.get("_var")).getExpression();
          varnameSet.add(varname);
          comp.setAttribute(VARNAME, varname);
          setupBindingRenderer(comp); //setup binding renderer
          toBeDetached.add(comp);
        }

        if (bindings != null) {
          //construct the path dependant tree
          setupPathTree(bindings, varnameSet);
       
          //register save-when event
          registerSaveEvents(comp, bindings);
         
          //register load-when events
          registerLoadEvents(comp, bindings);
        }
      }
           
      //detach template components so they will not interfer the visual part
      for(final Iterator it = toBeDetached.iterator(); it.hasNext(); ) {
        final Component comp = (Component) it.next();
        comp.detach();
      }
    }
  }
View Full Code Here


 
  /** Returns the value of the {@link Label} it contains, or null
   * if no such cell.
   */
  public String getLabel() {
    final Component cell = getFirstChild();
    return cell != null && cell instanceof Label ? ((Label)cell).getValue(): null;
  }
View Full Code Here

  //since 3.1
  //get associated clone components of a given bean and template component
  //note that same bean can be used in multiple components
  //assume comp is template component
  private Component[] getCollectionItems(Component comp, Object bean, boolean isCollectionItem) {
    Component owner = getCollectionOwner(comp);
    Component item = (Component) comp.getAttribute(DataBinder.ITEM);
    //For backward compatible, if by owner failed, try again with by item
    CollectionItem decor = myGetCollectionItemByOwner(owner);
    if (decor == null) {
      decor = getBindingCollectionItem(item);
    }
    final ListModel xmodel = decor.getModelByOwner(owner);
    if (isCollectionItem && comp == item) {
        if (xmodel instanceof BindingListModelExt && !((BindingListModelExt)xmodel).isDistinct()) {
          final BindingListModelExt model = (BindingListModelExt) xmodel;
          final int[] indexes = model.indexesOf(bean);
          final int sz = indexes.length;
          final List comps = new ArrayList(sz);
          for (int j = 0; j < sz; ++j) {
            final Component xcomp = lookupClone(decor.getComponentAtIndexByOwner(owner, indexes[j]), comp);
            if (xcomp != null)
              comps.add(xcomp);
          }
          return (Component[]) comps.toArray(new Component[comps.size()]);
        } else   if (xmodel instanceof BindingListModel) {
          final BindingListModel model = (BindingListModel) xmodel;
          int index = model.indexOf(bean);
          if (index >= 0) {
            final Component xcomp = lookupClone(decor.getComponentAtIndexByOwner(owner, index), comp);
            return xcomp != null ? new Component[] {xcomp} : new Component[0];
          }
        }
    } else {
      //though the comp is in collection but the binding does not relate to _var,
      //have to scan through the whole cloned children items  
      final int sz = xmodel.getSize();
        final List comps = new ArrayList(sz);
      if (decor instanceof CollectionItemExt) {
        final List items = ((CollectionItemExt)decor).getItems(owner);
        for (final Iterator it = items.iterator(); it.hasNext(); ) {
          final Component cloneitem = (Component) it.next();
            final Component xcomp = lookupClone(cloneitem, comp);
            if (xcomp != null)
              comps.add(xcomp);
        }
      } else {
        for (int j = 0; j < sz; ++j) {
            final Component xcomp = lookupClone(decor.getComponentAtIndexByOwner(owner, j), comp);
            if (xcomp != null)
              comps.add(xcomp);
        }
      }
        return (Component[]) comps.toArray(new Component[sz]);
View Full Code Here

      if (currentNode != null) {
        if (!currentNode.isVar()) {
          assocateSameNodes.add(currentNode);
        } else { //a var node, specialcase, find the var root
          Component varRootComp = getVarRootComponent(currentNode);
          assocateSameNodes.add(new Object[] {currentNode, varRootComp});
        }
      }
    }
    return assocateSameNodes;
View Full Code Here

        bean = obj;
        break;
      }
    }
   
    Component comp = null;
    for(final Iterator itx = varRootNode.getBindings().iterator(); itx.hasNext();) {
      Binding binding = (Binding) itx.next();
      if ("_var".equals(binding.getAttr())) {
        comp = binding.getComponent();
        break;
View Full Code Here

  }
 
  //feature #3026221: Databinder shall fire onCreate when cloning each items
  /*package*/ static void postOnCreateEvents(Component item) {
    for(final Iterator it = item.getChildren().iterator(); it.hasNext();) {
      final Component child = (Component) it.next();
      postOnCreateEvents(child); //recursive
    }
    if (Events.isListened(item, Events.ON_CREATE, false)) {
      Events.postEvent(new CreateEvent(Events.ON_CREATE, item, null));
    }
View Full Code Here

  }

  /** Returns the listbox that this belongs to.
   */
  public Listbox getListbox() {
    final Component comp = getParent();
    return comp != null ? (Listbox)comp.getParent(): null;
  }
View Full Code Here

      final BindingNode node = (BindingNode) data[1]; //to be loaded nodes
      final Binding savebinding = (Binding) data[2]; //to be excluded binding
      final Object bean = data[3]; //saved bean
      final boolean refChanged = ((Boolean) data[4]).booleanValue(); //whether bean itself changed
      final List nodes = (List) data[5]; //the complete nodes along the path to the node
      final Component savecomp = (Component) data[6]; //saved comp that trigger this load-on-save event
      final String triggerEventName = (String) data[7]; //event that trigger the save
      if (savecomp != null) {
        final Execution exec = Executions.getCurrent();
        final Object old = exec.getAttribute(LOAD_ON_SAVE_TRIGGER_COMPONENT);
        exec.setAttribute(LOAD_ON_SAVE_TRIGGER_COMPONENT, new Object[] {savecomp, triggerEventName});
View Full Code Here

            if (obj instanceof BindingNode) {
              BindingNode samenode = (BindingNode) obj;
              myLoadAllNodes(bean, samenode, new Component[] {collectionComp}, walkedNodes, savebinding, loadedComps, refChanged);
            } else {
              BindingNode samenode = (BindingNode)((Object[])obj)[0];
              Component varRootComp = (Component) ((Object[])obj)[1];
              myLoadAllNodes(bean, samenode, new Component[] {varRootComp}, walkedNodes, savebinding, loadedComps, refChanged);
            }
          }
        }
      }
View Full Code Here

          continue;
        }

        final String attr = binding.getAttr();
        final boolean isCollectionItem =  "_var".equals(attr);
        final Component comp = binding.getComponent();
         
        //since 3.1, 20080416, Henri Chen: support one object maps to multiple item of a ListModel
        if (isTemplate(comp)) { //a template component, locate the listitem
          Component[] clonecomps = new Component[0];
          if (isClone(collectionComp)) { //A listbox in listbox
            Component clonecomp = lookupClone(collectionComp, comp);
            if (clonecomp == null) { //the comp is in another Listbox?
              if (isCollectionItem) {
                clonecomps = getCollectionItems(comp, bean, isCollectionItem);
              } else {
                throw new UiException("Cannot find associated CollectionItem="+comp+", binding="+binding+", collectionComp="+ collectionComp);
              }
            } else {
              clonecomps = new Component[] {clonecomp};
            }
          } else {
            clonecomps = getCollectionItems(comp, bean, isCollectionItem);
          }
          if (refChanged) {
            for (int j = 0; j < clonecomps.length; ++j) {
              final Component clonecomp = clonecomps[j];
              binding.loadAttribute(clonecomp);
            }
          }
          //special case, collection items are found,
          //use it to handle the rest of the bindings in this node
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.