01: /*
02: * $Id: ContactDataProvider.java 460265 2006-04-16 13:36:52Z jdonnerstag $
03: * $Revision: 460265 $ $Date: 2006-04-16 15:36:52 +0200 (Sun, 16 Apr 2006) $
04: *
05: * ==================================================================== Licensed
06: * under the Apache License, Version 2.0 (the "License"); you may not use this
07: * file except in compliance with the License. You may obtain a copy of the
08: * License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples.repeater;
19:
20: import java.util.Iterator;
21:
22: import wicket.extensions.markup.html.repeater.data.IDataProvider;
23: import wicket.model.IModel;
24:
25: /**
26: * Implementation of IDataProvider that retrieves contacts from the contact
27: * database.
28: *
29: * @see wicket.extensions.markup.html.repeater.data.IDataProvider
30: * @see wicket.extensions.markup.html.repeater.data.DataViewBase
31: *
32: * @author igor
33: *
34: */
35: public class ContactDataProvider implements IDataProvider {
36: protected ContactsDatabase getContactsDB() {
37: return DatabaseLocator.getDatabase();
38: }
39:
40: /**
41: * retrieves contacts from database starting with index <code>first</code>
42: * and ending with <code>first+count</code>
43: *
44: * @see wicket.extensions.markup.html.repeater.data.IDataProvider#iterator(int,
45: * int)
46: */
47: public Iterator iterator(int first, int count) {
48: return getContactsDB().find(first, count, "firstName", true)
49: .iterator();
50: }
51:
52: /**
53: * returns total number of contacts in the database
54: *
55: * @see wicket.extensions.markup.html.repeater.data.IDataProvider#size()
56: */
57: public int size() {
58: return getContactsDB().getCount();
59: }
60:
61: /**
62: * wraps retrieved contact pojo with a wicket model
63: *
64: * @see wicket.extensions.markup.html.repeater.data.IDataProvider#model(java.lang.Object)
65: */
66: public IModel model(Object object) {
67: return new DetachableContactModel((Contact) object);
68: }
69:
70: }
|