final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt");
ListView itemList = new ListView("itemList", itemListModel) {
protected void populateItem(ListItem listItem) {
// cast to AbstactItem - show history may be == true
final AbstractItem item = (AbstractItem) listItem.getModelObject();
if (selectedItemId == item.getId()) {
listItem.add(new SimpleAttributeModifier("class", "selected"));
} else if(listItem.getIndex() % 2 == 1) {
listItem.add(sam);
}
final boolean showHistory = itemSearch.isShowHistory();
ListView fieldValues = new ListView("columns", columnHeadings) {
protected void populateItem(ListItem listItem) {
ColumnHeading ch = (ColumnHeading) listItem.getModelObject();
IModel value = null;
if(ch.isField()) {
value = new Model(item.getCustomValue(ch.getField().getName()));
} else {
switch(ch.getName()) {
case ID:
String refId = item.getRefId();
Fragment refIdFrag = new Fragment("column", "refId", ItemListPanel.this);
refIdFrag.setRenderBodyOnly(true);
listItem.add(refIdFrag);
Link refIdLink = new BookmarkablePageLink("refId", ItemViewPage.class, new PageParameters("0=" + refId));
refIdFrag.add(refIdLink);
refIdLink.add(new Label("refId", refId));
if (showHistory) {
int index = ((History) item).getIndex();
if (index > 0) {
refIdFrag.add(new Label("index", " (" + index + ")"));
} else {
refIdFrag.add(new WebMarkupContainer("index").setVisible(false));
}
} else {
refIdFrag.add(new WebMarkupContainer("index").setVisible(false));
}
// the first column ID is a special case, where we add a fragment.
// since we have already added a fragment return, instead of "break"
// so avoid going to the new Label("column", value) after the switch case
return;
case SUMMARY:
value = new PropertyModel(item, "summary");
break;
case DETAIL:
if(showHistory) {
Fragment detailFrag = new Fragment("column", "detail", ItemListPanel.this);
final History history = (History) item;
detailFrag.add(new AttachmentLinkPanel("attachment", history.getAttachment()));
if (history.getIndex() > 0) {
detailFrag.add(new Label("detail", new PropertyModel(history, "comment")));
} else {
detailFrag.add(new Label("detail", new PropertyModel(history, "detail")));
}
listItem.add(detailFrag);
return;
} else {
value = new PropertyModel(item, "detail");
}
break;
case LOGGED_BY:
value = new PropertyModel(item, "loggedBy.name");
break;
case STATUS:
value = new PropertyModel(item, "statusValue");
break;
case ASSIGNED_TO:
value = new PropertyModel(item, "assignedTo.name");
break;
case TIME_STAMP:
value = new Model(DateUtils.formatTimeStamp(item.getTimeStamp()));
break;
case SPACE:
if(showHistory) {
value = new PropertyModel(item, "parent.space.name");
} else {