01: /*
02: * $Id: IDataProvider.java 5261 2006-04-04 16:38:22 -0700 (Tue, 04 Apr 2006)
03: * ivaynberg $ $Revision: 460139 $ $Date: 2006-04-04 16:38:22 -0700 (Tue, 04 Apr
04: * 2006) $
05: *
06: * ==================================================================== Licensed
07: * under the Apache License, Version 2.0 (the "License"); you may not use this
08: * file except in compliance with the License. You may obtain a copy of the
09: * License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16: * License for the specific language governing permissions and limitations under
17: * the License.
18: */
19: package wicket.extensions.markup.html.repeater.data;
20:
21: import java.io.Serializable;
22: import java.util.Iterator;
23:
24: import wicket.model.IDetachable;
25: import wicket.model.IModel;
26:
27: /**
28: * Interface used to provide data to data views.
29: * <p>
30: * Note that if the IDataProvider implementation implements {@link IDetachable}
31: * interface, the {@link IDetachable#detach()} method will be called at the end
32: * of request.
33: *
34: * <p>
35: * Example:
36: *
37: * <pre>
38: * class UsersProvider implements IDataProvider() {
39: *
40: * Iterator iterator(int first, int count) {
41: * ((MyApplication)Application.get()).getUserDao().iterator(first, count);
42: * }
43: *
44: * int size() {
45: * ((MyApplication)Application.get()).getUserDao().getCount();
46: * }
47: *
48: * IModel model(Object object) {
49: * return new DetachableUserModel((User)object);
50: * }
51: * }
52: * </pre>
53: *
54: * @see DataViewBase
55: * @see DataView
56: * @see GridView
57: *
58: * @author Igor Vaynberg (ivaynberg)
59: *
60: * TODO 2.0: directly extend {@link IDetachable}
61: *
62: */
63: public interface IDataProvider extends Serializable {
64: /**
65: * Gets an iterator for the subset of total data
66: *
67: * @param first
68: * first row of data
69: * @param count
70: * minumum number of elements to retrieve
71: *
72: * @return iterator capable of iterating over {first, first+count} items
73: */
74: Iterator iterator(int first, int count);
75:
76: /**
77: * Gets total number of items in the collection represented by the
78: * DataProvider
79: *
80: * @return total item count
81: */
82: int size();
83:
84: /**
85: * Callback used by the consumer of this data provider to wrap objects
86: * retrieved from {@link #iterator(int, int)} with a model (usually a
87: * detachable one).
88: *
89: * @param object
90: * the object that needs to be wrapped
91: *
92: * @return the model representation of the object
93: */
94: IModel model(Object object);
95:
96: }
|