add(listContainer);
dataView = new DataView("items", dataProvider) {
@Override
protected void populateItem(Item item) {
final IModel itemModel = item.getModel();
// odd/even style
item.add(new SimpleAttributeModifier("class", item.getIndex() % 2 == 0 ? "even"
: "odd"));
// add row selector (visible only if selection is active)
WebMarkupContainer cnt = new WebMarkupContainer("selectItemContainer");
cnt.add(selectOneCheckbox(item));
cnt.setVisible(selectable);
item.add(cnt);
// create one component per viewable property
item.add(new ListView("itemProperties", dataProvider.getVisibleProperties()) {
@Override
protected void populateItem(ListItem item) {
Property<T> property = (Property<T>) item.getModelObject();
Component component = getComponentForProperty("component", itemModel,
property);
if(component == null) {
// show a plain label if the the subclass did not create any component
component = new Label("component", property.getModel(itemModel));
} else if (!"component".equals(component.getId())) {
// add some checks for the id, the error message
// that wicket returns in case of mismatch is not
// that helpful
throw new IllegalArgumentException("getComponentForProperty asked "
+ "to build a component " + "with id = 'component' "
+ "for property '" + property.getName() + "', but got '"
+ component.getId() + "' instead");
}
item.add(component);
}
});
}
};
listContainer.add(dataView);
// add select all checkbox
WebMarkupContainer cnt = new WebMarkupContainer("selectAllContainer");
cnt.add(selectAll = selectAllCheckbox());
cnt.setVisible(selectable);
listContainer.add(cnt);
// add the sorting links
listContainer.add(new ListView("sortableLinks", dataProvider.getVisibleProperties()) {
@Override
protected void populateItem(ListItem item) {
Property<T> property = (Property<T>) item.getModelObject();
// build a sortable link if the property is sortable, a label otherwise
IModel titleModel = getPropertyTitle(property);
if (property.getComparator() != null) {
Fragment f = new Fragment("header", "sortableHeader", item);
AjaxLink link = sortLink(dataProvider, item);
link.add(new Label("label", titleModel));
f.add(link);