List of usage examples for com.itextpdf.text.pdf PdfPTable keepRowsTogether
public void keepRowsTogether(int start)
From source file:fll.web.report.CategoryScoresByScoreGroup.java
License:Open Source License
@SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Category name determines table column, winner criteria determines sort") private void generateReport(final Connection connection, final Document pdfDoc, final ChallengeDescription challengeDescription, final Tournament tournament) throws SQLException, DocumentException { PreparedStatement prep = null; ResultSet rs = null;/* w w w .ja v a 2s.c o m*/ try { final String challengeTitle = challengeDescription.getTitle(); final WinnerType winnerCriteria = challengeDescription.getWinner(); final List<ScoreCategory> subjectiveCategories = challengeDescription.getSubjectiveCategories(); final Collection<String> eventDivisions = Queries.getAwardGroups(connection); final Collection<String> judgingGroups = Queries.getJudgingStations(connection, tournament.getTournamentID()); for (final ScoreCategory catElement : subjectiveCategories) { final String catName = catElement.getName(); final String catTitle = catElement.getTitle(); prep = connection.prepareStatement("SELECT "// + " Teams.TeamNumber, Teams.TeamName, Teams.Organization, FinalScores." + catName // + " FROM Teams, FinalScores" // + " WHERE FinalScores.Tournament = ?" // + " AND FinalScores.TeamNumber = Teams.TeamNumber" // + " AND FinalScores.TeamNumber IN (" // + " SELECT TeamNumber FROM TournamentTeams"// + " WHERE Tournament = ?" // + " AND event_division = ?" // + " AND judging_station = ?)" // + " ORDER BY " + catName + " " + winnerCriteria.getSortString() // ); prep.setInt(1, tournament.getTournamentID()); prep.setInt(2, tournament.getTournamentID()); for (final String division : eventDivisions) { for (final String judgingGroup : judgingGroups) { final PdfPTable table = PdfUtils.createTable(4); createHeader(table, challengeTitle, catTitle, division, judgingGroup, tournament); prep.setString(3, division); prep.setString(4, judgingGroup); boolean haveData = false; rs = prep.executeQuery(); while (rs.next()) { haveData = true; final int teamNumber = rs.getInt(1); final String teamName = rs.getString(2); final String organization = rs.getString(3); table.addCell(PdfUtils.createCell(String.valueOf(teamNumber))); table.addCell(PdfUtils.createCell(null == teamName ? "" : teamName)); table.addCell(PdfUtils.createCell(null == organization ? "" : organization)); double score = rs.getDouble(4); if (rs.wasNull()) { score = Double.NaN; } if (Double.isNaN(score)) { table.addCell(PdfUtils.createCell("No Score")); } else { table.addCell(PdfUtils.createCell(Utilities.NUMBER_FORMAT_INSTANCE.format(score))); } } if (haveData) { table.keepRowsTogether(0); pdfDoc.add(table); pdfDoc.add(Chunk.NEXTPAGE); } } // foreach station } // foreach division SQLFunctions.close(prep); prep = null; } // foreach category } finally { SQLFunctions.close(rs); SQLFunctions.close(prep); } }