01: /*
02: * $Id: PagingNavigation.java,v 1.3 2005/02/17 06:13:40 jonathanlocke
03: * Exp $ $Revision: 457783 $ $Date: 2005-10-02 12:06:33 +0200 (Sun, 02 Oct 2005) $
04: *
05: * ==============================================================================
06: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
07: * use this file except in compliance with the License. You may obtain a copy of
08: * the 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.markup.html.list;
19:
20: import java.util.List;
21:
22: import wicket.Component;
23: import wicket.model.AbstractDetachableModel;
24: import wicket.model.IModel;
25:
26: /**
27: * Model for list items.
28: */
29: public class ListItemModel extends AbstractDetachableModel {
30: private static final long serialVersionUID = 1L;
31:
32: // It is easy and cheap to re-build it if necessary.
33: // Avoid synchronising it in a cluster
34: private transient Object object;
35:
36: /** The ListView's list model */
37: private final ListView listView;
38:
39: /* The list item's index */
40: private final int index;
41:
42: /**
43: * Construct
44: *
45: * @param listView
46: * The ListView
47: * @param index
48: * The index of this model
49: */
50: public ListItemModel(final ListView listView, final int index) {
51: this .listView = listView;
52: this .index = index;
53: attach();
54: }
55:
56: /**
57: * @see wicket.model.IModel#getNestedModel()
58: */
59: public IModel getNestedModel() {
60: return null;
61: }
62:
63: /**
64: * @see wicket.model.AbstractDetachableModel#onAttach()
65: */
66: protected void onAttach() {
67: // Re-attach the model object based on index and ListView model object
68: this .object = ((List) listView.getModelObject()).get(index);
69: }
70:
71: /**
72: * @see wicket.model.AbstractDetachableModel#onDetach()
73: */
74: protected void onDetach() {
75: this .object = null;
76: }
77:
78: /**
79: * @see wicket.model.AbstractDetachableModel#onGetObject(wicket.Component)
80: */
81: protected Object onGetObject(final Component component) {
82: return object;
83: }
84:
85: /**
86: * @see wicket.model.AbstractDetachableModel#onSetObject(wicket.Component,
87: * java.lang.Object)
88: */
89: protected void onSetObject(final Component component,
90: final Object object) {
91: this.object = object;
92: }
93: }
|