001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.markup.html.list; 018 019import org.apache.wicket.model.IModel; 020 021/** 022 * Model for list items. 023 * 024 * @see ListView 025 * @param <T> 026 * Model object type 027 */ 028public class ListItemModel<T> implements IModel<T> 029{ 030 private static final long serialVersionUID = 1L; 031 032 /** The ListView itself */ 033 private final ListView<T> listView; 034 035 /** The list item's index */ 036 private final int index; 037 038 /** 039 * Construct 040 * 041 * @param listView 042 * The ListView 043 * @param index 044 * The index of this model 045 */ 046 public ListItemModel(final ListView<T> listView, final int index) 047 { 048 this.listView = listView; 049 this.index = index; 050 } 051 052 @Override 053 public T getObject() 054 { 055 return listView.getModelObject().get(index); 056 } 057 058 @Override 059 public void setObject(T object) 060 { 061 listView.getModelObject().set(index, object); 062 } 063}