You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by hu...@apache.org on 2002/10/18 22:45:50 UTC
cvs commit: jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util Scroller.java ResultListBase.java ResultList.java ProcessResultBase.java ProcessBeanBase.java ProcessBean.java
husted 2002/10/18 13:45:50
Modified: scaffold/src/java/org/apache/commons/scaffold/util
Scroller.java ResultListBase.java ResultList.java
ProcessResultBase.java ProcessBeanBase.java
ProcessBean.java
Log:
+ ProcessBean,*Base: Add ScrollFrom property to manage a scroller.
+ ResultList,*Base: Add Scroller property.
Revision Changes Path
1.2 +61 -5 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/Scroller.java
Index: Scroller.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/Scroller.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Scroller.java 9 Oct 2002 22:04:09 -0000 1.1
+++ Scroller.java 18 Oct 2002 20:45:49 -0000 1.2
@@ -10,12 +10,14 @@
* but does not support paging per se goto page 3 (or entry 30)),
* though that would be an easy enhancement.
*
+ * @author James Klicman <ja...@jsptags.com>
* @author Ted Husted
* @version $Revision$ $Date$
*/
public class Scroller {
- public Scroller(int limit, int count) {
+ public Scroller(int from, int limit, int count) {
+ setFrom(from);
setLimit(limit);
setCount(count);
}
@@ -25,10 +27,18 @@
// ---------------------------------------------------------------- Properties
+
+ /**
+ * The default starting point [1].
+ * The value is for the convenience of SQL, which is one-based.
+ */
+ public static int FROM = 1;
+
+
/**
- * The starting point for the current query [1].
+ * The starting point for the current query [FROM].
*/
- protected int from = 1; // SQL is one-based
+ protected int from = FROM;
/**
@@ -172,7 +182,6 @@
}
-
/**
* The maximum number of entries available (the SQL count).
*
@@ -213,6 +222,53 @@
return(--from);
}
+
+ /**
+ * Return page number for given entry.
+ * @returns The number of pages
+ */
+ public int getPage(int thru) {
+
+ int limit = getLimit();
+
+ if ((0==thru) || (0==limit)) return 1;
+
+ double page = (thru / limit) + (thru % limit == 0 ? 0 : 1);
+
+ return new Double(page).intValue();
+ }
+
+
+ /**
+ * Return current page number
+ * @returns The number of pages
+ */
+ public int getPage() {
+
+ return getPage(getThru());
+ }
+
+
+ /**
+ * Return number of pages.
+ * @returns The number of pages
+ */
+ public int getPages() {
+
+ return getPage(getCount());
+ }
+
+
+ /**
+ * Return first entry for given page.
+ * @returns first entry for given page
+ */
+ public int getOffsetForPage(int page) {
+
+ int limit = getLimit();
+
+ return ((page*limit)-limit)+1;
+ }
/**
1.3 +36 -121 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ResultListBase.java
Index: ResultListBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ResultListBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResultListBase.java 12 Sep 2002 12:38:14 -0000 1.2
+++ ResultListBase.java 18 Oct 2002 20:45:49 -0000 1.3
@@ -7,10 +7,8 @@
import java.util.List;
import java.util.Map;
-// import org.apache.struts.util.BeanUtils; // Struts 1.0.x
-// import org.apache.struts.util.PropertyUtils; // Struts 1.0.x
-import org.apache.commons.beanutils.BeanUtils; // Struts 1.1
-import org.apache.commons.beanutils.PropertyUtils; // Struts 1.1
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.scaffold.lang.ChainedException;
import org.apache.commons.scaffold.lang.Tokens;
@@ -32,44 +30,60 @@
protected List result = (List) new ArrayList();
- /**
- * Return the result list (an ArrayList).
- * @returns the result list
- */
public List getResult() {
return this.result;
}
- /**
- * Assign a new result list.
- * Will clear existing list if new result is null.
- * Will not assign null to result.
- */
public void setResult(List result) {
this.result = result;
}
+
/**
- * A result code, if returned by the resource layer.
+ * Our scroller object for paging through lists.
*/
- private Integer code = null;
+ protected Scroller scroller = null;
+
+
+ public void setScroller(Scroller scroller){
+ this.scroller = scroller;
+ }
+
+
+ public Scroller getScroller() {
+ return this.scroller;
+ }
/**
- * Return the code.
- * @return the code
+ * Our intial counter value [0].
*/
- public Integer getCode() {
- return (this.code);
+ private int counter = 0;
+
+
+ public int getCounter() {
+ return counter++;
+ }
+
+
+ public void setCounter(int counter) {
+ this.counter = counter;
}
/**
- * Set the code.
- * @param code The new code
+ * A result code, if returned by the resource layer.
*/
+ private Integer code = null;
+
+
+ public Integer getCode() {
+ return (this.code);
+ }
+
+
public void setCode(Integer code) {
this.code = code;
}
@@ -82,28 +96,16 @@
private String legend = null;
- /**
- * Return the legend.
- * @return the legend
- */
public String getLegend() {
return (this.legend);
}
- /**
- * Set the legend.
- * @param legend The new legend
- */
public void setLegend(String legend) {
this.legend = legend;
}
- /**
- * Set the legend.
- * @param legend The new legend
- */
public void setLegend(String name, String value) {
if ((null==value) || ("".equals(value))) {
@@ -125,22 +127,11 @@
protected Map displayName = null;
- /**
- * Return the displayName map (a HashMap).
- * These are localized titles for the
- * properties names in the result list.
- * @returns the displayName list
- */
public Map getDisplayName() {
return this.displayName;
}
- /**
- * Assign a new displayName list.
- * These are localized titles for the
- * properties names in the result list.
- */
public void setDisplayName(Map displayName) {
this.displayName = displayName;
}
@@ -153,20 +144,11 @@
// ----- array operations -----
- /**
- * Returns an array containing all of the elements in this collection.
- * @return an array containing all of the elements in this collection
- */
public Object[] toArray() {
return getResult().toArray();
}
- /**
- * Returns an array containing all of the elements in this collection; the
- * runtime type of the returned array is that of the specified array.
- * @return an array containing the elements of this collection
- */
public Object[] toArray(Object a[]) {
return getResult().toArray(a);
}
@@ -175,47 +157,26 @@
// ----- basic operations -----
- /**
- * Returns true if this collection contains no elements.
- * @return true if this collection contains no elements
- */
public boolean isEmpty() {
return getResult().isEmpty();
}
- /**
- * Return the number of elements on the List.
- * @return the size of the List
- */
public int size() {
return getResult().size();
}
- /**
- * Returns true if this collection contains the specified element.
- * @return true if this collection contains the specified element
- */
public boolean contains(Object element) {
return getResult().contains(element);
}
- /**
- * Appends the specified element to the end of this list (optional
- * operation).
- * @return the row count
- */
public boolean add(Object o) {
return getResult().add(o);
}
- /**
- * Return an iterator for the List.
- * @return an iterator for the List
- */
public Iterator iterator() {
return getResult().iterator();
}
@@ -224,9 +185,6 @@
// ----- list operations -----
- /**
- * Returns the element at the specified position in this list.
- */
public Object get(int index) {
return getResult().get(index);
}
@@ -235,57 +193,31 @@
// ----- bulk operations ------
- /**
- * Appends all of the elements in the specified Collection
- * to the end of this list, in the order that they are
- * returned by the specified Collection's Iterator.
- */
public boolean addAll(Collection c) {
return getResult().addAll(c);
}
- /**
- * Removes all of the elements from this list..
- */
public void clear() {
getResult().clear();
}
- /**
- * Returns true if this collection contains all of the elements in the
- * specified collection.
- * @returns true if this collection contains all of the elements in the
- * specified collection
- */
public boolean containsAll(Collection c) {
return getResult().containsAll(c);
}
- /**
- * Removes a single instance of the specified element from this
- * collection, if it is present (optional operation).
- */
public boolean remove(Object o) {
return getResult().remove(o);
}
- /**
- * Removes all this collection's elements that are also contained in the
- * specified collection.
- */
public boolean removeAll(Collection c) {
return getResult().removeAll(c);
}
- /**
- * Retains only the elements in this collection that are contained in the
- * specified collection.
- */
public boolean retainAll(Collection c) {
return getResult().retainAll(c);
}
@@ -295,38 +227,21 @@
// ----------------------------------------------------------- Public Methods
- /**
- * Convenience accessor for <code>get()</code>.
- */
public Object getElement(int index) {
return getResult().get(index);
}
- /**
- * Convenience accessor for <code>iterator()</code>.
- * @return an iterator for the List
- */
public Iterator getIterator() {
return iterator();
}
- /**
- * Convenience accessor for <code>size()</code>.
- * @return the size of the List
- */
public int getSize() {
return size();
}
- /**
- * Populate matching properties on given object,
- * using bean at given index. Returns false if index>size.
- * <code>PropertyUtils.describe</code>.
- * @exception Throws StateException on any error.
- */
public boolean populate(Object o, int index) throws Exception {
Object bean = null;
if (size()>index)
1.3 +47 -5 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ResultList.java
Index: ResultList.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ResultList.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ResultList.java 12 Sep 2002 12:38:14 -0000 1.2
+++ ResultList.java 18 Oct 2002 20:45:49 -0000 1.3
@@ -7,10 +7,8 @@
import java.util.List;
import java.util.Map;
-// import org.apache.struts.util.BeanUtils; // Struts 1.0.x
-// import org.apache.struts.util.PropertyUtils; // Struts 1.0.x
-import org.apache.commons.beanutils.BeanUtils; // Struts 1.1
-import org.apache.commons.beanutils.PropertyUtils; // Struts 1.1
+import org.apache.commons.beanutils.BeanUtils;
+import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.scaffold.lang.ChainedException;
@@ -35,6 +33,50 @@
* @returns the result list
*/
public List getResult();
+
+
+ /**
+ * Set our result
+ * @param result The new result
+ */
+ public void setResult(List result);
+
+
+ /**
+ * Return our scroller.
+ * The scroller object tracks the client's current
+ * position in a result list.
+ * The database (or a cache) can return part of a
+ * larger list at a time.
+ * The scroller object can be used to request the
+ * appropriate next or previous entry on the list,
+ * and also to display the relative postion of the
+ * first item in this batch (x of xx).
+ * @return Our scroller
+ */
+ public Scroller getScroller();
+
+
+ /**
+ * Set our scroller.
+ * @param scroller The new scroller
+ */
+ public void setScroller(Scroller scroller);
+
+
+ /**
+ * Convenience method for maintaining a counter
+ * that can be shared among multiple components
+ * in some presentation systems (e.g, Tiles).
+ * @returns The next counter value
+ */
+ public int getCounter();
+
+
+ /**
+ * Set a new counter value.
+ */
+ public void setCounter(int counter);
/**
1.3 +17 -3 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessResultBase.java
Index: ProcessResultBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessResultBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProcessResultBase.java 12 Sep 2002 12:38:14 -0000 1.2
+++ ProcessResultBase.java 18 Oct 2002 20:45:49 -0000 1.3
@@ -6,8 +6,7 @@
import java.util.Iterator;
import java.util.List;
-// import org.apache.struts.util.BeanUtils; // Struts 1.0.x
-import org.apache.commons.beanutils.BeanUtils; // Struts 1.1
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.scaffold.lang.Tokens;
@@ -312,6 +311,21 @@
this.dispatchPath = dispatchPath;
}
+
+ /**
+ * Our scroller object for paging through lists.
+ */
+ protected Scroller scroller = null;
+
+
+ public void setScroller(Scroller scroller){
+ this.scroller = scroller;
+ }
+
+
+ public Scroller getScroller() {
+ return this.scroller;
+ }
// ----------------------------------------------------------- Constructors
1.5 +18 -23 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBeanBase.java
Index: ProcessBeanBase.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBeanBase.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ProcessBeanBase.java 9 Oct 2002 22:04:09 -0000 1.4
+++ ProcessBeanBase.java 18 Oct 2002 20:45:49 -0000 1.5
@@ -1,15 +1,10 @@
-
-
package org.apache.commons.scaffold.util;
import java.util.Locale;
import java.util.Map;
-
-// import org.apache.struts.util.BeanUtils; // Struts 1.0.x
-import org.apache.commons.beanutils.BeanUtils; // Struts 1.1
-
+import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.scaffold.lang.ChainedException;
@@ -33,19 +28,11 @@
private Locale locale = null;
- /**
- * Return the locale for this bean instance.
- * @return the locale
- */
public Locale getLocale() {
return this.locale;
}
- /**
- * Set the locale for this bean instance.
- * @param locale The new locale
- */
public void setLocale(Locale locale) {
this.locale = locale;
}
@@ -62,22 +49,30 @@
private Object server = null;
- /**
- * Return the remote server, if any.
- * @return the remote server
- */
public Object getRemoteServer() {
return this.server;
}
- /**
- * Set the new remote server.
- * @param server The new server
- */
public void setRemoteServer(Object server) {
this.server = server;
}
+
+
+ /**
+ * The entry (or page) from which to scroll [0].
+ */
+ protected int scrollFrom = Scroller.FROM ;
+
+ public int getScrollFrom() {
+ return scrollFrom;
+ }
+
+ public void setScrollFrom(int scrollFrom) {
+ this.scrollFrom = scrollFrom;
+ }
+
+
// --------------------------------------------------------- Public Methods
1.3 +18 -1 jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBean.java
Index: ProcessBean.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/scaffold/src/java/org/apache/commons/scaffold/util/ProcessBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ProcessBean.java 9 Oct 2002 22:04:09 -0000 1.2
+++ ProcessBean.java 18 Oct 2002 20:45:49 -0000 1.3
@@ -72,6 +72,23 @@
public void setRemoteServer(Object server);
+
+ /**
+ * Return the scrollFrom property.
+ * The ScrollFrom propery can be used to update a Scroller
+ * object as to the next starting point for a result list.
+ * @return the scrollFrom
+ */
+ public int getScrollFrom();
+
+
+ /**
+ * Set the scrollFrom
+ * @param scrollFrom The new scrollFrom
+ */
+ public void setScrollFrom(int scrollFrom);
+
+
// ------------------------------------------------------- Public Methods
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>