final Iterator<AuftragsPositionVO> it = orderPositions.iterator();
int orderNumber = -1;
StringBuffer buf = new StringBuffer();
Link<String> link = null;
BigDecimal totalPersonDays = BigDecimal.ZERO;
AuftragsPositionVO previousOrderPosition = null;
while (it.hasNext() == true) {
final AuftragsPositionVO orderPosition = it.next();
if (orderPosition.getAuftragNummer() != null && orderNumber != orderPosition.getAuftragNummer().intValue()) {
orderNumber = orderPosition.getAuftragNummer();
final WebMarkupContainer item = new WebMarkupContainer(positionsRepeater.newChildId());
positionsRepeater.add(item);
final Label separatorLabel = new Label("separator", ", ");
if (previousOrderPosition != null) {
// Previous order position finished.
addTitleAttribute(link, previousOrderPosition, totalPersonDays, buf);
buf = new StringBuffer();
totalPersonDays = BigDecimal.ZERO;
} else {
separatorLabel.setVisible(false); // Invisible for first entry.
}
previousOrderPosition = orderPosition;
item.add(separatorLabel);
link = new Link<String>("link") {
@Override
public void onClick()
{
final PageParameters params = new PageParameters();
params.add(AbstractEditPage.PARAMETER_KEY_ID, String.valueOf(orderPosition.getAuftragId()));
final AuftragEditPage page = new AuftragEditPage(params);
page.setReturnToPage((AbstractSecuredPage) getPage());
setResponsePage(page);
};
};
item.add(link);
link.add(new Label("label", String.valueOf(orderPosition.getAuftragNummer())));
} else {
buf.append("\n");
}
buf.append("#").append(orderPosition.getNumber()).append(" (");
if (orderPosition.getPersonDays() != null) {
buf.append(NumberFormatter.format(orderPosition.getPersonDays()));
totalPersonDays = totalPersonDays.add(orderPosition.getPersonDays());
} else {
buf.append("??");
}
final String title = StringUtils.defaultString(orderPosition.getTitel());
buf.append(" ").append(getString("projectmanagement.personDays.short")).append("): ").append(title);
if (orderPosition.getStatus() != null) {
if (StringUtils.isNotBlank(title) == true) {
buf.append(", ");
}
buf.append(getString(orderPosition.getStatus().getI18nKey()));
}
if (it.hasNext() == false && link != null) {
addTitleAttribute(link, orderPosition, totalPersonDays, buf);
}
}