click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r921323 [5/5] - in /click/trunk/click: build/ documentation/docs/ examples/src/org/apache/click/examples/control/ examples/src/org/apache/click/examples/control/cayenne/ examples/src/org/apache/click/examples/control/exporter/ examples/src/...
Date Wed, 10 Mar 2010 12:06:36 GMT
Modified: click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/service/ClientService.java Wed Mar 10 12:06:32 2010
@@ -52,6 +52,7 @@ public class ClientService extends Cayen
         commitChanges();
     }
 
+    @SuppressWarnings("deprecation")
     public Client createClientInNestedContext() {
         return (Client) getDataContext().createChildDataContext().
             createAndRegisterNewObject(Client.class);

Modified: click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/service/CustomerService.java Wed Mar 10 12:06:32 2010
@@ -250,6 +250,7 @@ public class CustomerService extends Cay
     /**
      * A custom Cayenne query which performs a count(*) query on the database.
      */
+    @SuppressWarnings("unchecked")
     class CountQuery extends IndirectQuery {
 
         private static final long serialVersionUID = 1L;
@@ -260,6 +261,7 @@ public class CustomerService extends Cay
             this.objectClass = objectClass;
         }
 
+        @SuppressWarnings("deprecation")
         protected Query createReplacementQuery(EntityResolver resolver) {
             DbEntity entity = resolver.lookupDbEntity(objectClass);
 

Modified: click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/service/StudentService.java Wed Mar 10 12:06:32 2010
@@ -1,147 +1,151 @@
-/*
- * 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.click.examples.service;
-
-import java.util.Iterator;
-import java.util.List;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.Ordering;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.click.examples.domain.Course;
-import org.apache.click.examples.domain.Student;
-import org.apache.click.examples.domain.StudentHouse;
-import org.apache.click.extras.cayenne.CayenneTemplate;
-import org.springframework.stereotype.Component;
-
-/**
- * Provides a Student Service.
- */
-@Component
-public class StudentService extends CayenneTemplate {
-
-    // ---------------------------------------------------------- Student logic
-
-    public List getStudents() {
-        SelectQuery query = new SelectQuery(Student.class);
-        query.addPrefetch("studentHouse");
-        query.addOrdering("db:id", true);
-        return performQuery(query);
-    }
-
-    public Student getStudent(Object id) {
-        SelectQuery query = new SelectQuery(Student.class);
-        query.addPrefetch("courses");
-        query.addPrefetch("studentHouse");
-        query.setQualifier(ExpressionFactory.matchDbExp("id", id));
-
-        List students = getDataContext().performQuery(query);
-
-        if (students.size() == 0) {
-            return null;
-        }
-
-        if (students.size() == 1) {
-            return (Student) students.get(0);
-        } else {
-            String msg = "SelectQuery for " + Student.class.getName()
-                    + " where id equals " + id + " returned "
-                    + students.size() + " rows";
-            throw new RuntimeException(msg);
-        }
-    }
-
-    public void saveStudent(Student student) {
-        if (student.getObjectContext() == null) {
-            registerNewObject(student);
-        }
-        commitChanges();
-    }
-
-    // ----------------------------------------------------------- Course logic
-
-    public void setStudentCourses(Student student, List courseIds) {
-        // First remove current courses
-        List removes = student.getCourses();
-        for (int i = removes.size() - 1; i >= 0; i--) {
-            Course course = (Course) removes.get(i);
-            student.removeFromCourses(course);
-        }
-
-        if (courseIds == null || courseIds.isEmpty()) {
-            return;
-        }
-
-        // Next, set the new courses
-        SelectQuery query = new SelectQuery(Course.class);
-        query.setQualifier(ExpressionFactory.inDbExp("id", courseIds));
-        List courses = getDataContext().performQuery(query);
-
-        for (Iterator it = courses.iterator(); it.hasNext(); ) {
-            Course course = (Course) it.next() ;
-            student.addToCourses(course);
-        }
-    }
-
-    public List getCourses() {
-        SelectQuery query = new SelectQuery(Course.class);
-        query.addOrdering("db:id", true);
-        return performQuery(query);
-    }
-
-    public Course getCourse(Object id) {
-        return (Course) getObjectForPK(Course.class, id);
-    }
-
-    public void saveCourse(Course course) {
-        if (course.getObjectContext() == null) {
-            registerNewObject(course);
-        }
-        commitChanges();
-    }
-
-    // ---------------------------------------------------- Student House logic
-
-    public List getStudentsByHouse() {
-        SelectQuery query = new SelectQuery(Student.class);
-        query.addPrefetch("studentHouse");
-
-        // Add in-memory ordering
-        Ordering ordering = new Ordering("studentHouse.name", true);
-        List result = performQuery(query);
-        ordering.orderList(result);
-        return result;
-    }
-
-    public List getStudentHouses() {
-        SelectQuery query = new SelectQuery(StudentHouse.class);
-        query.addOrdering(StudentHouse.NAME_PROPERTY, true);
-        return performQuery(query);
-    }
-
-    public StudentHouse getStudentHouse(Object id) {
-        return (StudentHouse) getObjectForPK(StudentHouse.class, id);
-    }
-
-    public void saveStudentHouse(StudentHouse studentHouse) {
-        if (studentHouse.getObjectContext() == null) {
-            registerNewObject(studentHouse);
-        }
-        commitChanges();
-    }
-}
+/*
+ * 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.click.examples.service;
+
+import java.util.List;
+
+import org.apache.cayenne.exp.ExpressionFactory;
+import org.apache.cayenne.query.Ordering;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.click.examples.domain.Course;
+import org.apache.click.examples.domain.Student;
+import org.apache.click.examples.domain.StudentHouse;
+import org.apache.click.extras.cayenne.CayenneTemplate;
+import org.springframework.stereotype.Component;
+
+/**
+ * Provides a Student Service.
+ */
+@Component
+public class StudentService extends CayenneTemplate {
+
+    // ---------------------------------------------------------- Student logic
+
+    @SuppressWarnings("unchecked")
+    public List<Student> getStudents() {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("studentHouse");
+        query.addOrdering("db:id", true);
+        return performQuery(query);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Student getStudent(Object id) {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("courses");
+        query.addPrefetch("studentHouse");
+        query.setQualifier(ExpressionFactory.matchDbExp("id", id));
+
+        List<Student> students = getDataContext().performQuery(query);
+
+        if (students.size() == 0) {
+            return null;
+        }
+
+        if (students.size() == 1) {
+            return students.get(0);
+        } else {
+            String msg = "SelectQuery for " + Student.class.getName()
+                    + " where id equals " + id + " returned "
+                    + students.size() + " rows";
+            throw new RuntimeException(msg);
+        }
+    }
+
+    public void saveStudent(Student student) {
+        if (student.getObjectContext() == null) {
+            registerNewObject(student);
+        }
+        commitChanges();
+    }
+
+    // ----------------------------------------------------------- Course logic
+
+    @SuppressWarnings("unchecked")
+    public void setStudentCourses(Student student, List courseIds) {
+        // First remove current courses
+        List<Course> removes = student.getCourses();
+        for (Course course : removes) {
+            student.removeFromCourses(course);
+        }
+
+        if (courseIds == null || courseIds.isEmpty()) {
+            return;
+        }
+
+        // Next, set the new courses
+        SelectQuery query = new SelectQuery(Course.class);
+        query.setQualifier(ExpressionFactory.inDbExp("id", courseIds));
+        List<Course> courses = getDataContext().performQuery(query);
+
+        for (Course course : courses) {
+            student.addToCourses(course);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<Course> getCourses() {
+        SelectQuery query = new SelectQuery(Course.class);
+        query.addOrdering("db:id", true);
+        return performQuery(query);
+    }
+
+    public Course getCourse(Object id) {
+        return (Course) getObjectForPK(Course.class, id);
+    }
+
+    public void saveCourse(Course course) {
+        if (course.getObjectContext() == null) {
+            registerNewObject(course);
+        }
+        commitChanges();
+    }
+
+    // ---------------------------------------------------- Student House logic
+
+    @SuppressWarnings("unchecked")
+    public List<Student> getStudentsByHouse() {
+        SelectQuery query = new SelectQuery(Student.class);
+        query.addPrefetch("studentHouse");
+
+        // Add in-memory ordering
+        Ordering ordering = new Ordering("studentHouse.name", true);
+        List<Student> result = performQuery(query);
+        ordering.orderList(result);
+        return result;
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<StudentHouse> getStudentHouses() {
+        SelectQuery query = new SelectQuery(StudentHouse.class);
+        query.addOrdering(StudentHouse.NAME_PROPERTY, true);
+        return performQuery(query);
+    }
+
+    public StudentHouse getStudentHouse(Object id) {
+        return (StudentHouse) getObjectForPK(StudentHouse.class, id);
+    }
+
+    public void saveStudentHouse(StudentHouse studentHouse) {
+        if (studentHouse.getObjectContext() == null) {
+            registerNewObject(studentHouse);
+        }
+        commitChanges();
+    }
+}

Modified: click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsAdaptor.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsAdaptor.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsAdaptor.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsAdaptor.java Wed Mar 10 12:06:32 2010
@@ -22,6 +22,10 @@ import org.apache.click.examples.domain.
 import org.springframework.security.GrantedAuthority;
 import org.springframework.security.userdetails.UserDetails;
 
+/**
+ * Provides a Spring Security (ACEGI) UserDetails adaptor class, which wraps the
+ * User class in the Spring Security UserDetails interface.
+ */
 public class UserDetailsAdaptor implements UserDetails {
 
     private static final long serialVersionUID = 1L;

Modified: click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsService.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsService.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/springsecurity/UserDetailsService.java Wed Mar 10 12:06:32 2010
@@ -27,6 +27,9 @@ import org.springframework.security.user
 import org.springframework.security.userdetails.UsernameNotFoundException;
 import org.springframework.stereotype.Component;
 
+/**
+ * Provides a Spring Security (ACEGI) UserDetailsService for loading users.
+ */
 @Component
 public class UserDetailsService implements org.springframework.security.userdetails.UserDetailsService {
 

Modified: click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitListener.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitListener.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitListener.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/util/DatabaseInitListener.java Wed Mar 10 12:06:32 2010
@@ -64,8 +64,6 @@ import org.quartz.impl.StdSchedulerFacto
  * <p/>
  * This listener also provides a customer reloading task which runs every 15
  * minutes.
- *
- * @author Malcolm Edgar
  */
 public class DatabaseInitListener implements ServletContextListener {
 

Modified: click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/util/ExampleUtils.java Wed Mar 10 12:06:32 2010
@@ -26,8 +26,6 @@ import org.apache.click.Context;
 
 /**
  * Provides examples helper methods.
- *
- * @author Malcolm Edgar
  */
 public class ExampleUtils {
 

Modified: click/trunk/click/examples/src/org/apache/click/examples/util/customers.txt
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/util/customers.txt?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/util/customers.txt (original)
+++ click/trunk/click/examples/src/org/apache/click/examples/util/customers.txt Wed Mar 10 12:06:32 2010
@@ -94,4 +94,7 @@ Tanya Stockwell, t.stockwell@abs.com, 39
 Steve Haywood, steve.haywood@timbercorp.com, 45, Stocks, 150000,  1998-10-09, true
 Rove Apple, rove.apple@bignet.com, 31, Stocks, 34000,
 Greg Matherson, gregm@bubhub.com, 27, Stocks, 234000,
-Katie Lang, klang@rockit.net, 21, Stocks
\ No newline at end of file
+Katie Lang, klang@rockit.net, 21, Stocks
+Mick Cooper, mcoper@gbh.com, 31, Stocks, 125000
+Albert Nicholes, albertn@gmail.com, 43, Stocks, 56000
+Emma Joslin, ejolin@gbh.com, 28, Stocks 34000
\ No newline at end of file

Added: click/trunk/click/extras/src/org/apache/click/extras/cayenne/QueryDataProvider.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/cayenne/QueryDataProvider.java?rev=921323&view=auto
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/cayenne/QueryDataProvider.java (added)
+++ click/trunk/click/extras/src/org/apache/click/extras/cayenne/QueryDataProvider.java Wed Mar 10 12:06:32 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.click.extras.cayenne;
+
+import java.util.List;
+
+import org.apache.cayenne.BaseContext;
+import org.apache.cayenne.query.Query;
+import org.apache.click.util.DataProvider;
+
+/**
+ * Provides a Cayenne Query DataProvider class which will perform a lazily
+ * load data.
+ */
+public class QueryDataProvider<T> implements DataProvider<T> {
+
+    /** The Cayenne query to perform when the getData method is invoked. */
+    protected Query query;
+
+    // Constructors -----------------------------------------------------------
+
+    /**
+     * Create a Query data provider with the given query.
+     *
+     * @param query the Cayenne query to execute when the getData method is
+     *     invoked
+     */
+    public QueryDataProvider(Query query) {
+        this.query = query;
+    }
+
+    // Public Methods ---------------------------------------------------------
+
+    /**
+     * Return the data list results of the query, performing the query if the
+     * data list is null.
+     *
+     * @see DataProvider#getData()
+     *
+     * @return the results of the query
+     */
+    @SuppressWarnings("unchecked")
+    public List<T> getData() {
+        return BaseContext.getThreadObjectContext().performQuery(query);
+    }
+
+}

Added: click/trunk/click/extras/src/org/apache/click/extras/util/PaginatingList.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/util/PaginatingList.java?rev=921323&view=auto
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/util/PaginatingList.java (added)
+++ click/trunk/click/extras/src/org/apache/click/extras/util/PaginatingList.java Wed Mar 10 12:06:32 2010
@@ -0,0 +1,453 @@
+/*
+ * 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.click.extras.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * Provides a paginating list for displaying a sliding window into a much larger
+ * data set. This list object is typically provided to the Table control to
+ * support table paging while also displaying a page of data.
+ *
+ * <h3>Example</h3>
+ *
+ * The example below uses a PaginatingList object in a DataProvider for a table.
+ * When the table is rendered it will call the DataProvider to load the data.
+ * The DataProvider in term calls the getPaginatingList() method which performs
+ * the database query and returns a PaginatingList to the table.
+ *
+ * <pre class="prettyprint">
+ * public class CustomerSearach extends Page {
+ *
+ *    private Table table = new Table("table");
+ *
+ *    public CustomerSearch() {
+ *        // Setup table
+ *        table.setPageSize(5);
+ *        table.setSortable(true);
+ *        table.setSorted(true);
+ *
+ *        table.addColumn(new Column("id"));
+ *        ..
+ *        addControl(table);
+ *
+ *
+ *        table.setDataProvider(new DataProvider<Customer>() {
+ *            public List<Customer> getData() {
+ *                return getPaginatingList();
+ *            }
+ *        });
+ *    }
+ *
+ *    private PaginatingList<Customer> getPaginatingList() {
+ *
+ *        // Below we retrieve only those customers between:
+ *        //     first row .. (first row + page size)
+ *        List<Customer> customerList =
+ *            customerService.getCustomersForPage(table.getFirstRow(),
+ *                                                table.getPageSize(),
+ *                                                table.getSortedColumn(),
+ *                                                table.isSortedAscending());
+ *
+ *        int customerCount = customerService.getNumberOfCustomers();
+ *
+ *        return new PaginatingList<Customer>(customerList,
+ *                                            table.getFirstRow(),
+ *                                            table.getPageSize(),
+ *                                            customerCount);
+ *    }
+ * } </pre>
+ */
+public class PaginatingList<E> implements List<E> {
+
+    private static final long serialVersionUID = 1L;
+
+    /** The first index to access. */
+    protected final int firstIndex;
+
+    /** The page data list. */
+    protected final List<E> pageData;
+
+    /** The page size. */
+    protected final int pageSize;
+
+    /** The total size of the data set. */
+    protected final int totalSize;
+
+    // Constructors -----------------------------------------------------------
+
+    /**
+     * Create a paginating list with the given pageData, first page item index,
+     * page size and the total data set size.
+     *
+     * @param pageData the page of data to display
+     * @param pageSize the number of items read from the pageData and display
+     * @param firstIndex the index of the first item to display
+     * @param totalSize the total size of the paginated data set
+     */
+    public PaginatingList(Iterator<E> pageData, int firstIndex, int pageSize, int totalSize) {
+        if (pageData == null) {
+            throw new IllegalArgumentException("Null pageData parameter");
+        }
+        if (pageSize < 0) {
+            throw new IllegalArgumentException("Illegal Capacity: " + pageSize);
+        }
+
+        // Populate the internal page data list
+        this.pageData = new ArrayList<E>(pageSize);
+        for (int i = 0; i < pageSize; i++) {
+            if (pageData.hasNext()) {
+                this.pageData.add(pageData.next());
+            } else {
+                break;
+            }
+        }
+
+        this.firstIndex = firstIndex;
+        this.pageSize = pageSize;
+        this.totalSize = totalSize;
+    }
+
+    /**
+     * Create a paginating list with the given pageData, first page item index,
+     * page size and the total data set size.
+     *
+     * @param pageData the page of data to display
+     * @param pageSize the number of items read from the pageData and display
+     * @param firstIndex the index of the first item to display
+     * @param totalSize the total size of the paginated data set
+     */
+    public PaginatingList(List<E> pageData, int firstIndex, int pageSize, int totalSize) {
+        if (pageData == null) {
+            throw new IllegalArgumentException("Null pageData parameter");
+        }
+        if (pageSize < 0) {
+            throw new IllegalArgumentException("Illegal Capacity: " + pageSize);
+        }
+
+        // Populate the internal page data list
+        this.pageData = new ArrayList<E>(pageSize);
+        int size = Math.min(pageSize, pageData.size());
+        for (int i = 0; i < size; i++) {
+            this.pageData.add(pageData.get(i));
+        }
+
+        this.firstIndex = firstIndex;
+        this.pageSize = pageSize;
+        this.totalSize = totalSize;
+    }
+
+    // Public Methods ---------------------------------------------------------
+
+    /**
+     * Returns the row at the specified index, offsetted by the current
+     * table first row value.
+     *
+     * @param index the index of the row as viewed in the Table
+     * @return the the row at the specified index, offsetted by the
+     * current table first row value.
+     */
+    public E get(int index) {
+        int realIndex = index - firstIndex;
+        return pageData.get(realIndex);
+    }
+
+    /**
+     * Return true if the total size of the data set is greater than zero.
+     *
+     * @see Collection#isEmpty()
+     *
+     * @return true if the total size of the data set is greater than 0
+     */
+    public boolean isEmpty() {
+        return totalSize <= 0;
+    }
+
+    /**
+     * Return total size of the paginated data set.
+     *
+     * @see java.util.List#size()
+     *
+     * @return total size of the paginated data set.
+     */
+    public int size() {
+        return totalSize;
+    }
+
+    /**
+     * Return the string representation of this object.
+     *
+     * @see String#toString()
+     *
+     * @return the string representation of this object
+     */
+    public String toString() {
+        return getClass().getSimpleName()
+            + "[pageData.size=" + pageData.size()
+            + ",firstIndex=" + firstIndex
+            + ",pageSize=" + pageSize
+            + ",totalSize=" + totalSize + "]";
+    }
+
+    // Unsupported Methods ----------------------------------------------------
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#add(Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean add(E o) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#addAll(int, Collection)a
+     *
+     * @throws UnsupportedOperationException
+     */
+    public void add(int index, E element) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#addAll(Collection)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean addAll(Collection<? extends E> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#addAll(int, Collection)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean addAll(int index, Collection<? extends E> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#clear()
+     *
+     * @throws UnsupportedOperationException
+     */
+    public void clear() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#contains(Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean contains(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#containsAll(Collection)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean containsAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#indexOf(Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public int indexOf(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#iterator()
+     *
+     * @throws UnsupportedOperationException
+     */
+    public Iterator<E> iterator() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#lastIndexOf(Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public int lastIndexOf(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#listIterator()
+     *
+     * @throws UnsupportedOperationException
+     */
+    public ListIterator<E> listIterator() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#listIterator(int)
+     */
+    public ListIterator<E> listIterator(int index) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#remove(Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#remove(int)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public E remove(int index) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#removeAll(Collection)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean removeAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#retainAll(Collection)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public boolean retainAll(Collection<?> c) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#set(int, Object)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public E set(int index, E element) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#subList(int, int)
+     *
+     * @throws UnsupportedOperationException
+     */
+    public List<E> subList(int fromIndex, int toIndex) {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#toArray()
+     *
+     * @throws UnsupportedOperationException
+     */
+    public Object[] toArray() {
+        throw new UnsupportedOperationException();
+
+    }
+
+    /**
+     * This method is not supported and will throw
+     * <tt>UnsupportedOperationException</tt> if invoked.
+     *
+     * @see List#toArray(Object[])
+     *
+     * @throws UnsupportedOperationException
+     */
+    public <T> T[] toArray(T[] a) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Added: click/trunk/click/extras/src/org/apache/click/extras/util/package.html
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/util/package.html?rev=921323&view=auto
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/util/package.html (added)
+++ click/trunk/click/extras/src/org/apache/click/extras/util/package.html Wed Mar 10 12:06:32 2010
@@ -0,0 +1,22 @@
+<!--
+   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.
+-->
+
+<body>
+Provides miscellaneous utility classes.
+</body>
\ No newline at end of file

Modified: click/trunk/click/framework/src/org/apache/click/Context.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/Context.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/Context.java (original)
+++ click/trunk/click/framework/src/org/apache/click/Context.java Wed Mar 10 12:06:32 2010
@@ -756,6 +756,7 @@ public class Context {
      * @return rendered Velocity template merged with the model data
      * @throws RuntimeException if an error occurs
      */
+    @SuppressWarnings("unchecked")
     public String renderTemplate(Class templateClass, Map<String, Object> model) {
 
         if (templateClass == null) {

Modified: click/trunk/click/framework/src/org/apache/click/control/Table.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Table.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Table.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Table.java Wed Mar 10 12:06:32 2010
@@ -28,9 +28,10 @@ import java.util.Set;
 import java.util.StringTokenizer;
 
 import org.apache.click.Control;
+import org.apache.click.element.Element;
 import org.apache.click.util.ClickUtils;
+import org.apache.click.util.DataProvider;
 import org.apache.click.util.HtmlStringBuffer;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 
@@ -265,10 +266,10 @@ public class Table extends AbstractContr
 
     private static final long serialVersionUID = 1L;
 
-    private static final Set DARK_STYLES;
+    private static final Set<String> DARK_STYLES;
 
     static {
-        DARK_STYLES = new HashSet();
+        DARK_STYLES = new HashSet<String>();
         DARK_STYLES.add("isi");
         DARK_STYLES.add("nocol");
         DARK_STYLES.add("report");
@@ -369,20 +370,24 @@ public class Table extends AbstractContr
     protected int bannerPosition = POSITION_BOTTOM;
 
     /** The map of table columns keyed by column name. */
-    protected Map columns = new HashMap();
+    protected Map<String, Column> columns = new HashMap<String, Column>();
 
     /** The list of table Columns. */
-    protected List columnList = new ArrayList();
+    protected List<Column> columnList = new ArrayList<Column>();
 
     /** The table paging and sorting control action link. */
     protected ActionLink controlLink;
 
     /** The list of table controls. */
-    protected List controlList;
+    protected List<Control> controlList;
 
     /** The table HTML &lt;td&gt; height attribute. */
     protected String height;
 
+    /** The table data provider. */
+    @SuppressWarnings("unchecked")
+    protected DataProvider dataProvider;
+
     /**
      * The table rows set 'hover' CSS class on mouseover events flag. By default
      * hoverRows is false.
@@ -430,6 +435,7 @@ public class Table extends AbstractContr
      * The list Table rows. Please note the rowList is cleared in table
      * {@link #onDestroy()} method at the end of each request.
      */
+    @SuppressWarnings("unchecked")
     protected List rowList;
 
     /**
@@ -611,7 +617,7 @@ public class Table extends AbstractContr
      *
      * @param columnNames the list of column names to remove from the table
      */
-    public void removeColumns(List columnNames) {
+    public void removeColumns(List<String> columnNames) {
         if (columnNames != null) {
             for (int i = 0; i < columnNames.size(); i++) {
                 removeColumn(columnNames.get(i).toString());
@@ -661,7 +667,7 @@ public class Table extends AbstractContr
      *
      * @return the list of table columns
      */
-    public List getColumnList() {
+    public List<Column> getColumnList() {
         return columnList;
     }
 
@@ -670,7 +676,7 @@ public class Table extends AbstractContr
      *
      * @return the Map of table Columns, keyed on column name
      */
-    public Map getColumns() {
+    public Map<String, Column> getColumns() {
         return columns;
     }
 
@@ -710,9 +716,9 @@ public class Table extends AbstractContr
      *
      * @return the list of table controls
      */
-    public List getControls() {
+    public List<Control> getControls() {
         if (controlList == null) {
-            controlList = new ArrayList();
+            controlList = new ArrayList<Control>();
         }
         return controlList;
     }
@@ -744,6 +750,26 @@ public class Table extends AbstractContr
     }
 
     /**
+     * Return the table row list DataProvider.
+     *
+     * @return the table row list DataProvider
+     */
+    @SuppressWarnings("unchecked")
+    public DataProvider getDataProvider() {
+        return dataProvider;
+    }
+
+    /**
+     * Set the table row list DataProvider.
+     *
+     * @param dataProvider the table row list DataProvider
+     */
+    @SuppressWarnings("unchecked")
+    public void setDataProvider(DataProvider dataProvider) {
+        this.dataProvider = dataProvider;
+    }
+
+    /**
      * Return the table HTML &lt;td&gt; height attribute.
      *
      * @return the table HTML &lt;td&gt; height attribute
@@ -800,6 +826,7 @@ public class Table extends AbstractContr
      *
      * @return the HTML head import statements for the control stylesheet
      */
+    @SuppressWarnings("deprecation")
     public String getHtmlImports() {
         HtmlStringBuffer buffer = new HtmlStringBuffer(512);
 
@@ -847,7 +874,7 @@ public class Table extends AbstractContr
      *
      * @return the list of HEAD elements for the Table
      */
-    public List getHeadElements() {
+    public List<Element> getHeadElements() {
         if (headElements == null) {
             headElements = super.getHeadElements();
             headElements.addAll(getControlLink().getHeadElements());
@@ -992,9 +1019,20 @@ public class Table extends AbstractContr
      *
      * @return the list of table rows
      */
+    @SuppressWarnings("unchecked")
     public List getRowList() {
-        if (rowList == null) {
-            rowList = new ArrayList(0);
+        if (rowList == null || rowList.isEmpty()) {
+
+            if (getDataProvider() != null) {
+                rowList = getDataProvider().getData();
+
+                if (rowList == null) {
+                    throw new IllegalStateException("DataProvider provided null data");
+                }
+
+            } else {
+                rowList = new ArrayList();
+            }
         }
 
         return rowList;
@@ -1009,6 +1047,7 @@ public class Table extends AbstractContr
      *
      * @param rowList the list of table rows to set
      */
+    @SuppressWarnings("unchecked")
     public void setRowList(List rowList) {
         this.rowList = rowList;
     }
@@ -1244,7 +1283,7 @@ public class Table extends AbstractContr
 
     /**
      * This method will clear the <tt>rowList</tt>, if the property
-     * <tt>clearRowListOnDestroy</tt> is true, set the sorted flag to false and
+     * <tt>nullifyRowListOnDestroy</tt> is true, set the sorted flag to false and
      * will invoke the onDestroy() method of any child controls.
      *
      * @see org.apache.click.Control#onDestroy()
@@ -1312,9 +1351,9 @@ public class Table extends AbstractContr
         // If table class not specified, look for message property
         // 'table-default-class' in the global click-page.properties messages bundle.
         if (!hasAttribute("class") && getPage() != null) {
-            Map messages = getPage().getMessages();
+            Map<String, String> messages = getPage().getMessages();
             if (messages.containsKey("table-default-class")) {
-                String htmlClass = (String) messages.get("table-default-class");
+                String htmlClass = messages.get("table-default-class");
                 setAttribute("class", htmlClass);
             }
         }
@@ -1360,9 +1399,9 @@ public class Table extends AbstractContr
     protected void renderHeaderRow(HtmlStringBuffer buffer) {
         buffer.append("<thead>\n<tr>\n");
 
-        final List tableColumns = getColumnList();
+        List<Column> tableColumns = getColumnList();
         for (int j = 0; j < tableColumns.size(); j++) {
-            Column column = (Column) tableColumns.get(j);
+            Column column = tableColumns.get(j);
             column.renderTableHeader(buffer, getContext());
             if (j < tableColumns.size() - 1) {
                 buffer.append("\n");
@@ -1377,6 +1416,7 @@ public class Table extends AbstractContr
      *
      * @param buffer the StringBuffer to render the table body rows in
      */
+    @SuppressWarnings("unchecked")
     protected void renderBodyRows(HtmlStringBuffer buffer) {
         buffer.append("<tbody>\n");
 
@@ -1401,7 +1441,7 @@ public class Table extends AbstractContr
         if (lastRow == 0) {
             renderBodyNoRows(buffer);
         } else {
-            final List tableRows = getRowList();
+            List tableRows = getRowList();
 
             Map rowAttributes = new HashMap(3);
 
@@ -1524,7 +1564,7 @@ public class Table extends AbstractContr
      * @param row the domain object currently being rendered
      * @param rowIndex the rows index
      */
-    protected void addRowAttributes(Map attributes, Object row, int rowIndex) {
+    protected void addRowAttributes(Map<String, String> attributes, Object row, int rowIndex) {
     }
 
     /**
@@ -1582,10 +1622,10 @@ public class Table extends AbstractContr
     protected void renderBodyRowColumns(HtmlStringBuffer buffer, int rowIndex) {
         Object row = getRowList().get(rowIndex);
 
-        final List tableColumns = getColumnList();
+        List<Column> tableColumns = getColumnList();
 
         for (int j = 0; j < tableColumns.size(); j++) {
-            Column column = (Column) tableColumns.get(j);
+            Column column = tableColumns.get(j);
             column.renderTableData(row, buffer, getContext(), rowIndex);
             if (j < tableColumns.size() - 1) {
                 buffer.append("\n");
@@ -1759,6 +1799,7 @@ public class Table extends AbstractContr
      * The default row list sorting method, which will sort the row list based
      * on the selected column if the row list is not already sorted.
      */
+    @SuppressWarnings("unchecked")
     protected void sortRowList() {
         if (!isSorted() && StringUtils.isNotBlank(getSortedColumn())) {
 

Modified: click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ClickUtils.java Wed Mar 10 12:06:32 2010
@@ -908,12 +908,12 @@ public class ClickUtils {
      * @param context the request context
      * @return a template model as a map
      */
-    public static Map createTemplateModel(final Page page, Context context) {
+    public static Map<String, Object> createTemplateModel(final Page page, Context context) {
 
         ConfigService configService = ClickUtils.getConfigService(context.getServletContext());
         LogService logger = configService.getLogService();
 
-        final Map model = new HashMap(page.getModel());
+        final Map<String, Object> model = new HashMap<String, Object>(page.getModel());
 
         final HttpServletRequest request = context.getRequest();
 

Added: click/trunk/click/framework/src/org/apache/click/util/DataProvider.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/DataProvider.java?rev=921323&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/DataProvider.java (added)
+++ click/trunk/click/framework/src/org/apache/click/util/DataProvider.java Wed Mar 10 12:06:32 2010
@@ -0,0 +1,35 @@
+/*
+ * 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.click.util;
+
+import java.util.List;
+
+/**
+ * An interface to provide data on demand to controls.
+ */
+public interface DataProvider<T> {
+
+    /**
+     * Return the list of data items supplied by the data provider.
+     *
+     * @return the list of data items supplied by the data provider.
+     */
+    public List<T> getData();
+
+}

Modified: click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java
URL: http://svn.apache.org/viewvc/click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java?rev=921323&r1=921322&r2=921323&view=diff
==============================================================================
--- click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java (original)
+++ click/trunk/click/mock/test/org/apache/click/servlet/MockTests.java Wed Mar 10 12:06:32 2010
@@ -33,8 +33,6 @@ import junit.framework.TestCase;
 
 /**
  * Sanity checks for Mock package.
- *
- * @author Bob Schellink
  */
 public class MockTests extends TestCase {
 



Mime
View raw message