📄 tablewritertemplate.java
字号:
{ currentRow = rowIterator.next(); } else { previousRow = currentRow; currentRow = nextRow; } if (previousRow != null) { previousRowValues.putAll(currentRowValues); } if (!nextRowValues.isEmpty()) { currentRowValues.putAll(nextRowValues); } // handle the first pass else { ColumnIterator columnIterator = currentRow.getColumnIterator(model.getHeaderCellList()); // iterator on columns if (log.isDebugEnabled()) { log.debug(" creating ColumnIterator on " + model.getHeaderCellList()); } while (columnIterator.hasNext()) { Column column = columnIterator.nextColumn(); // Get the value to be displayed for the column column.initialize(); CellStruct struct = new CellStruct(column, column.getChoppedAndLinkedValue()); currentRowValues.put(new Integer(column.getHeaderCell().getColumnNumber()), struct); } } nextRowValues.clear(); // Populate the next row values nextRow = rowIterator.hasNext() ? rowIterator.next() : null; if (nextRow != null) { ColumnIterator columnIterator = nextRow.getColumnIterator(model.getHeaderCellList()); // iterator on columns if (log.isDebugEnabled()) { log.debug(" creating ColumnIterator on " + model.getHeaderCellList()); } while (columnIterator.hasNext()) { Column column = columnIterator.nextColumn(); column.initialize(); // Get the value to be displayed for the column CellStruct struct = new CellStruct(column, column.getChoppedAndLinkedValue()); nextRowValues.put(new Integer(column.getHeaderCell().getColumnNumber()), struct); } } // now we are going to create the current row; reset the decorator to the current row if (tableDecorator != null) { tableDecorator.initRow(currentRow.getObject(), currentRow.getRowNumber(), currentRow.getRowNumber() + rowIterator.getPageOffset()); } Iterator headerCellsIter = model.getHeaderCellList().iterator(); ArrayList structsForRow = new ArrayList(model.getHeaderCellList().size()); lowestEndedGroup = NO_RESET_GROUP; lowestStartedGroup = NO_RESET_GROUP; while (headerCellsIter.hasNext()) { HeaderCell header = (HeaderCell) headerCellsIter.next(); // Get the value to be displayed for the column CellStruct struct = (CellStruct) currentRowValues.get(new Integer(header.getColumnNumber())); struct.decoratedValue = struct.bodyValue; // Check and see if there is a grouping transition. If there is, then notify the decorator if (header.getGroup() != -1) { CellStruct prior = (CellStruct) previousRowValues.get(new Integer(header.getColumnNumber())); CellStruct next = (CellStruct) nextRowValues.get(new Integer(header.getColumnNumber())); // Why npe? String priorBodyValue = prior != null ? prior.bodyValue : null; String nextBodyValue = next != null ? next.bodyValue : null; short groupingValue = groupColumns(struct.bodyValue, priorBodyValue, nextBodyValue, header.getGroup()); if (tableDecorator != null) { switch (groupingValue) { case GROUP_START : tableDecorator.startOfGroup(struct.bodyValue, header.getGroup()); break; case GROUP_END : tableDecorator.endOfGroup(struct.bodyValue, header.getGroup()); break; case GROUP_START_AND_END : tableDecorator.startOfGroup(struct.bodyValue, header.getGroup()); tableDecorator.endOfGroup(struct.bodyValue, header.getGroup()); break; default : break; } } if (tableDecorator != null) { struct.decoratedValue = tableDecorator.displayGroupedValue(struct.bodyValue, groupingValue, header.getColumnNumber()); } else if (groupingValue == GROUP_END || groupingValue == GROUP_NO_CHANGE) { struct.decoratedValue = TagConstants.EMPTY_STRING; } } structsForRow.add(struct); } if (tableDecorator != null) { writeDecoratedRowStart(model); } // open row writeRowOpener(currentRow); for (Iterator iterator = structsForRow.iterator(); iterator.hasNext();) { CellStruct struct = (CellStruct) iterator.next(); writeColumnOpener(struct.column); writeColumnValue(struct.decoratedValue, struct.column); writeColumnCloser(struct.column); } if (model.isEmpty()) { if (log.isDebugEnabled()) { log.debug("[" + this.id + "] table has no columns"); } // render empty row writeRowWithNoColumns(currentRow.getObject().toString()); } // close row writeRowCloser(currentRow); // decorate row finish if (model.getTableDecorator() != null) { writeDecoratedRowFinish(model); } } // render empty list message if (model.getRowListPage().size() == 0) { writeEmptyListRowMessage(MessageFormat.format( model.getProperties().getEmptyListRowMessage(), new Object[]{new Integer(model.getNumberOfColumns())})); } } /* * writeTableBody callback methods */ /** * Called by writeTableBody to write to decorate the table. * @param model The table model for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeDecoratedRowStart(TableModel model) throws Exception; /** * Called by writeTableBody to write the start of the row structure. * @param row The table row for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeRowOpener(Row row) throws Exception; /** * Called by writeTableBody to write the start of the column structure. * @param column The table column for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeColumnOpener(Column column) throws Exception; /** * Called by writeTableBody to write a column's value. * @param value The column value. * @param column The table column for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeColumnValue(Object value, Column column) throws Exception; /** * Called by writeTableBody to write the end of the column structure. * @param column The table column for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeColumnCloser(Column column) throws Exception; /** * Called by writeTableBody to write a row that has no columns. * @param value The row value. * @throws Exception if it encounters an error while writing. */ protected abstract void writeRowWithNoColumns(String value) throws Exception; /** * Called by writeTableBody to write the end of the row structure. * @param row The table row for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeRowCloser(Row row) throws Exception; /** * Called by writeTableBody to decorate the table. * @param model The table model for which the content is written. * @throws Exception if it encounters an error while writing. */ protected abstract void writeDecoratedRowFinish(TableModel model) throws Exception; /** * Called by writeTableBody to write a message explaining that the row contains no data. * @param message The message explaining that the row contains no data. * @throws Exception if it encounters an error while writing. */ protected abstract void writeEmptyListRowMessage(String message) throws Exception; /** * This takes a column value and grouping index as the argument. It then groups the column and returns the * appropriate string back to the caller. * @param value String current cell value * @return String */ protected short groupColumns(String value, String previous, String next, int currentGroup) { short groupingKey = GROUP_NO_CHANGE; if (lowestEndedGroup < currentGroup) { // if a lower group has ended, cascade so that all subgroups end as well groupingKey += GROUP_END; } else if (next == null || !ObjectUtils.equals(value, next)) { // at the end of the list groupingKey += GROUP_END; lowestEndedGroup = currentGroup; } if (lowestStartedGroup < currentGroup) { // if a lower group has started, cascade so that all subgroups restart as well groupingKey += GROUP_START; } else if (previous == null || !ObjectUtils.equals(value, previous)) { // At the start of the list groupingKey += GROUP_START; lowestStartedGroup = currentGroup; } return groupingKey; } static class CellStruct { Column column; String bodyValue; String decoratedValue; public CellStruct(Column theColumn, String bodyValueParam) { this.column = theColumn; this.bodyValue = bodyValueParam; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -