You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by so...@apache.org on 2008/07/30 17:50:15 UTC

svn commit: r681091 - in /myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main: java-templates/org/apache/myfaces/trinidad/component/ java/org/apache/myfaces/trinidad/component/

Author: sobryan
Date: Wed Jul 30 08:50:14 2008
New Revision: 681091

URL: http://svn.apache.org/viewvc?rev=681091&view=rev
Log:
TRINIDAD-961: NON-FUNCTIONAL PARTIALTRIGGERS FOR TABLE COLUMN HEADER/FOOTER

Thanks Kamran!

Modified:
    myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTableTemplate.java
    myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTreeTableTemplate.java
    myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/TableUtils.java

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTableTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTableTemplate.java?rev=681091&r1=681090&r2=681091&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTableTemplate.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTableTemplate.java Wed Jul 30 08:50:14 2008
@@ -18,7 +18,10 @@
  */
 package org.apache.myfaces.trinidad.component;
 
+import java.io.IOException;
+
 import java.util.ArrayList;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -51,11 +54,56 @@
   implements CollectionComponent
 {
 
+
+  /**
+   * Override to update the container client id cache before decode
+   */
+  @Override
+  public void decode(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.decode(context);    
+  }
+  
+  /**
+   * Override to update the container client id cache before validations
+   */
+  @Override
+  public void processValidators(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.processValidators(context);
+  }
+  
+
+  /**
+   * Override to update the container client id cache before updates
+   */  
+  @Override
+  public void processUpdates(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.processUpdates(context);
+  }  
+  
+  /**
+   * Override to update the container client id cache before encode
+   */
+  @Override
+  void __encodeBegin(FacesContext context) throws IOException
+  {
+    _resetContainerClientIdCache();
+    super.__encodeBegin(context);
+  }
+  
+  /**
+   * Override to return clientd ids with no currency for items in header/footer facets
+   */
   @Override
   public String getContainerClientId(FacesContext context, UIComponent child)
   {
     String id;
-    if (_isStampedChild(child))
+    if (_containerClientIdCache == null || _isStampedChild(child))
     {   
       // call the UIXCollection getContainerClientId, which attaches currency string to the client id
       id = getContainerClientId(context);
@@ -421,19 +469,30 @@
     }
   }
 
+  /**
+   * Is target a stamped child UIComponent in the table body
+   */
   private boolean _isStampedChild(UIComponent target)
   {
-    // Not stamped if target is in table header/footer:
-    if (TableUtils.__isInTableHeaderFooterFacet(this, target))
-      return false;
-
-    // Not stamped if target is in a column header/footer:
-    if (TableUtils.__isInColumnHeaderFooterFacet(this, target))
-      return false;
+    assert _containerClientIdCache != null;
+    return !_containerClientIdCache.containsKey(target);
+  }
 
-    return true;
+  /**
+   * Reset the cache of child components used in getContainerClientId
+   */
+  private void _resetContainerClientIdCache()
+  {
+    if(_containerClientIdCache == null)
+      _containerClientIdCache = new IdentityHashMap<UIComponent, Boolean>();
+    else
+      _containerClientIdCache.clear();
+
+    TableUtils.cacheHeaderFooterFacets(this, _containerClientIdCache);
+    TableUtils.cacheColumnHeaderFooterFacets(this, _containerClientIdCache);
   }
 
+  
   @Override
   void __init()
   {
@@ -449,4 +508,7 @@
   }
 
   transient private List<SortCriterion> _sortCriteria = null;
+  // cache of child components inside this table header/footer facets and column header/footer
+  // facets
+  transient private IdentityHashMap<UIComponent, Boolean> _containerClientIdCache = null;
 }

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTreeTableTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTreeTableTemplate.java?rev=681091&r1=681090&r2=681091&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTreeTableTemplate.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXTreeTableTemplate.java Wed Jul 30 08:50:14 2008
@@ -18,9 +18,12 @@
  */
 package org.apache.myfaces.trinidad.component;
 
+import java.io.IOException;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -49,11 +52,55 @@
 /**/  public abstract int[] getRowsByDepth();
 /**/  abstract public MethodExpression getRangeChangeListener();
 
+  /**
+   * Override to update the container client id cache before decode
+   */
+  @Override
+  public void decode(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.decode(context);    
+  }
+  
+  /**
+   * Override to update the container client id cache before validations
+   */
+  @Override
+  public void processValidators(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.processValidators(context);
+  }
+  
+  /**
+   * Override to update the container client id cache before updates
+   */  
+  @Override
+  public void processUpdates(FacesContext context)
+  {
+    _resetContainerClientIdCache();
+    super.processUpdates(context);
+  }  
+
+  /**
+   * Override to update the container client id cache before encode
+   */
+  @Override
+  protected void __encodeBegin(FacesContext context) throws IOException
+  {
+    _resetContainerClientIdCache();
+    super.__encodeBegin(context);
+  }
+
+
+  /**
+   * Override to return clientd ids with no currency for items in header/footer facets
+   */
   @Override
   public String getContainerClientId(FacesContext context, UIComponent child)
   {
     String id;
-    if (_isStampedChild(child))
+    if (_containerClientIdCache == null || _isStampedChild(child))
     {   
       // call the UIXCollection getContainerClientId, which attaches currency string to the client id
       id = getContainerClientId(context);
@@ -349,23 +396,43 @@
     return parentKey;
   }
 
+  /**
+   * Is target a stamped child UIComponent in the treeTable body
+   */
   private boolean _isStampedChild(UIComponent target)
   {
-    // Not stamped if target is in table header/footer:
-    if (TableUtils.__isInTableHeaderFooterFacet(this, target))
-      return false;
-
-    // Not stamped if target is in a column header/footer:
-    if (TableUtils.__isInColumnHeaderFooterFacet(this, target))
-      return false;
-
-    // Not stamped if target is in the nodeStamp column header/footer:
-    if (TableUtils.__isInNodeStampHeaderFooterFacet(this, target))
-      return false;
+    assert _containerClientIdCache != null;
+    return !_containerClientIdCache.containsKey(target);
+  }
 
-    return true;
+  /**
+   * Reset the cache of child components used in getContainerClientId
+   */
+  private void _resetContainerClientIdCache()
+  {
+    if(_containerClientIdCache == null)
+      _containerClientIdCache = new IdentityHashMap<UIComponent, Boolean>();
+    else
+      _containerClientIdCache.clear();
+
+    // cache treeTable header/footer items
+    TableUtils.cacheHeaderFooterFacets(this, _containerClientIdCache);
+    // cache child column header/footer items, including nested columns
+    TableUtils.cacheColumnHeaderFooterFacets(this, _containerClientIdCache);
+
+    UIComponent nodeStamp = getNodeStamp();
+    if(nodeStamp != null)
+    {
+      // cache nodeStamp header/footer items
+      TableUtils.cacheHeaderFooterFacets(nodeStamp, _containerClientIdCache);
+      // cache any nested columns in nodeStamp facet
+      TableUtils.cacheColumnHeaderFooterFacets(nodeStamp, _containerClientIdCache);      
+    }
   }
 
 
   private Map<Object, Integer> _firstMap = Collections.emptyMap();
+  // cache of child components inside this treeTable header/footer facets and column header/footer
+  // facets
+  transient private IdentityHashMap<UIComponent, Boolean> _containerClientIdCache = null;
 }

Modified: myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/TableUtils.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/TableUtils.java?rev=681091&r1=681090&r2=681091&view=diff
==============================================================================
--- myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/TableUtils.java (original)
+++ myfaces/trinidad/trunk_1.2.x/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/TableUtils.java Wed Jul 30 08:50:14 2008
@@ -309,124 +309,47 @@
     }          
   }  
 
-  /**
-   * Determine if the target component is inside the table header/footer facet
-   * @param parent
-   * @param target
-   * @return
-   */
-  static boolean __isInTableHeaderFooterFacet(UIXCollection parent, UIComponent target)
-  {
-    return __isInHeaderFooterFacet(parent, target);
-  }
-
-  /**
-   * Determine if the target component is inside a column header/footer facet
-   * @param parent
-   * @param target
-   * @return
-   */
-  static boolean __isInColumnHeaderFooterFacet(UIXCollection parent, UIComponent target)
-  {
-    List<UIComponent> children = new ArrayList<UIComponent>();
-    children = _getColumns(parent, children);
-    for (UIComponent child : children)
-    {
-      if (__isInHeaderFooterFacet(child, target))
-        return true;
-    }
-
-    return false;
-  }
-  
-  /**
-   * Determine if the target component is in the treeTable nodeStamp column
-   * header/footer
-   * @param tree
-   * @param target
-   * @return
-   */
-  static boolean __isInNodeStampHeaderFooterFacet(UIXTree tree, UIComponent target)
-  {
-    UIComponent nodeStamp = tree.getNodeStamp();
-    if (nodeStamp != null)
-    {
-      if (__isInHeaderFooterFacet(nodeStamp, target))
-        return true;      
-    }
-    
-    return false;
-  }
-
-  /**
-   * Determine if the target component is inside the parent header/footer facet
-   * @param parent
-   * @param target
-   * @return
-   */
-  static boolean __isInHeaderFooterFacet(UIComponent parent, UIComponent target)
+  static void cacheHeaderFooterFacets(UIComponent parent, Map<UIComponent, Boolean> cache)
   {
+    // grab the header facet and it's children
     UIComponent headerFacet = parent.getFacets().get("header");
     if (headerFacet != null)
     {
-      if (target == headerFacet || _isDescendant(headerFacet, target, null))
-        return true;
+      _cacheDescendants(headerFacet, cache, true);
     }
 
+    // grab the footer facet and it's children
     UIComponent footerFacet = parent.getFacets().get("footer");
     if (footerFacet != null)
     {
-      if (target == footerFacet || _isDescendant(footerFacet, target, null))
-        return true;
+      _cacheDescendants(footerFacet, cache, true);
     }
-
-    return false;
   }
 
-  /**
-   * Returns all columns including column groups
-   * @param parent
-   * @param columns
-   * @return
-   */
-  static private List<UIComponent> _getColumns(UIComponent parent, List<UIComponent> columns)
+  static void cacheColumnHeaderFooterFacets(UIComponent parent, Map<UIComponent, Boolean> cache)
   {
     List<UIComponent> children = parent.getChildren();
     for (UIComponent child : children)
     {
       if (child instanceof UIXColumn)
       {
-        columns.add(child);
-        columns = _getColumns(child, columns);
+        cacheHeaderFooterFacets(child, cache);
+        cacheColumnHeaderFooterFacets(child, cache);
       }
     }
-    return columns;
   }
   
-  /**
-   * Determine if target is a descendant of the parent parameter by recursively walking
-   * the parent's children. Optionally skip children of type skipType
-   * @param parent
-   * @param target
-   * @param skipType
-   * @return
-   */
-  static private <T> boolean _isDescendant(UIComponent parent, UIComponent target, Class<T> skipType)
+
+  private static void _cacheDescendants(UIComponent parent, Map<UIComponent, Boolean> cache, boolean inclusive)
   {
+    if(inclusive)
+      cache.put(parent, Boolean.TRUE);
+    
     List<UIComponent> children = parent.getChildren();
     for (UIComponent child : children)
     {
-      if ( (skipType == null || !skipType.isInstance(child)) && child == target)
-      {
-        return true;
-      }
-      else
-      {
-        if (_isDescendant(child, target, skipType))
-          return true;
-      }
+      _cacheDescendants(child, cache, true);
     }
-    return false;    
   }
 
   /**