You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ar...@apache.org on 2010/07/17 00:18:43 UTC

svn commit: r964964 [2/2] - in /myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main: java-templates/org/apache/myfaces/trinidad/component/ java-templates/org/apache/myfaces/trinidad/component/core/layout/ java/org/apache/myfaces...

Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java?rev=964964&r1=964963&r2=964964&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/UIXHierarchy.java Fri Jul 16 22:18:43 2010
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -19,11 +19,12 @@
 package org.apache.myfaces.trinidad.component;
 
 import java.util.Collections;
-
 import java.util.List;
 
 import javax.faces.component.UIComponent;
 
+import org.apache.myfaces.trinidad.component.visit.VisitCallback;
+import org.apache.myfaces.trinidad.component.visit.VisitContext;
 import org.apache.myfaces.trinidad.model.CollectionModel;
 import org.apache.myfaces.trinidad.model.LocalRowKeyIndex;
 import org.apache.myfaces.trinidad.model.ModelUtils;
@@ -37,7 +38,7 @@ import org.apache.myfaces.trinidad.model
  *
  * @version $Name:  $ ($Revision: adfrt/faces/adf-faces-api/src/main/java/oracle/adf/view/faces/component/UIXHierarchy.java#0 $) $Date: 10-nov-2005.19:09:52 $
  */
-abstract public class UIXHierarchy extends UIXCollection implements CollectionComponent, LocalRowKeyIndex, 
+abstract public class UIXHierarchy extends UIXCollection implements CollectionComponent, LocalRowKeyIndex,
              TreeLocalRowKeyIndex
 {
   /**
@@ -58,7 +59,7 @@ abstract public class UIXHierarchy exten
   public CollectionModel createCollectionModel(CollectionModel current, Object value)
   {
     TreeModel model = ModelUtils.toTreeModel(value);
-    model.setRowKey(null);    
+    model.setRowKey(null);
     return model;
   }
 
@@ -80,8 +81,8 @@ abstract public class UIXHierarchy exten
   public int getRows()
   {
     return 0;
-  }  
-  
+  }
+
   /**
   * Treats the current element as a parent element and steps into the children.
   * A new path is constructed by appending the null value to the old path.
@@ -128,7 +129,7 @@ abstract public class UIXHierarchy exten
    */
   public boolean isContainerEmpty()
   {
-    
+
     return getTreeModel().isContainerEmpty();
   }
 
@@ -169,7 +170,7 @@ abstract public class UIXHierarchy exten
   {
     return getTreeModel().getContainerRowKey(childKey);
   }
-  
+
   /**
    * Gets the all the rowKeys of the ancestors of the given child row.
    * @see TreeModel#getAllAncestorContainerRowKeys(Object)
@@ -184,8 +185,8 @@ abstract public class UIXHierarchy exten
   //
 
   /**
-   * Indicates whether data for a child model (children of the current node) is 
-   * locally available. 
+   * Indicates whether data for a child model (children of the current node) is
+   * locally available.
    * @see TreeModel#isChildCollectionLocallyAvailable()
    * @return true if child data is locally available
    */
@@ -196,7 +197,7 @@ abstract public class UIXHierarchy exten
 
   /**
    * Indicates whether child data for the node with the given index is
-   * locally available.   
+   * locally available.
    * @see TreeModel#isChildCollectionLocallyAvailable(int)
    * @param index row index to check
    * @return true if child data is available, false otherwise
@@ -208,7 +209,7 @@ abstract public class UIXHierarchy exten
 
   /**
    * Indicates whether child data for the node with the given row key is
-   * locally available.   
+   * locally available.
    * @see TreeModel#isChildCollectionLocallyAvailable(Object)
    * @param rowKey row key to check
    * @return true if child data is available, false otherwise
@@ -221,7 +222,7 @@ abstract public class UIXHierarchy exten
   /**
    * Check if a range of rows is locally available starting from a row index.  The range
    * can include child nodes in any expanded nodes within the range.
-   * @param startIndex staring index for the range  
+   * @param startIndex staring index for the range
    * @param rowCount number of rows in the range
    * @param disclosedRowKeys set of expanded nodes which may fall within the range to check for
    * availability
@@ -237,7 +238,7 @@ abstract public class UIXHierarchy exten
   /**
    * Check if a range of rows is locally available starting from a row key.   The range
    * can include child nodes in any expanded nodes within the range.
-   * @param startRowKey staring row key for the range  
+   * @param startRowKey staring row key for the range
    * @param rowCount number of rows in the range
    * @param disclosedRowKeys set of expanded nodes which may fall within the range to check for
    * availability
@@ -273,8 +274,8 @@ abstract public class UIXHierarchy exten
   {
     TreeModel model = (TreeModel) getCollectionModel();
     return model;
-  } 
-  
+  }
+
   @Override
   protected List<UIComponent> getStamps()
   {
@@ -283,7 +284,94 @@ abstract public class UIXHierarchy exten
       return Collections.singletonList(nodeStamp);
     else
       return Collections.emptyList();
-  }  
+  }
 
   abstract public Object getFocusRowKey();
+
+  protected final boolean visitLevel(
+    VisitContext      visitContext,
+    VisitCallback     callback,
+    List<UIComponent> stamps)
+  {
+    if (getRowCount() != 0)
+    {
+      if (!stamps.isEmpty())
+      {
+        int oldRow = getRowIndex();
+        int first = getFirst();
+        int last = TableUtils.getLast(this, first);
+
+        try
+        {
+          for (int i = first; i <= last; i++)
+          {
+            setRowIndex(i);
+
+            for (UIComponent currStamp : stamps)
+            {
+              // visit the stamps.  If we have visited all of the visit targets then return early
+              if (UIXComponent.visitTree(visitContext, currStamp, callback))
+                return true;
+            }
+          }
+        }
+        finally
+        {
+          setRowIndex(oldRow);
+        }
+      }
+    }
+
+    return false;
+  }
+
+  protected final boolean visitHierarchy(
+    VisitContext      visitContext,
+    VisitCallback     callback,
+    List<UIComponent> stamps,
+    RowKeySet         disclosedRowKeys)
+  {
+    int oldRow = getRowIndex();
+    int first = getFirst();
+    int last = TableUtils.getLast(this, first);
+
+    try
+    {
+      for(int i = first; i <= last; i++)
+      {
+        setRowIndex(i);
+        if (!stamps.isEmpty())
+        {
+          for (UIComponent currStamp : stamps)
+          {
+            // visit the stamps.  If we have visited all of the visit targets then return early
+            if (UIXComponent.visitTree(visitContext, currStamp, callback))
+              return true;
+          }
+        }
+
+        if (isContainer() && ((disclosedRowKeys == null) || disclosedRowKeys.isContained()))
+        {
+          enterContainer();
+
+          try
+          {
+            // visit this container.  If we have visited all of the visit targets then return early
+            if (visitHierarchy(visitContext, callback, stamps, disclosedRowKeys))
+              return true;
+          }
+          finally
+          {
+            exitContainer();
+          }
+        }
+      }
+    }
+    finally
+    {
+      setRowIndex(oldRow);
+    }
+
+    return false;
+  }
 }

Added: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java?rev=964964&view=auto
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java (added)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java Fri Jul 16 22:18:43 2010
@@ -0,0 +1,80 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.myfaces.trinidad.component.visit;
+
+import java.util.Collection;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseId;
+
+
+/**
+ * A port of the JSF 2 <code>VisitContextWrapper</code> class so that we may be able to use
+ * its functionality in JSF 1.2 with Trinidad 1.2
+ */
+public abstract class VisitContextWrapper
+  extends VisitContext
+{
+  /**
+   * Get the wrapped visit context
+   */
+  public abstract VisitContext getWrapped();
+
+  @Override
+  public FacesContext getFacesContext()
+  {
+    return getWrapped().getFacesContext();
+  }
+
+  @Override
+  public PhaseId getPhaseId()
+  {
+    return getWrapped().getPhaseId();
+  }
+
+  @Override
+  public Set<VisitHint> getHints()
+  {
+    return getWrapped().getHints();
+  }
+
+  @Override
+  public Collection<String> getIdsToVisit()
+  {
+    return getWrapped().getIdsToVisit();
+  }
+
+  @Override
+  public Collection<String> getSubtreeIdsToVisit(
+    UIComponent component)
+  {
+    return getWrapped().getSubtreeIdsToVisit(component);
+  }
+
+  @Override
+  public VisitResult invokeVisitCallback(
+    UIComponent   component,
+    VisitCallback callback)
+  {
+    return getWrapped().invokeVisitCallback(component, callback);
+  }
+}

Propchange: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/component/visit/VisitContextWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java?rev=964964&r1=964963&r2=964964&view=diff
==============================================================================
--- myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java (original)
+++ myfaces/trinidad/branches/anrobins_1.2.12.3_visitTree/trinidad-api/src/main/java/org/apache/myfaces/trinidad/render/CoreRenderer.java Fri Jul 16 22:18:43 2010
@@ -161,6 +161,46 @@ public class CoreRenderer extends Render
       tearDownEncodingContext(context, rc, (UIXComponent)component);
   }
 
+  /**
+   * Hook to allow the renderer to customize the visitation of the children components
+   * of a component during the visitation of a component during rendering.
+   *
+   * @param component the component which owns the children to visit
+   * @param visitContext the visitation context
+   * @param callback the visit callback
+   * @return <code>true</code> if the visit is complete.
+   * @see UIXComponent#visitChildren(VisitContext, VisitCallback)
+   */
+  public boolean visitChildrenForEncoding(
+    UIXComponent  component,
+    VisitContext  visitContext,
+    VisitCallback callback)
+  {
+    // visit the children of the component
+    Iterator<UIComponent> kids = component.getFacetsAndChildren();
+
+    while (kids.hasNext())
+    {
+      // If any kid visit returns true, we are done.
+      UIComponent kid = kids.next();
+      if (kid instanceof UIXComponent)
+      {
+        if (((UIXComponent)kid).visitTree(visitContext, callback))
+        {
+          return true;
+        }
+      }
+      else
+      {
+        if (UIXComponent.visitTree(visitContext, kid, callback))
+        {
+          return true;
+        }
+      }
+    }
+
+    return false;
+  }
 
   //
   // COERCION HELPERS
@@ -684,9 +724,9 @@ public class CoreRenderer extends Render
   {
     return (Agent.PLATFORM_GENERICPDA.equals(rc.getAgent().getPlatformName()));
   }
-  
+
   /**
-   * This method returns true if a user-agent's platform is NokiaS60 
+   * This method returns true if a user-agent's platform is NokiaS60
    * @param arc - RenderingContext of a request
    * @return boolean
    */