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.extensions.markup.html.repeater.util.SortParam;
22: import org.apache.wicket.extensions.markup.html.repeater.util.SortableDataProvider;
23: import org.apache.wicket.model.IModel;
24:
25: /**
26: * implementation of IDataProvider for contacts that keeps track of sort
27: * information
28: *
29: * @author igor
30: *
31: */
32: public class SortableContactDataProvider extends SortableDataProvider {
33: /**
34: * constructor
35: */
36: public SortableContactDataProvider() {
37: // set default sort
38: setSort("firstName", true);
39: }
40:
41: protected ContactsDatabase getContactsDB() {
42: return DatabaseLocator.getDatabase();
43: }
44:
45: /**
46: * @see org.apache.wicket.markup.repeater.data.IDataProvider#iterator(int, int)
47: */
48: public Iterator iterator(int first, int count) {
49: SortParam sp = getSort();
50: return getContactsDB().find(first, count, sp.getProperty(),
51: sp.isAscending()).iterator();
52: }
53:
54: /**
55: * @see org.apache.wicket.markup.repeater.data.IDataProvider#size()
56: */
57: public int size() {
58: return getContactsDB().getCount();
59: }
60:
61: /**
62: * @see org.apache.wicket.markup.repeater.data.IDataProvider#model(java.lang.Object)
63: */
64: public IModel model(Object object) {
65: return new DetachableContactModel((Contact) object);
66: }
67:
68: }
|