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