You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2009/05/17 13:27:22 UTC

svn commit: r775627 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms: binding/ formmodel/

Author: joerg
Date: Sun May 17 11:27:21 2009
New Revision: 775627

URL: http://svn.apache.org/viewvc?rev=775627&view=rev
Log:
whitespace

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterAdapter.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathCollection.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/EnhancedRepeater.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterAdapter.java?rev=775627&r1=775626&r2=775627&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterAdapter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterAdapter.java Sun May 17 11:27:21 2009
@@ -25,16 +25,17 @@
  */
 public interface RepeaterAdapter {
 
-	public void setBinding(EnhancedRepeaterJXPathBinding binding);
-	public void setJXCollection(RepeaterJXPathCollection collection);
+    public void setBinding(EnhancedRepeaterJXPathBinding binding);
+    public void setJXCollection(RepeaterJXPathCollection collection);
 
-	public void setCollection(Collection c);
+    public void setCollection(Collection c);
 
-	// TODO expand with widget path
-	public RepeaterSorter sortBy(String path);
-	public RepeaterFilter getFilter();
+    // TODO expand with widget path
+    public RepeaterSorter sortBy(String path);
+    public RepeaterFilter getFilter();
+
+    public RepeaterItem getItem(int i);
+    public RepeaterItem generateItem(RepeaterRow row);
+    public void populateRow(RepeaterItem item) throws BindingException;
 
-	public RepeaterItem getItem(int i);
-	public RepeaterItem generateItem(RepeaterRow row);
-	public void populateRow(RepeaterItem item) throws BindingException;
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java?rev=775627&r1=775626&r2=775627&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathAdapter.java Sun May 17 11:27:21 2009
@@ -30,185 +30,194 @@
 import org.apache.commons.jxpath.Pointer;
 
 /**
- * @version $Id$
+ * @version $Id: RepeaterJXPathAdapter.java 517733 2007-03-13 15:37:22Z
+ *          vgritsenko $
  */
 public class RepeaterJXPathAdapter implements RepeaterAdapter {
 
-	private int progressive = 100000;
+    private int progressive = 100000;
 
-	private EnhancedRepeaterJXPathBinding binding;
-	private RepeaterJXPathCollection jxCollection;
-	private List sortedItems;
-
-
-	public RepeaterFilter getFilter() {
-		return new RepeaterJXPathFilter();
-	}
-
-	private String findPathFor(String field) {
-		JXPathBindingBase[] childBindings = binding.getRowBinding().getChildBindings();
-		String path = null;
-		for (int i = 0; i < childBindings.length; i++) {
-			if (childBindings[i] instanceof ValueJXPathBinding) {
-				ValueJXPathBinding bnd = (ValueJXPathBinding) childBindings[i];
-				if (bnd.getFieldId().equals(field)) {
-					path = bnd.getXPath();
-					break;
-				}
-			}
-		}
-		return path;
-	}
-
-	public RepeaterSorter sortBy(String field) {
-		if (field == null) {
-			sortedItems = null;
-			return new NormalOrderJXPathSorter();
-		}
-		String path = findPathFor(field);
-		if (path == null) throw new IllegalStateException("Cannot find a path for sorting on widget " + field);
-		RepeaterSorter sort = new RepeaterJXPathSorter(path, field);
-		if (sortedItems == null) {
-			List tsortedItems = new ArrayList();
-			int i = 0;
-			RepeaterItem item = getItem(i);
-			while (item != null) {
-				tsortedItems.add(item);
-				i++;
-				item = getItem(i);
-			}
-			this.sortedItems = tsortedItems;
-		}
-		Collections.sort(sortedItems, sort);
-		return sort;
-	}
-
-	public void setBinding(EnhancedRepeaterJXPathBinding binding) {
-		this.binding = binding;
-	}
-
-	public void setCollection(Collection c) {
-	}
-
-	public void setJXCollection(RepeaterJXPathCollection collection) {
-		this.jxCollection = collection;
-	}
+    private EnhancedRepeaterJXPathBinding binding;
+    private RepeaterJXPathCollection jxCollection;
+    private List sortedItems;
+
+    public RepeaterFilter getFilter() {
+        return new RepeaterJXPathFilter();
+    }
+
+    private String findPathFor(String field) {
+        JXPathBindingBase[] childBindings = binding.getRowBinding().getChildBindings();
+        String path = null;
+        for (int i = 0; i < childBindings.length; i++) {
+            if (childBindings[i] instanceof ValueJXPathBinding) {
+                ValueJXPathBinding bnd = (ValueJXPathBinding) childBindings[i];
+                if (bnd.getFieldId().equals(field)) {
+                    path = bnd.getXPath();
+                    break;
+                }
+            }
+        }
+        return path;
+    }
+
+    public RepeaterSorter sortBy(String field) {
+        if (field == null) {
+            sortedItems = null;
+            return new NormalOrderJXPathSorter();
+        }
+        String path = findPathFor(field);
+        if (path == null) {
+            throw new IllegalStateException("Cannot find a path for sorting on widget " + field);
+        }
+        RepeaterSorter sort = new RepeaterJXPathSorter(path, field);
+        if (sortedItems == null) {
+            List tsortedItems = new ArrayList();
+            int i = 0;
+            RepeaterItem item = getItem(i);
+            while (item != null) {
+                tsortedItems.add(item);
+                i++;
+                item = getItem(i);
+            }
+            this.sortedItems = tsortedItems;
+        }
+        Collections.sort(sortedItems, sort);
+        return sort;
+    }
+
+    public void setBinding(EnhancedRepeaterJXPathBinding binding) {
+        this.binding = binding;
+    }
+
+    public void setCollection(Collection c) {
+    }
+
+    public void setJXCollection(RepeaterJXPathCollection collection) {
+        this.jxCollection = collection;
+    }
 
     public RepeaterItem getItem(int i) {
-    	if (i < 0) return null;
-		if (i >= jxCollection.getOriginalCollectionSize()) return null;
-    	if (this.sortedItems == null) {
-	    	JXPathContext storageContext = this.jxCollection.getStorageContext();
-	        Pointer pointer = storageContext.getPointer(binding.getRowPath() + "[" + (i+1) + "]");
-	        JXPathContext rowContext = storageContext.getRelativeContext(pointer);
-	        RepeaterItem item = new RepeaterItem(new Integer(i + 1));
-	        item.setContext(rowContext);
-	        return item;
-    	} else {
-    		return (RepeaterItem) sortedItems.get(i);
-    	}
-    }
-
-
-	class RepeaterJXPathFilter implements RepeaterFilter {
-
-		private Map fieldsPaths = new HashMap();
-		private Map fieldsValues = new HashMap();
-
-		public boolean shouldDisplay(RepeaterItem item) {
-			for (Iterator iter = fieldsValues.keySet().iterator(); iter.hasNext();) {
-				String field = (String) iter.next();
-				Object value = fieldsValues.get(field);
-				Object acvalue = null;
-				if (item.getRow() == null) {
-					String path = (String) fieldsPaths.get(field);
-					acvalue = item.getContext().getValue(path);
-				} else {
-					acvalue = item.getRow().getChild(field).getValue();
-				}
-				if (acvalue == null) return false;
-				if (acvalue instanceof String && value instanceof String) {
-					return ((String)acvalue).startsWith((String)value);
-				} else {
-					return acvalue.equals(value);
-				}
-			}
-			return true;
-		}
-
-		public void setFilter(String field, Object value) {
-			if (value == null || ((value instanceof String) && ((String)value).length() == 0)) {
-				fieldsPaths.remove(field);
-				fieldsValues.remove(field);
-			} else {
-				String path = findPathFor(field);
-				if (path == null) throw new IllegalStateException("Cannot find a path for filtering on widget " + field);
-				fieldsPaths.put(field, path);
-				fieldsValues.put(field, value);
-			}
-		}
-
-	}
-
-	static class RepeaterJXPathSorter implements RepeaterSorter {
-
-		private String path;
-		private String field;
-
-		public RepeaterJXPathSorter(String path, String field) {
-			this.path = path;
-			this.field = field;
-		}
-
-		public void setCollection(Collection c) {
-		}
-
-		public int compare(Object o1, Object o2) {
-			RepeaterItem i1 = (RepeaterItem) o1;
-			RepeaterItem i2 = (RepeaterItem) o2;
+        if (i < 0) {
+            return null;
+        }
+        if (i >= jxCollection.getOriginalCollectionSize()) {
+            return null;
+        }
+        if (this.sortedItems == null) {
+            JXPathContext storageContext = this.jxCollection.getStorageContext();
+            Pointer pointer = storageContext.getPointer(binding.getRowPath() + "[" + (i + 1) + "]");
+            JXPathContext rowContext = storageContext.getRelativeContext(pointer);
+            RepeaterItem item = new RepeaterItem(new Integer(i + 1));
+            item.setContext(rowContext);
+            return item;
+        } else {
+            return (RepeaterItem) sortedItems.get(i);
+        }
+    }
+
+    class RepeaterJXPathFilter implements RepeaterFilter {
+
+        private Map fieldsPaths = new HashMap();
+        private Map fieldsValues = new HashMap();
+
+        public boolean shouldDisplay(RepeaterItem item) {
+            for (Iterator iter = fieldsValues.keySet().iterator(); iter.hasNext();) {
+                String field = (String) iter.next();
+                Object value = fieldsValues.get(field);
+                Object acvalue = null;
+                if (item.getRow() == null) {
+                    String path = (String) fieldsPaths.get(field);
+                    acvalue = item.getContext().getValue(path);
+                } else {
+                    acvalue = item.getRow().getChild(field).getValue();
+                }
+                if (acvalue == null) {
+                    return false;
+                }
+                if (acvalue instanceof String && value instanceof String) {
+                    return ((String) acvalue).startsWith((String) value);
+                } else {
+                    return acvalue.equals(value);
+                }
+            }
+            return true;
+        }
+
+        public void setFilter(String field, Object value) {
+            if (value == null || ((value instanceof String) && ((String)value).length() == 0)) {
+                fieldsPaths.remove(field);
+                fieldsValues.remove(field);
+            } else {
+                String path = findPathFor(field);
+                if (path == null) {
+                    throw new IllegalStateException("Cannot find a path for filtering on widget " + field);
+                }
+                fieldsPaths.put(field, path);
+                fieldsValues.put(field, value);
+            }
+        }
+
+    }
+
+    static class RepeaterJXPathSorter implements RepeaterSorter {
+
+        private String path;
+        private String field;
+
+        public RepeaterJXPathSorter(String path, String field) {
+            this.path = path;
+            this.field = field;
+        }
+
+        public void setCollection(Collection c) {
+        }
+
+        public int compare(Object o1, Object o2) {
+            RepeaterItem i1 = (RepeaterItem) o1;
+            RepeaterItem i2 = (RepeaterItem) o2;
 
             Object val1;
-			if (i1.getRow() != null) {
-				val1 = i1.getRow().getChild(field).getValue();
-			} else {
-				val1 = i1.getContext().getValue(path);
-			}
+            if (i1.getRow() != null) {
+                val1 = i1.getRow().getChild(field).getValue();
+            } else {
+                val1 = i1.getContext().getValue(path);
+            }
 
             Object val2;
-			if (i2.getRow() != null) {
-				val2 = i2.getRow().getChild(field).getValue();
-			} else {
-				val2 = i2.getContext().getValue(path);
-			}
+            if (i2.getRow() != null) {
+                val2 = i2.getRow().getChild(field).getValue();
+            } else {
+                val2 = i2.getContext().getValue(path);
+            }
 
             if (val1 instanceof Comparable) {
                 return ((Comparable) val1).compareTo(val2);
             }
             return val1.toString().compareTo(val2.toString());
-		}
+        }
 
-	}
+    }
 
-	static class NormalOrderJXPathSorter implements RepeaterSorter {
+    static class NormalOrderJXPathSorter implements RepeaterSorter {
 
-		public void setCollection(Collection c) {
-		}
+        public void setCollection(Collection c) {
+        }
 
-		public int compare(Object o1, Object o2) {
-			RepeaterItem i1 = (RepeaterItem) o1;
-			RepeaterItem i2 = (RepeaterItem) o2;
+        public int compare(Object o1, Object o2) {
+            RepeaterItem i1 = (RepeaterItem) o1;
+            RepeaterItem i2 = (RepeaterItem) o2;
             return ((Integer) i1.getHandle()).compareTo((Integer) i2.getHandle());
         }
-	}
+    }
 
-	public RepeaterItem generateItem(RepeaterRow row) {
-		RepeaterItem item = new RepeaterItem(new Integer(progressive++));
-		item.setRow(row);
-		return item;
-	}
+    public RepeaterItem generateItem(RepeaterRow row) {
+        RepeaterItem item = new RepeaterItem(new Integer(progressive++));
+        item.setRow(row);
+        return item;
+    }
 
-	public void populateRow(RepeaterItem item) throws BindingException {
+    public void populateRow(RepeaterItem item) throws BindingException {
         binding.getRowBinding().loadFormFromModel(item.getRow(), item.getContext());
-	}
+    }
 
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathCollection.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathCollection.java?rev=775627&r1=775626&r2=775627&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathCollection.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/RepeaterJXPathCollection.java Sun May 17 11:27:21 2009
@@ -33,7 +33,7 @@
 /**
  * Implements a collection that takes care about removed, updated and inserted
  * elements, obtaining from a {@link RepeaterAdapter} all the needed objects.
- *
+ * 
  * @version $Id$
  */
 public class RepeaterJXPathCollection {
@@ -44,14 +44,13 @@
     private Set deletedRows;
     private List insertedRows;
 
-	private int collectionSize;
+    private int collectionSize;
 
-	private RepeaterSorter sorter = null;
-	private RepeaterFilter filter = null;
-	private RepeaterAdapter adapter = null;
-
-	private List itemsCache = new ArrayList();
+    private RepeaterSorter sorter = null;
+    private RepeaterFilter filter = null;
+    private RepeaterAdapter adapter = null;
 
+    private List itemsCache = new ArrayList();
 
     public void init(JXPathContext storageContext, String rowpath, RepeaterAdapter adapter) {
         this.storageContext = storageContext;
@@ -59,9 +58,9 @@
         Object value = storageContext.getValue(rowpath);
         if (value != null) {
             if (value instanceof Collection) {
-                collectionSize = ((Collection)value).size();
+                collectionSize = ((Collection) value).size();
             } else {
-                collectionSize = ((Double) storageContext.getValue("count("+rowpath+")")).intValue();
+                collectionSize = ((Double) storageContext.getValue("count(" + rowpath + ")")).intValue();
             }
         }
 
@@ -73,93 +72,107 @@
     }
 
     private int getStartIndex(int start) {
-    	int i = start;
-    	RepeaterItem item = adapter.getItem(i);
-    	// In case start is after the end of the collection try to go back
-    	// until a valid item is found
-    	while (item == null && i > 0) {
-    		i--;
-    		item = adapter.getItem(i);
-    	}
-    	if (item == null) return 0;
-    	// Now move the index ahead of one for each deleted item "before"
-    	// the desired one
+        int i = start;
+        RepeaterItem item = adapter.getItem(i);
+        // In case start is after the end of the collection try to go back
+        // until a valid item is found
+        while (item == null && i > 0) {
+            i--;
+            item = adapter.getItem(i);
+        }
+        if (item == null) {
+            return 0;
+        }
+        // Now move the index ahead of one for each deleted item "before"
+        // the desired one
         for (Iterator iter = deletedRows.iterator(); iter.hasNext();) {
-			RepeaterItem delitem = (RepeaterItem) iter.next();
-			if (sorter.compare(delitem, item) < 0) {
-				i++;
-			}
-		}
+            RepeaterItem delitem = (RepeaterItem) iter.next();
+            if (sorter.compare(delitem, item) < 0) {
+                i++;
+            }
+        }
         // And move it backward for each inserted row before the actual index
         for (Iterator iter = insertedRows.iterator(); iter.hasNext();) {
-			RepeaterItem insitem = (RepeaterItem) iter.next();
-			if (sorter.compare(insitem, item) < 0) {
-				i--;
-			}
-		}
-        if (i < 0) return 0;
+            RepeaterItem insitem = (RepeaterItem) iter.next();
+            if (sorter.compare(insitem, item) < 0) {
+                i--;
+            }
+        }
+        if (i < 0) {
+            return 0;
+        }
         // Now we should have the correct start
         return i;
     }
 
     public List getItems(int start, int length) {
-    	List ret = new ArrayList();
-    	int rlength = length;
-    	int rstart = getStartIndex(start);
-    	RepeaterItem startItem = null;
-    	if (rstart > 0) {
-    		// Try to fetch one element before, so that we can distinguish
-    		// where we started after inferring added elements.
-    		startItem = getItem(rstart - 1);
-    	}
-    	if (startItem != null) {
-    		ret.add(startItem);
-    	}
-    	int i = rstart;
-    	RepeaterItem item;
+        List ret = new ArrayList();
+        int rlength = length;
+        int rstart = getStartIndex(start);
+        RepeaterItem startItem = null;
+        if (rstart > 0) {
+            // Try to fetch one element before, so that we can distinguish
+            // where we started after inferring added elements.
+            startItem = getItem(rstart - 1);
+        }
+        if (startItem != null) {
+            ret.add(startItem);
+        }
+        int i = rstart;
+        RepeaterItem item;
         while (length > 0) {
-        	item = getItem(i);
-        	if (item == null) break;
-        	// skip deleted items
+            item = getItem(i);
+            if (item == null) {
+                break;
+            }
+            // skip deleted items
             while (isDeleted(item)) {
-            	i++;
-            	item = getItem(i);
-                if (item == null) break;
+                i++;
+                item = getItem(i);
+                if (item == null) {
+                    break;
+                }
             }
             if (filter != null) {
                 while (!filter.shouldDisplay(item)) {
-                	i++;
-                	item = getItem(i);
-                    if (item == null) break;
+                    i++;
+                    item = getItem(i);
+                    if (item == null) {
+                        break;
+                    }
                 }
             }
-            if (item == null) break;
-        	ret.add(item);
-        	i++;
-        	length--;
+            if (item == null) {
+                break;
+            }
+            ret.add(item);
+            i++;
+            length--;
         }
         // Infer the inserted rows.
         if (this.insertedRows.size() > 0) {
             if (filter != null) {
-            	for (Iterator iter = this.insertedRows.iterator(); iter.hasNext();) {
-					RepeaterItem acitem = (RepeaterItem) iter.next();
-					if (filter.shouldDisplay(acitem)) {
-						ret.add(acitem);
-					}
-				}
+                for (Iterator iter = this.insertedRows.iterator(); iter.hasNext();) {
+                    RepeaterItem acitem = (RepeaterItem) iter.next();
+                    if (filter.shouldDisplay(acitem)) {
+                        ret.add(acitem);
+                    }
+                }
             } else {
-            	ret.addAll(this.insertedRows);
+                ret.addAll(this.insertedRows);
             }
-	    	Collections.sort(ret, this.sorter);
+            Collections.sort(ret, this.sorter);
+        }
+        if (startItem != null) {
+            // Now get from the element after our start element.
+            int pos = ret.indexOf(startItem);
+            for (int j = 0; j <= pos; j++) {
+                ret.remove(0);
+            }
+        }
+        while (ret.size() > rlength) {
+            ret.remove(ret.size() - 1);
         }
-    	if (startItem != null) {
-	    	// Now get from the element after our start element.
-	    	int pos = ret.indexOf(startItem);
-	    	for (int j = 0; j <= pos; j++) {
-	    		ret.remove(0);
-	    	}
-    	}
-    	while (ret.size() > rlength) ret.remove(ret.size() - 1);
 
         this.itemsCache.clear();
         this.itemsCache.addAll(ret);
@@ -167,41 +180,43 @@
     }
 
     public List getCachedItems() {
-    	return this.itemsCache;
+        return this.itemsCache;
     }
 
     public void flushCachedItems() {
-    	this.itemsCache.clear();
+        this.itemsCache.clear();
     }
 
     private RepeaterItem getItem(int i) {
         // Take the element from the original collection and check if it was updated
         RepeaterItem item = this.adapter.getItem(i);
-        if (item == null) return null;
+        if (item == null) {
+            return null;
+        }
         if (isUpdated(item)) {
-        	item = (RepeaterItem) this.updatedRows.get(item.getHandle());
+            item = (RepeaterItem) this.updatedRows.get(item.getHandle());
         }
         return item;
     }
 
     public void updateRow(RepeaterItem item) {
-    	if (!isInserted(item) && !isDeleted(item)) {
-    		this.updatedRows.put(item.getHandle(), item);
-    	}
+        if (!isInserted(item) && !isDeleted(item)) {
+            this.updatedRows.put(item.getHandle(), item);
+        }
     }
 
     public void deleteRow(RepeaterItem item) {
-    	if (isInserted(item)) {
-    		this.insertedRows.remove(item);
-    		return;
-    	} else if (isUpdated(item)) {
-    		this.updatedRows.remove(item);
-    	}
-    	this.deletedRows.add(item);
+        if (isInserted(item)) {
+            this.insertedRows.remove(item);
+            return;
+        } else if (isUpdated(item)) {
+            this.updatedRows.remove(item);
+        }
+        this.deletedRows.add(item);
     }
 
     public void addRow(RepeaterItem item) {
-    	this.insertedRows.add(item);
+        this.insertedRows.add(item);
     }
 
     public int getOriginalCollectionSize() {
@@ -209,7 +224,7 @@
     }
 
     public int getActualCollectionSize() {
-    	return getOriginalCollectionSize() - this.deletedRows.size() + this.insertedRows.size();
+        return getOriginalCollectionSize() - this.deletedRows.size() + this.insertedRows.size();
     }
 
     /*
@@ -228,43 +243,43 @@
         return this.insertedRows.contains(item);
     }
 
-	public JXPathContext getStorageContext() {
-		return storageContext;
-	}
-
-	public List getDeletedRows() {
-		// FIXME we should sort by natural order
-		List ret = new ArrayList(this.deletedRows);
-    	Collections.sort(ret, this.sorter);
-    	Collections.reverse(ret);
-		return ret;
-	}
-
-	public List getInsertedRows() {
-		return insertedRows;
-	}
-
-	public Collection getUpdatedRows() {
-		return updatedRows.values();
-	}
-
-	public RepeaterAdapter getAdapter() {
-		return this.adapter;
-	}
-
-	public void addRow(RepeaterRow row) {
-		RepeaterItem item = this.adapter.generateItem(row);
-		this.addRow(item);
-	}
-
-	public void sortBy(String field) {
-		this.sorter = this.adapter.sortBy(field);
-	}
-
-	public void filter(String field, Object value) {
-		if (filter == null) {
-			filter = this.adapter.getFilter();
-		}
-		filter.setFilter(field, value);
-	}
+    public JXPathContext getStorageContext() {
+        return storageContext;
+    }
+
+    public List getDeletedRows() {
+        // FIXME we should sort by natural order
+        List ret = new ArrayList(this.deletedRows);
+        Collections.sort(ret, this.sorter);
+        Collections.reverse(ret);
+        return ret;
+    }
+
+    public List getInsertedRows() {
+        return insertedRows;
+    }
+
+    public Collection getUpdatedRows() {
+        return updatedRows.values();
+    }
+
+    public RepeaterAdapter getAdapter() {
+        return this.adapter;
+    }
+
+    public void addRow(RepeaterRow row) {
+        RepeaterItem item = this.adapter.generateItem(row);
+        this.addRow(item);
+    }
+
+    public void sortBy(String field) {
+        this.sorter = this.adapter.sortBy(field);
+    }
+
+    public void filter(String field, Object value) {
+        if (filter == null) {
+            filter = this.adapter.getFilter();
+        }
+        filter.setFilter(field, value);
+    }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/EnhancedRepeater.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/EnhancedRepeater.java?rev=775627&r1=775626&r2=775627&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/EnhancedRepeater.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/EnhancedRepeater.java Sun May 17 11:27:21 2009
@@ -1,19 +1,19 @@
 /*
-* 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.
-*/
+ * 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.cocoon.forms.formmodel;
 
 import java.util.ArrayList;
@@ -27,45 +27,47 @@
 import org.apache.cocoon.xml.AttributesImpl;
 
 public class EnhancedRepeater extends Repeater {
+
     private RepeaterJXPathCollection collection;
     private String customPageFieldId;
     private Field customPageField;
-	
+
     // pagination
     private int currentPage;
     private int pageSize;
 
-	
     public EnhancedRepeater(RepeaterDefinition repeaterDefinition) {
-		super(repeaterDefinition);
-    	this.currentPage = this.definition.getInitialPage();
-    	this.pageSize = this.definition.getPageSize();
+        super(repeaterDefinition);
+        this.currentPage = this.definition.getInitialPage();
+        this.pageSize = this.definition.getPageSize();
         this.customPageFieldId = this.definition.getCustomPageId();
-	}
+    }
 
-	public void doPageLoad() throws BindingException {
+    public void doPageLoad() throws BindingException {
         clearAllRows();
         collection.flushCachedItems();
         int start = getStartIndex();
         List items = collection.getItems(start, this.pageSize);
         for (Iterator iter = items.iterator(); iter.hasNext();) {
-			RepeaterItem item = (RepeaterItem) iter.next();
-	        if (item == null) break;
+            RepeaterItem item = (RepeaterItem) iter.next();
+            if (item == null) {
+                break;
+            }
             if (item.getRow() != null) {
-            	addRow(item.getRow());
+                addRow(item.getRow());
             } else {
                 RepeaterRow thisRow = addRow();
                 item.setRow(thisRow);
                 collection.getAdapter().populateRow(item);
             }
         }
-        
+
         // set customPageField
         if (this.customPageField != null) {
             StaticSelectionList selectionList = new StaticSelectionList(this.customPageField.getDatatype());
             int j;
-            for (j = 0; j <= this.getMaxPage();j++) {
-                selectionList.addItem(new Integer(j),(j+1)+"");
+            for (j = 0; j <= this.getMaxPage(); j++) {
+                selectionList.addItem(new Integer(j), (j + 1) + "");
             }
             this.customPageField.setSelectionList(selectionList);
             this.customPageField.setValue(new Integer(this.currentPage));
@@ -79,7 +81,7 @@
     public void doPageSave() throws BindingException {
         List tempUpdatedRows = new ArrayList();
         List tempInsertedRows = new ArrayList();
-        
+
         List cache = collection.getCachedItems();
         // iterate rows in the form model...
         int formRowCount = getSize();
@@ -87,78 +89,80 @@
             Repeater.RepeaterRow thisRow = getRow(i);
             boolean found = false;
             for (int j = 0; j < cache.size(); j++) {
-            	RepeaterItem item = (RepeaterItem) cache.get(j);
-            	if (item == null) break;
-            	if (item.getRow() == thisRow) {
-                	// Found the matching row
-                	// TODO we need a way to know if the row was really modified or not, maybe a FormHandler?
-                	tempUpdatedRows.add(item);
+                RepeaterItem item = (RepeaterItem) cache.get(j);
+                if (item == null) {
+                    break;
+                }
+                if (item.getRow() == thisRow) {
+                    // Found the matching row
+                    // TODO we need a way to know if the row was really modified or not, maybe a FormHandler?
+                    tempUpdatedRows.add(item);
                     found = true;
                     break;
                 }
             }
             if (!found) {
-            	tempInsertedRows.add(thisRow);
+                tempInsertedRows.add(thisRow);
             }
         }
-        
+
         List toDelete = new ArrayList();
         for (int j = 0; j < cache.size(); j++) {
-        	RepeaterItem item = (RepeaterItem) cache.get(j);
-        	if (item == null) break;
-        	boolean found = false;
+            RepeaterItem item = (RepeaterItem) cache.get(j);
+            if (item == null) {
+                break;
+            }
+            boolean found = false;
             for (int i = 0; i < formRowCount; i++) {
                 Repeater.RepeaterRow thisRow = getRow(i);
                 if (thisRow == item.getRow()) {
-                	found = true;
-                	break;
+                    found = true;
+                    break;
                 }
             }
             if (!found) {
-            	toDelete.add(item);
+                toDelete.add(item);
             }
         }
         for (Iterator iter = tempUpdatedRows.iterator(); iter.hasNext();) {
-			RepeaterItem ele = (RepeaterItem) iter.next();
-			collection.updateRow(ele);
-		}
+            RepeaterItem ele = (RepeaterItem) iter.next();
+            collection.updateRow(ele);
+        }
         for (Iterator iter = tempInsertedRows.iterator(); iter.hasNext();) {
-        	RepeaterRow row = (RepeaterRow) iter.next();
-			collection.addRow(row);
-		}
+            RepeaterRow row = (RepeaterRow) iter.next();
+            collection.addRow(row);
+        }
         for (Iterator iter = toDelete.iterator(); iter.hasNext();) {
-        	RepeaterItem ele = (RepeaterItem) iter.next();
-			collection.deleteRow(ele);
-		}
+            RepeaterItem ele = (RepeaterItem) iter.next();
+            collection.deleteRow(ele);
+        }
         collection.flushCachedItems();
     }
-	
+
     private int getStartIndex() {
         return this.currentPage * this.pageSize;
     }
-            
+
     public int getMaxPage() {
         return ((int)(Math.ceil((double)collection.getActualCollectionSize() / (double)pageSize))) - 1;
     }
-    
+
     public int getCustomPageWidgetValue() {
-        return ((Integer)this.customPageField.getValue()).intValue();
+        return ((Integer) this.customPageField.getValue()).intValue();
     }
-    
+
     public int getCurrentPage() {
         return currentPage;
     }
 
-    
-    
     /*
      * convenience methods for presentation
      */
-    
+
     public int getDisplayableCurrentPage() {
         return this.getCurrentPage() + 1;
     }
-    
+
     public int getDisplayableLastPage() {
         // increment if we created a new page for insertion
         if (this.getCurrentPage() > this.getMaxPage()) {
@@ -166,84 +170,84 @@
         }
         return this.getMaxPage() + 1;
     }
-    
+
     public boolean isFirstPage() {
         return this.getCurrentPage() == 0;
     }
-    
+
     public boolean isLastPage() {
-    	return this.getCurrentPage() >= this.getMaxPage();
+        return this.getCurrentPage() >= this.getMaxPage();
+    }
+
+    public int getPageSize() {
+        return pageSize;
+    }
+
+    public void setPageSize(int pageSize) {
+        this.pageSize = pageSize;
+    }
+
+    public boolean isEnhanced() {
+        return true;
+    }
+
+    public AttributesImpl getXMLElementAttributes() {
+        AttributesImpl elementAttributes = super.getXMLElementAttributes();
+        if (this.pageSize < Integer.MAX_VALUE) {
+            elementAttributes.addCDATAAttribute("page", String.valueOf(currentPage));
+        }
+        return elementAttributes;
     }
 
-	public int getPageSize() {
-		return pageSize;
-	}
-
-	public void setPageSize(int pageSize) {
-		this.pageSize = pageSize;
-	}
-
-	public boolean isEnhanced() {
-		return true;
-	}
-
-	public AttributesImpl getXMLElementAttributes() {
-		AttributesImpl elementAttributes = super.getXMLElementAttributes();
-	    if (this.pageSize < Integer.MAX_VALUE) {
-	    	elementAttributes.addCDATAAttribute("page", String.valueOf(currentPage));
-	    }
-		return elementAttributes;
-	}
-	
     private void addRow(RepeaterRow row) {
-    	rows.add(row);
+        rows.add(row);
         getForm().addWidgetUpdate(this);
     }
-    
+
     private void clearAllRows() {
-        rows.clear();    	
+        rows.clear();
         getForm().addWidgetUpdate(this);
     }
 
-	public void setCollection(RepeaterJXPathCollection collection) {
-		this.collection = collection;
-	}
+    public void setCollection(RepeaterJXPathCollection collection) {
+        this.collection = collection;
+    }
 
-	public void initialize() {
-		super.initialize();
+    public void initialize() {
+        super.initialize();
         Widget widget = getForm().lookupWidget(this.customPageFieldId);
         if (widget instanceof Field) {
-            this.customPageField = (Field)widget;
+            this.customPageField = (Field) widget;
         }
-	}
+    }
+
+    public RepeaterJXPathCollection getCollection() {
+        return collection;
+    }
+
+    public void refreshPage() throws BindingException {
+        doPageSave();
+        doPageLoad();
+    }
+
+    public void goToPage(int page) throws BindingException {
+        doPageSave();
+        this.currentPage = page;
+        doPageLoad();
+    }
+
+    public void sortBy(String field) throws BindingException {
+        doPageSave();
+        this.collection.sortBy(field);
+        this.currentPage = 0;
+        doPageLoad();
+    }
+
+    public void setFilter(String field, Object value) throws BindingException {
+        doPageSave();
+        this.collection.filter(field, value);
+        this.currentPage = 0;
+        doPageLoad();
+    }
 
-	public RepeaterJXPathCollection getCollection() {
-		return collection;
-	}
-
-	public void refreshPage() throws BindingException {
-		doPageSave();
-		doPageLoad();
-	}
-
-	public void goToPage(int page) throws BindingException {
-		doPageSave();
-		this.currentPage = page;
-		doPageLoad();
-	}
-
-	public void sortBy(String field) throws BindingException {
-		doPageSave();
-		this.collection.sortBy(field);
-		this.currentPage = 0;
-		doPageLoad();
-	}
-
-	public void setFilter(String field, Object value) throws BindingException {
-		doPageSave();
-		this.collection.filter(field, value);
-		this.currentPage = 0;
-		doPageLoad();		
-	}
-    
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java?rev=775627&r1=775626&r2=775627&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/formmodel/RepeaterActionDefinition.java Sun May 17 11:27:21 2009
@@ -23,9 +23,9 @@
 import org.apache.cocoon.forms.event.ActionListener;
 
 /**
- * Abstract repeater action. Subclasses will typically just self-add an
- * event handler that will act on the repeater.
- *
+ * Abstract repeater action. Subclasses will typically just self-add an event
+ * handler that will act on the repeater.
+ * 
  * @see RepeaterActionDefinitionBuilder
  * @version $Id$
  */
@@ -70,15 +70,15 @@
     /**
      * Get the name of the repeater on which to act. If <code>null</code>, the repeater
      * is the parent of the current widget (i.e. actions are in repeater rows). Otherwise,
-     * the repeater is a sibling of the current widget.
-     *
+     *the repeater is a sibling of the current widget.
+     * 
      * @return the repeater name (can be <code>null</code>).
      */
     public String getRepeaterName() {
         return this.name;
     }
 
-    //---------------------------------------------------------------------------------------------
+    // ---------------------------------------------------------------------------------------------
 
     /**
      * The definition of a repeater action that deletes the selected rows of a sibling repeater.
@@ -141,7 +141,7 @@
         }
     }
 
-    //---------------------------------------------------------------------------------------------
+    // ---------------------------------------------------------------------------------------------
 
     /**
      * The definition of a repeater action that adds a row to a sibling repeater.
@@ -157,11 +157,11 @@
                 public void actionPerformed(ActionEvent event) {
                     Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
                     if (repeater instanceof EnhancedRepeater) {
-                    	try {
+                        try {
                             ((EnhancedRepeater) repeater).goToPage(((EnhancedRepeater) repeater).getMaxPage());
                         } catch (BindingException e) {
-							throw new CascadingRuntimeException("Error switching page", e);
-						}
+                            throw new CascadingRuntimeException("Error switching page", e);
+                        }
                     }
                     for (int i = 0; i < AddRowActionDefinition.this.insertRows; i++) {
                         repeater.addRow();
@@ -169,10 +169,10 @@
                 }
             });
         }
-        
+
     }
 
-    //---------------------------------------------------------------------------------------------
+    // ---------------------------------------------------------------------------------------------
 
     /**
      * The definition of a repeater action that insert rows before the selected rows in a sibling repeater,
@@ -224,22 +224,22 @@
             });
         }
     }
-    
+
     public static class SortActionDefinition extends RepeaterActionDefinition {
-    	protected String field = null;
-    	
+        protected String field = null;
+
         public SortActionDefinition(String repeaterName, String field) {
             super(repeaterName);
             this.field = field;
-            
+
             this.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent event) {
                     Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
                     if (repeater instanceof EnhancedRepeater) {
-                    	EnhancedRepeater erep = (EnhancedRepeater) repeater;
+                        EnhancedRepeater erep = (EnhancedRepeater) repeater;
                         try {
                             if (repeater.validate()) {
-                            	erep.sortBy(SortActionDefinition.this.field);
+                                erep.sortBy(SortActionDefinition.this.field);
                             }
                         } catch (Exception e) {
                             throw new CascadingRuntimeException("Error switching page", e);
@@ -247,44 +247,43 @@
                     }
                 }
             });
-            
+
         }
     }
 
-  
     public static class ChangePageActionDefinition extends RepeaterActionDefinition {
 
-       protected int method;
-       
-       public static final int FIRST = 0; 
-       public static final int PREV = 1;
-       public static final int NEXT = 2;
-       public static final int LAST = 3;
-       public static final int CUSTOM = 4;
+        protected int method;
+
+        public static final int FIRST = 0;
+        public static final int PREV = 1;
+        public static final int NEXT = 2;
+        public static final int LAST = 3;
+        public static final int CUSTOM = 4;
 
         /**
          * initialize this definition with the other, sort of like a copy constructor
          */
         public void initializeFrom(WidgetDefinition definition) throws Exception {
             super.initializeFrom(definition);
-            if(definition instanceof ChangePageActionDefinition) {
-                ChangePageActionDefinition other = (ChangePageActionDefinition)definition;
+            if (definition instanceof ChangePageActionDefinition) {
+                ChangePageActionDefinition other = (ChangePageActionDefinition) definition;
                 this.method = other.method;
             } else {
-                throw new Exception("Definition to inherit from is not of the right type! (at "+getLocation()+")");
+                throw new Exception("Definition to inherit from is not of the right type! (at " + getLocation() + ")");
             }
         }
 
         public ChangePageActionDefinition(String repeaterName, int m) {
             super(repeaterName);
-            
+
             this.method = m;
-            
+
             this.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent event) {
                     Repeater repeater = ((RepeaterAction)event.getSource()).getRepeater();
                     if (repeater instanceof EnhancedRepeater) {
-                    	EnhancedRepeater erep = (EnhancedRepeater) repeater;
+                        EnhancedRepeater erep = (EnhancedRepeater) repeater;
                         int page = erep.getCurrentPage();
                         if (method == FIRST) {
                             page = 0;
@@ -301,15 +300,15 @@
                         }
                         try {
                             if (repeater.validate()) {
-                            	erep.goToPage(page);
+                                erep.goToPage(page);
                             }
                         } catch (Exception e) {
                             throw new CascadingRuntimeException("Error switching page", e);
                         }
-                    } 
+                    }
                 }
             });
         }
     }
-    
+
 }