⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 listview.java

📁 Wicket一个开发Java Web应用程序框架。它使得开发web应用程序变得容易而轻松。 Wicket利用一个POJO data beans组件使得它可以与任何持久层技术相结合。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
						{							Collections.swap(getList(), oldIndex - 1, oldIndex);						}					});					// Swap items and invalidate listView					Collections.swap(getList(), index, index - 1);					ListView.this.removeAll();				}			}			/**			 * @see org.apache.wicket.Component#onBeforeRender()			 */			protected void onBeforeRender()			{				super.onBeforeRender();				setAutoEnable(false);				if (getList().indexOf(item.getModelObject()) == 0)				{					setEnabled(false);				}			}		};	}	/**	 * Returns a link that will remove this ListItem from the ListView that holds it.	 * 	 * @param id	 *            Name of remove link component to create	 * @param item	 * @return The link component	 */	public final Link removeLink(final String id, final ListItem item)	{		return new Link(id)		{			private static final long serialVersionUID = 1L;			/**			 * @see org.apache.wicket.markup.html.link.Link#onClick()			 */			public void onClick()			{				addStateChange(new Change()				{					private static final long serialVersionUID = 1L;					final int oldIndex = getList().indexOf(item.getModelObject());					final Object removedObject = item.getModelObject();					public void undo()					{						getList().add(oldIndex, removedObject);					}				});				item.modelChanging();				// Remove item and invalidate listView				getList().remove(item.getModelObject());				ListView.this.modelChanged();				ListView.this.removeAll();			}		};	}	/**	 * Sets the model as the provided list and removes all children, so that the next render will be	 * using the contents of the model.	 * 	 * @param list	 *            The list for the new model. The list must implement {@link Serializable}.	 * @return This for chaining	 */	public Component setList(List list)	{		return setModel(new Model((Serializable)list));	}	/**	 * Sets the model and removes all current children, so that the next render will be using the	 * contents of the model.	 * 	 * @param model	 *            The new model	 * @return This for chaining	 * 	 * @see org.apache.wicket.MarkupContainer#setModel(org.apache.wicket.model.IModel)	 */	public Component setModel(IModel model)	{		return super.setModel(model);	}	/**	 * If true re-rendering the list view is more efficient if the windows doesn't get changed at	 * all or if it gets scrolled (compared to paging). But if you modify the listView model object,	 * than you must manually call listView.removeAll() in order to rebuild the ListItems. If you	 * nest a ListView in a Form, ALLWAYS set this property to true, as otherwise validation will	 * not work properly.	 * 	 * @param reuseItems	 *            Whether to reuse the child items.	 * @return this	 */	public ListView setReuseItems(boolean reuseItems)	{		this.reuseItems = reuseItems;		return this;	}	/**	 * Set the index of the first item to render	 * 	 * @param startIndex	 *            First index of model object's list to display	 * @return This	 */	public ListView setStartIndex(final int startIndex)	{		firstIndex = startIndex;		if (firstIndex < 0)		{			firstIndex = 0;		}		else if (firstIndex > getList().size())		{			firstIndex = 0;		}		return this;	}	/**	 * Define the maximum number of items to render. Default: render all.	 * 	 * @param size	 *            Number of items to display	 * @return This	 */	public ListView setViewSize(final int size)	{		viewSize = size;		if (viewSize < 0)		{			viewSize = Integer.MAX_VALUE;		}		return this;	}	/**	 * Subclasses may provide their own ListItemModel with extended functionality. The default	 * ListItemModel works fine with mostly static lists where index remains valid. In cases where	 * the underlying list changes a lot (many users using the application), it may not longer be	 * appropriate. In that case your own ListItemModel implementation should use an id (e.g. the	 * database' record id) to identify and load the list item model object.	 * 	 * @param listViewModel	 *            The ListView's model	 * @param index	 *            The list item index	 * @return The ListItemModel created	 */	protected IModel getListItemModel(final IModel listViewModel, final int index)	{		return new ListItemModel(this, index);	}	/**	 * Create a new ListItem for list item at index.	 * 	 * @param index	 * @return ListItem	 */	protected ListItem newItem(final int index)	{		return new ListItem(index, getListItemModel(getModel(), index));	}	/**	 * @see org.apache.wicket.markup.repeater.AbstractRepeater#onPopulate()	 */	protected final void onPopulate()	{		// Get number of items to be displayed		final int size = getViewSize();		if (size > 0)		{			if (getReuseItems())			{				// Remove all ListItems no longer required				final int maxIndex = firstIndex + size;				for (final Iterator iterator = iterator(); iterator.hasNext();)				{					// Get next child component					final ListItem child = (ListItem)iterator.next();					if (child != null)					{						final int index = child.getIndex();						if (index < firstIndex || index >= maxIndex)						{							iterator.remove();						}					}				}			}			else			{				// Automatically rebuild all ListItems before rendering the				// list view				removeAll();			}			// Loop through the markup in this container for each item			for (int i = 0; i < size; i++)			{				// Get index				final int index = firstIndex + i;				// If this component does not already exist, populate it				ListItem item = (ListItem)get(Integer.toString(index));				if (item == null)				{					// Create item for index					item = newItem(index);					// Add list item					add(item);					// Populate the list item					onBeginPopulateItem(item);					populateItem(item);				}			}		}		else		{			removeAll();		}	}	/**	 * Comes handy for ready made ListView based components which must implement populateItem() but	 * you don't want to lose compile time error checking reminding the user to implement abstract	 * populateItem().	 * 	 * @param item	 */	protected void onBeginPopulateItem(final ListItem item)	{	}	/**	 * Populate a given item.	 * <p>	 * <b>be careful</b> to add any components to the list item. So, don't do:	 * 	 * <pre>	 * add(new Label(&quot;foo&quot;, &quot;bar&quot;));	 * </pre>	 * 	 * but:	 * 	 * <pre>	 * item.add(new Label(&quot;foo&quot;, &quot;bar&quot;));	 * </pre>	 * 	 * </p>	 * 	 * @param item	 *            The item to populate	 */	protected abstract void populateItem(final ListItem item);	/**	 * @see org.apache.wicket.markup.repeater.AbstractRepeater#renderChild(org.apache.wicket.Component)	 */	protected final void renderChild(Component child)	{		renderItem((ListItem)child);	}	/**	 * Render a single item.	 * 	 * @param item	 *            The item to be rendered	 */	protected void renderItem(final ListItem item)	{		item.render(getMarkupStream());	}	/**	 * @see org.apache.wicket.markup.repeater.AbstractRepeater#renderIterator()	 */	protected Iterator renderIterator()	{		final int size = size();		return new ReadOnlyIterator()		{			private int index = 0;			public boolean hasNext()			{				return index < size;			}			public Object next()			{				final String id = Integer.toString(firstIndex + index);				index++;				Component c = get(id);				return c;			}		};	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -