int numberOfLogEntries = pers.getNumberOfLogMessageEntries(pipeId);
int numberOfPages = numberOfLogEntries > 0 ? (int) Math.ceil(((double) numberOfLogEntries)
/ ((double) LOG_ENTRIES_PER_PAGE)) : 1;
String pager = getPager(page, numberOfPages, labels);
TableTool tt = new TableTool();
tt.setZebra(true);
Table logTable = tt.getInnerTable().addElement(
tt.getHeaderRow(new String[] {
labels.getLabel("time"),
labels.getLabel("pipe"),
labels.getLabel("status"),
labels.getLabel("lastuser"),
labels.getLabel("messages")}));
//colorIndex needed for abort and error colors
int colorIndex = 0;
LogEntry logEntryOld = null;
TD messageCell = new TD();
boolean firstEntry = true;
for(Iterator i = entries.iterator(); i.hasNext();) {
LogMessageEntry entry = (LogMessageEntry) i.next();
LogEntry logEntry = entry.getLog();
/*
* Rows are added to table immediately after logEntry has changed.
* To detect the change, logEntryOld is used for comparison.
* When entering the for-loop for the first time logEntryOld is set to logEntry.
*/
if (firstEntry){
logEntryOld = logEntry;
firstEntry = false;
//check if entry is continued from previous page
if(entry.getIndex() != 1){
messageCell.addElement("...");
messageCell.addElement(new BR());
}
}
/*
* When logEntry gets new value, the previously collected log message entries are written
* to table and new TD() is created
*/
if(!logEntry.equals(logEntryOld)){
colorIndex = 1 - colorIndex;
writeRow(logEntryOld, dFormat, colorIndex, tt, logTable, messageCell, labels);
messageCell = new TD();
messageCell.setAlign("left"); // IE6 would center the contents by default
logEntryOld = logEntry;
}
messageCell.addElement(entry.getMessage());
messageCell.addElement(new BR());
//write last row (complete or incomplete entry)
if (!i.hasNext()){
//check if entry is continued on next page
if (entry.getIndex() < pers.getMaxMessageIndex(logEntry.getId()))
messageCell.addElement("...");
colorIndex = 1 - colorIndex;
writeRow(logEntryOld, dFormat, colorIndex, tt, logTable, messageCell, labels);
}
}
ElementContainer content = new ElementContainer()
.addElement(new BR())
.addElement(pager)
.addElement(tt.getOuterTable(logTable))
.addElement(pager)
.addElement(new HR().addElement(form));
return content.toString();
}