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 * A very simple Item. Usually it is used as based class for more advanced Items. 023 * 024 * @author Juergen Donnerstag 025 */ 026public class LoopItem extends AbstractItem 027{ 028 private static final long serialVersionUID = 1L; 029 030 /** The index of the ListItem in the parent ListView */ 031 private int index; 032 033 /** 034 * Constructor 035 * 036 * @param index 037 * The index of the item 038 */ 039 public LoopItem(final int index) 040 { 041 super(index); 042 this.index = index; 043 } 044 045 /** 046 * A constructor which uses the index and the list provided to create a ListItem. This 047 * constructor is the default one. 048 * 049 * @param index 050 * The index of the item 051 * @param model 052 * The model object of the item 053 */ 054 public LoopItem(final int index, final IModel<?> model) 055 { 056 super(index, model); 057 this.index = index; 058 } 059 060 /** 061 * Constructor 062 * 063 * @param id 064 * component id 065 * @param index 066 * relative index of this item in the pageable view 067 * @param model 068 * model for this item 069 */ 070 public LoopItem(final String id, int index, final IModel<?> model) 071 { 072 super(id, model); 073 this.index = index; 074 } 075 076 /** 077 * Constructor 078 * 079 * @param id 080 * component id 081 * @param index 082 * relative index of this item in the pageable view 083 */ 084 public LoopItem(final String id, final int index) 085 { 086 super(id); 087 this.index = index; 088 } 089 090 /** 091 * Gets the index of the listItem in the parent listView. 092 * 093 * @return The index of this listItem in the parent listView 094 */ 095 public final int getIndex() 096 { 097 return index; 098 } 099 100 /** 101 * Sets the index of this item 102 * 103 * @param index 104 * new index 105 */ 106 public final void setIndex(int index) 107 { 108 if (this.index != index) 109 { 110 if (isVersioned()) 111 { 112 addStateChange(); 113 } 114 this.index = index; 115 } 116 } 117}