Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataView.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataView.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataView.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataView.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.data; + +import wicket.MarkupContainer; +import wicket.markup.html.navigation.paging.IPageable; + + +/** + * DataView is a basic implementation of AbstractDataView. + * + * Data views aim to make it very simple to populate your repeating view from a + * database by utilizing [EMAIL PROTECTED] IDataProvider} to act as an interface between + * the database and the dataview. + * + * + * + * <p> + * Example: + * + * <pre> + * <tbody> + * <tr wicket:id="rows"> + * <td><span wicket:id="id">Test ID</span></td> + * ... + * </pre> + * + * <p> + * Though this example is about a HTML table, DataView is not at all limited to + * HTML tables. Any kind of list can be rendered using DataView. + * <p> + * And the related Java code: + * + * <pre> + * add(new DataView("rows", dataProvider) + * { + * public void populateItem(final Item item) + * { + * final UserDetails user = (UserDetails)item.getModelObject(); + * item.add(new Label("id", user.getId())); + * } + * }); + * </pre> + * + * @see IDataProvider + * @see IPageable + * + * @author Igor Vaynberg (ivaynberg) + * + * @param <T> + * Type of model object this component holds + */ +public abstract class DataView<T> extends DataViewBase<T> +{ + + /** + * @param parent + * The parent of this component The parent of this component. + * @param id + * component id + * @param dataProvider + * data provider + */ + public DataView(MarkupContainer<?> parent, final String id, IDataProvider<T> dataProvider) + { + super(parent, id, dataProvider); + } + + /** + * @param parent + * The parent of this component The parent of this component. + * @param id + * component id + * @param dataProvider + * data provider + * @param itemsPerPage + * items per page + */ + public DataView(MarkupContainer<?> parent, final String id, IDataProvider<T> dataProvider, + int itemsPerPage) + { + super(parent, id, dataProvider); + setItemsPerPage(itemsPerPage); + } + + /** + * Sets the number of items to be displayed per page + * + * @param items + * number of items to display per page + */ + public void setItemsPerPage(int items) + { + internalSetRowsPerPage(items); + } + + /** + * @return number of items displayed per page + */ + public int getItemsPerPage() + { + return internalGetRowsPerPage(); + } + + /** + * @return data provider + */ + public IDataProvider<T> getDataProvider() + { + return internalGetDataProvider(); + } + +}
Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataViewBase.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataViewBase.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataViewBase.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/DataViewBase.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.data; + +import java.util.Iterator; + +import wicket.MarkupContainer; +import wicket.markup.html.navigation.paging.IPageable; +import wicket.markup.repeater.AbstractPageableView; +import wicket.markup.repeater.RefreshingView; +import wicket.model.IModel; + +/** + * Base class for data views. + * + * Data views aim to make it very simple to populate your repeating view from a + * database by utilizing [EMAIL PROTECTED] IDataProvider} to act as an interface between + * the database and the dataview. + * + * @see IDataProvider + * @see DataView + * @see IPageable + * @see RefreshingView + * + * @author Igor Vaynberg (ivaynberg) + * + * @param <T> + * Type of model object this component holds + */ +public abstract class DataViewBase<T> extends AbstractPageableView<T> +{ + private IDataProvider<T> dataProvider; + + /** + * @param parent + * The parent of this component The parent of this component. + * @param id + * component id + * @param dataProvider + * data provider + */ + public DataViewBase(MarkupContainer<?> parent, final String id, IDataProvider<T> dataProvider) + { + super(parent, id); + if (dataProvider == null) + { + throw new IllegalArgumentException("argument [dataProvider] cannot be null"); + } + this.dataProvider = dataProvider; + } + + /** + * @return data provider associated with this view + */ + protected final IDataProvider<T> internalGetDataProvider() + { + return dataProvider; + } + + + @Override + protected final Iterator<IModel<T>> getItemModels(int offset, int count) + { + return new ModelIterator<T>(internalGetDataProvider(), offset, count); + } + + /** + * Helper class that converts input from IDataProvider to an iterator over + * view items. + * + * @author Igor Vaynberg (ivaynberg) + * + * @param <T> + * + */ + private static final class ModelIterator<T> implements Iterator<IModel<T>> + { + private Iterator<T> items; + private IDataProvider<T> dataProvider; + private int max; + private int index; + + /** + * Constructor + * + * @param dataProvider + * data provider + * @param offset + * index of first item + * @param count + * max number of items to return + */ + public ModelIterator(IDataProvider<T> dataProvider, int offset, int count) + { + this.items = dataProvider.iterator(offset, count); + this.dataProvider = dataProvider; + this.max = count; + } + + /** + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return items.hasNext() && (index < max); + } + + /** + * @see java.util.Iterator#next() + */ + public IModel<T> next() + { + index++; + return dataProvider.model(items.next()); + } + } + + @Override + protected final int internalGetItemCount() + { + return internalGetDataProvider().size(); + } + + @Override + protected void onDetach() + { + super.onDetach(); + dataProvider.detach(); + } +} Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/GridView.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/GridView.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/GridView.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/GridView.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,369 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.data; + +import java.util.Iterator; + +import wicket.Component; +import wicket.MarkupContainer; +import wicket.markup.repeater.Item; +import wicket.markup.repeater.RepeatingView; +import wicket.version.undo.Change; + +/** + * A pageable DataView which breaks the data in the IDataProvider into a number + * of data-rows, depending on the column size. A typical use case is to show + * items in a table with ie 3 columns where the table is filled left to right + * top-down so that for each third item a new row is created. + * <p> + * Example + * + * <pre> + * <tbody> + * <tr wicket:id="rows" class"even"> + * <td wicket:id="cols"> + * <span wicket:id="id">Test ID</span> + * </td> + * </tr> + * </tbody> + * </pre> + * + * and in java: + * + * <pre> + * add(new GridView("rows", dataProvider).setColumns(3)); + * </pre> + * + * @author Igor Vaynberg + * @author Christian Essl + * + * @param <T> + * Type of model object this component holds + */ +public abstract class GridView<T> extends DataViewBase<T> +{ + + private int columns = 1; + private int rows = Integer.MAX_VALUE; + + + /** + * @param parent + * The parent of this component The parent of this component. + * @param id + * component id + * @param dataProvider + * data provider + */ + public GridView(MarkupContainer<?> parent, final String id, IDataProvider<T> dataProvider) + { + super(parent, id, dataProvider); + } + + + /** + * @return number of columns + */ + public int getColumns() + { + return columns; + } + + /** + * Sets number of columns + * + * @param cols + * number of colums + * @return this for chaining + */ + public GridView<T> setColumns(int cols) + { + if (cols < 1) + { + throw new IllegalArgumentException(); + } + + if (columns != cols) + { + if (isVersioned()) + { + addStateChange(new Change() + { + private static final long serialVersionUID = 1L; + + final int old = columns; + + @Override + public void undo() + { + columns = old; + } + + @Override + public String toString() + { + return "GridViewColumnsChange[component: " + getPath() + + ", removed columns: " + old + "]"; + } + }); + } + columns = cols; + } + updateItemsPerPage(); + return this; + } + + /** + * @return number of rows per page + */ + public int getRows() + { + return rows; + } + + /** + * Sets number of rows per page + * + * @param rows + * number of rows + * @return this for chaining + */ + public GridView<T> setRows(int rows) + { + if (rows < 1) + { + throw new IllegalArgumentException(); + } + + if (this.rows != rows) + { + if (isVersioned()) + { + addStateChange(new Change() + { + private static final long serialVersionUID = 1L; + + final int old = GridView.this.rows; + + @Override + public void undo() + { + GridView.this.rows = old; + } + + @Override + public String toString() + { + return "GridViewRowsChange[component: " + getPath() + ", removed rows: " + + old + "]"; + } + }); + } + this.rows = rows; + } + + // TODO Post 1.2: Performance: Can this be moved into the this.rows != + // rows if + // block for optimization? + updateItemsPerPage(); + return this; + } + + private void updateItemsPerPage() + { + int items = Integer.MAX_VALUE; + + long result = (long)rows * (long)columns; + + // overflow check + int desiredHiBits = -((int)(result >>> 31) & 1); + int actualHiBits = (int)(result >>> 32); + + if (desiredHiBits == actualHiBits) + { + items = (int)result; + } + + internalSetRowsPerPage(items); + + } + + + @Override + protected void addItems(Iterator<Item<T>> items) + { + if (items.hasNext()) + { + final int cols = getColumns(); + + int row = 0; + + do + { + // Build a row + Item<T> rowItem = newRowItem(newChildId(), row); + new RepeatingView<T>(rowItem, "cols"); + + // Populate the row + for (int index = 0; index < cols; index++) + { + final Item<T> cellItem; + if (items.hasNext()) + { + cellItem = items.next(); + } + else + { + cellItem = newEmptyItem(newChildId(), index); + populateEmptyItem(cellItem); + } + } + + // increase row + row++; + + } + while (items.hasNext()); + } + + } + + /** + * @return data provider + */ + public IDataProvider<T> getDataProvider() + { + return internalGetDataProvider(); + } + + /** + * @see wicket.markup.repeater.AbstractPageableView#getItems() + */ + @Override + public Iterator<Item<T>> getItems() + { + return new ItemsIterator<T>(iterator()); + } + + /** + * Add component to an Item for which there is no model anymore and is shown + * in a cell + * + * @param item + * Item object + */ + abstract protected void populateEmptyItem(Item<T> item); + + /** + * Create a Item which represents an empty cell (there is no model for it in + * the DataProvider) + * + * @param id + * @param index + * @return created item + */ + protected Item<T> newEmptyItem(final String id, int index) + { + return new Item<T>(this, id, index, null); + } + + /** + * Create a new Item which will hold a row. + * + * @param id + * @param index + * @return created Item + */ + protected Item<T> newRowItem(final String id, int index) + { + return new Item<T>(this, id, index, null); + } + + /** + * Iterator that iterats over all items in the cells + * + * @author igor + * + * @param <T> + * Type of model object this component holds + */ + private static class ItemsIterator<T> implements Iterator<Item<T>> + { + private Iterator<Component> rows; + private Iterator<Item<T>> cells; + + private Item<T> next; + + /** + * @param rows + * iterator over child row views + */ + public ItemsIterator(Iterator<Component> rows) + { + this.rows = rows; + findNext(); + } + + /** + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException(); + } + + /** + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return next != null; + } + + /** + * @see java.util.Iterator#next() + */ + public Item<T> next() + { + Item<T> item = next; + findNext(); + return item; + } + + private void findNext() + { + next = null; + + if (cells != null && cells.hasNext()) + { + next = cells.next(); + } + + while (rows.hasNext()) + { + MarkupContainer<?> row = (MarkupContainer)rows.next(); + cells = ((MarkupContainer)row.iterator().next()).iterator(); + if (cells.hasNext()) + { + next = cells.next(); + break; + } + } + } + + } +} \ No newline at end of file Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/IDataProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/IDataProvider.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/IDataProvider.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/IDataProvider.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.data; + +import java.util.Iterator; + +import wicket.model.IDetachable; +import wicket.model.IModel; + +/** + * Interface used to provide data to data views. + * + * Example: + * + * <pre> + * class UsersProvider implements IDataProvider<User>() { + * + * Iterator<User> iterator(int first, int count) { + * MyApplication.get().getUserDao().iterator(first, count); + * } + * + * int size() { + * MyApplication.get().getUserDao().getCount(); + * } + * + * IModel<User> model(User user) { + * return new DetachableUserModel<User>(user); + * } + * } + * </pre> + * + * You can use the [EMAIL PROTECTED] IDetachable#detach()} method for cleaning up your + * IDataProvider instance. So that you can do one query that returns both + * the size and the values if your dataset is small enough the be able to + * do that. + * + * @see IDetachable + * @see DataViewBase + * @see DataView + * @see GridView + * + * @author Igor Vaynberg (ivaynberg) + * + * @param <T> The IModel type + */ +public interface IDataProvider<T> extends IDetachable +{ + /** + * Gets an iterator for the subset of total data + * + * @param first + * first row of data + * @param count + * minumum number of elements to retrieve + * + * @return iterator capable of iterating over {first, first+count} items + */ + Iterator<T> iterator(int first, int count); + + /** + * Gets total number of items in the collection represented by the + * DataProvider + * + * @return total item count + */ + int size(); + + /** + * Callback used by the consumer of this data provider to wrap objects + * retrieved from [EMAIL PROTECTED] #iterator(int, int)} with a model (usually a + * detachable one). + * + * @param object + * the object that needs to be wrapped + * + * @return the model representation of the object + */ + IModel<T> model(T object); + +} Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/ListDataProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/ListDataProvider.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/ListDataProvider.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/data/ListDataProvider.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.data; + +import java.util.Iterator; +import java.util.List; + +import wicket.model.IModel; +import wicket.model.Model; + +/** + * Allows the use of lists with dataview. The only requirement is that either + * list items must be serializable or model(Object) needs to be overridden to + * provide the proper model implementation. + * + * @author Igor Vaynberg ( ivaynberg ) + * + * @param <T> The IModel type + */ +public class ListDataProvider<T> implements IDataProvider<T> +{ + private static final long serialVersionUID = 1L; + + /** reference to the list used as dataprovider for the dataview */ + private List<T> list; + + /** + * + * @param list + * the list used as dataprovider for the dataview + */ + public ListDataProvider(List<T> list) + { + if (list == null) + { + throw new IllegalArgumentException("argument [list] cannot be null"); + } + + this.list = list; + } + + /** + * @see IDataProvider#iterator(int, int) + */ + public Iterator<T> iterator(final int first, final int count) + { + return list.listIterator(first); + } + + /** + * @see IDataProvider#size() + */ + public int size() + { + return list.size(); + } + + /** + * @see IDataProvider#model(Object) + */ + public IModel<T> model(T object) + { + return new Model<T>(object); + } + + public void detach() + { + } + +} Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ArrayIteratorAdapter.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ArrayIteratorAdapter.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ArrayIteratorAdapter.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ArrayIteratorAdapter.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.util; + +import java.util.Iterator; + +import wicket.model.IModel; + +/** + * Iterator over an array. Implementation must provide + * [EMAIL PROTECTED] ArrayIteratorAdapter#model(Object, int) } method to wrap each item in a + * model before it is returned through [EMAIL PROTECTED] ArrayIteratorAdapter#next() } + * method. + * + * @author Igor Vaynberg (ivaynberg) + * + */ +public abstract class ArrayIteratorAdapter implements Iterator +{ + private Object[] array; + private int pos = 0; + + /** + * Constructor + * + * @param array + */ + public ArrayIteratorAdapter(Object[] array) + { + this.array = array; + } + + /** + * @see java.util.Iterator#remove() + */ + public void remove() + { + throw new UnsupportedOperationException("remove() is not allowed"); + } + + /** + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return pos < array.length; + } + + /** + * @see java.util.Iterator#next() + */ + public Object next() + { + IModel model = model(array[pos], pos); + pos++; + return model; + } + + /** + * Resets the iterator position back to the beginning of the array + */ + public void reset() + { + pos = 0; + } + + /** + * This method is used to wrap the provided object with an implementation of + * IModel. The provided object is guaranteed to be returned from the + * delegate iterator. + * + * @param object + * object to be wrapped + * @param index + * array index of the object + * @return IModel wrapper for the object + */ + abstract protected IModel model(Object object, int index); + + +} Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/EmptyDataProvider.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/EmptyDataProvider.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/EmptyDataProvider.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/EmptyDataProvider.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package wicket.markup.repeater.util; + +import java.util.Collections; +import java.util.Iterator; + +import wicket.markup.repeater.data.IDataProvider; +import wicket.model.IModel; + +/** + * A convienience class to represent an empty data provider. + * + * @author Phil Kulak + */ +public class EmptyDataProvider implements IDataProvider +{ + private static final long serialVersionUID = 1L; + + private static EmptyDataProvider INSTANCE = new EmptyDataProvider(); + + /** + * @return the singleton instance of this class + */ + public static EmptyDataProvider getInstance() + { + return INSTANCE; + } + + /** + * @see wicket.markup.repeater.data.IDataProvider#iterator(int, + * int) + */ + public Iterator iterator(int first, int count) + { + return Collections.EMPTY_LIST.iterator(); + } + + /** + * @see wicket.markup.repeater.data.IDataProvider#size() + */ + public int size() + { + return 0; + } + + /** + * @see wicket.markup.repeater.data.IDataProvider#model(java.lang.Object) + */ + public IModel model(Object object) + { + return null; + } + + /** + * @see wicket.model.IDetachable#detach() + */ + public void detach() + { + } +} Added: incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ModelIteratorAdapter.java URL: http://svn.apache.org/viewvc/incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ModelIteratorAdapter.java?view=auto&rev=486920 ============================================================================== --- incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ModelIteratorAdapter.java (added) +++ incubator/wicket/trunk/wicket/src/main/java/wicket/markup/repeater/util/ModelIteratorAdapter.java Wed Dec 13 17:13:55 2006 @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package wicket.markup.repeater.util; + +import java.util.Iterator; + +import wicket.markup.repeater.RefreshingView; +import wicket.model.IModel; + +/** + * Iterator adapter that wraps adaptee's elements with a model. Convinient when + * implementing [EMAIL PROTECTED] RefreshingView}. + * + * @param <T> + * + * @author Igor Vaynberg (ivaynberg) + * + * + */ +public abstract class ModelIteratorAdapter<T> implements Iterator<IModel<T>> +{ + private Iterator<T> delegate; + + /** + * Constructor + * + * @param delegate + * iterator that will be wrapped + */ + public ModelIteratorAdapter(Iterator<T> delegate) + { + this.delegate = delegate; + } + + /** + * @see java.util.Iterator#hasNext() + */ + public boolean hasNext() + { + return delegate.hasNext(); + } + + /** + * @see java.util.Iterator#next() + */ + public IModel<T> next() + { + return model(delegate.next()); + } + + /** + * @see java.util.Iterator#remove() + */ + public void remove() + { + delegate.remove(); + } + + /** + * This method is used to wrap the provided object with an implementation of + * IModel. The provided object is guaranteed to be returned from the + * delegate iterator. + * + * @param object + * object to be wrapped + * @return IModel wrapper for the object + */ + abstract protected IModel<T> model(T object); +}
