List of usage examples for com.lowagie.text.pdf PdfPTable getNumberOfColumns
public int getNumberOfColumns()
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
private static void addTable(Document pdfDocument, Chapter pdfSheet, int totalWidth, float[] widths, PdfPTable pdfTable) throws Exception { final int MAX_WIDTH = (int) (pdfDocument.getPageSize().getWidth() / 842 * 65000); // if(totalWidth>MAX_WIDTH) { //Split the tables in subcolumns for (int offset = 0; offset < pdfTable.getNumberOfColumns();) { if (offset > 0) pdfSheet.add(new Chunk(" ")); //Calculates the indexes that fit the page: [offset; index2] int subTotalWidth = 0; int index2; for (index2 = offset; index2 < pdfTable.getNumberOfColumns() && subTotalWidth < MAX_WIDTH; index2++) { subTotalWidth += widths[index2] * totalWidth; }//from ww w . ja v a 2 s. c o m index2 = Math.min(index2, pdfTable.getNumberOfColumns() - 1); //Calculates the new sub widths float[] subWidths = new float[index2 - offset + 2]; for (int i = 0; i < subWidths.length - 1; i++) { subWidths[i] = widths[offset + i] * totalWidth / MAX_WIDTH; } subWidths[subWidths.length - 1] = Math.max(0, (float) (MAX_WIDTH - subTotalWidth) / MAX_WIDTH); System.out.println("PDFUtils.addTable() " + Arrays.toString(subWidths)); //Creates the new sub widths PdfPTable subtable = new PdfPTable(subWidths.length); subtable.setWidths(subWidths); for (int r = 0; r < pdfTable.getRows().size(); r++) { for (int c = 0; c < index2 - offset + 1; c++) { PdfPCell cell = pdfTable.getRow(r).getCells()[c + offset]; subtable.addCell(cell); } PdfPCell pdfCell = new PdfPCell(); pdfCell.setBorder(0); subtable.addCell(pdfCell); } subtable.setWidthPercentage(100); collapseBorder(subtable); pdfSheet.add(subtable); //Go to the next index offset offset = index2 + 1; } // } else { // //Calculates the new sub widths // float[] subWidths = new float[widths.length+1]; // for (int i = 0; i < subWidths.length-1; i++) { // subWidths[i] = widths[0]*totalWidth/MAX_WIDTH; // } // subWidths[subWidths.length-1] = Math.max(0, (float)(MAX_WIDTH-totalWidth)/MAX_WIDTH); // pdfTable.setWidths(subWidths); // pdfTable.setWidthPercentage(100); // collapseBorder(pdfTable); // pdfSheet.add(pdfTable); // } }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
private static void collapseBorder(PdfPTable pdfTable) { for (int r = 0; r < pdfTable.getRows().size(); r++) { for (int c = 0; c < pdfTable.getNumberOfColumns(); c++) { PdfPCell cell = pdfTable.getRow(r).getCells()[c]; if (cell.getBorderWidthTop() > 0 && r > 0) { PdfPCell cell2 = pdfTable.getRow(r - 1).getCells()[c]; if (cell2.getBorderWidthBottom() > 0) cell.setBorderWidthTop(0); }/* w w w .java 2 s.c o m*/ if (cell.getBorderWidthLeft() > 0 && c > 0) { PdfPCell cell2 = pdfTable.getRow(r).getCells()[c - 1]; if (cell2.getBorderWidthRight() > 0) cell.setBorderWidthLeft(0); } } } }
From source file:com.bytecode.customexporter.PDFCustomExporter.java
protected void exportCells(DataTable table, PdfPTable pdfTable) { for (UIColumn col : table.getColumns()) { if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyStatelessModel(); }/*from ww w .j a va2 s . c om*/ if (col.isRendered() && col.isExportable()) { if (col.getSelectionMode() != null) { pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont)); continue; } addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data"); } } pdfTable.completeRow(); FacesContext context = null; if (table.getRowIndex() == 0) { for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); childTable.setRowIndex(-1); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList childList = (DataList) rowExpansion.getChildren().get(0); childList.setRowIndex(-1); } } } } } for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); pdfTable.addCell(cell); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList list = (DataList) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-"); pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); } } } pdfTable.completeRow(); } }
From source file:com.crm.webapp.util.PDFCustomExporter.java
License:Apache License
protected void exportCells(DataTable table, PdfPTable pdfTable, int rowIndex) { for (UIColumn col : table.getColumns()) { UIComponent component = (UIComponent) col; ////Adding RowIndex for custom Export if (component.getId().equalsIgnoreCase("subject")) { int value = rowIndex; PdfPCell cell = new PdfPCell(new Paragraph(value + "")); //addColumnAlignments(component, cell); if (facetBackground != null) { cell.setBackgroundColor(facetBackground); }/*from w ww .ja va 2s.c o m*/ cell.setHorizontalAlignment(Element.ALIGN_CENTER); System.out.println("value is" + value); pdfTable.addCell(cell); } if (!col.isRendered()) { continue; } if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyModel(); } if (col.isExportable()) { if (col.getSelectionMode() != null) { pdfTable.addCell(new Paragraph(col.getSelectionMode(), this.cellFont)); continue; } addColumnValue(pdfTable, col.getChildren(), this.cellFont, "data"); } } pdfTable.completeRow(); FacesContext context = null; if (table.getRowIndex() == 0) { for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); childTable.setRowIndex(-1); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList childList = (DataList) rowExpansion.getChildren().get(0); childList.setRowIndex(-1); } } } } } table.setRowIndex(table.getRowIndex() + 1); for (UIComponent component : table.getChildren()) { if (component instanceof RowExpansion) { RowExpansion rowExpansion = (RowExpansion) component; if (rowExpansion.getChildren() != null) { if (rowExpansion.getChildren().get(0) instanceof DataTable) { DataTable childTable = (DataTable) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, childTable, false, false, "-", false); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); pdfTable.addCell(cell); } if (rowExpansion.getChildren().get(0) instanceof DataList) { DataList list = (DataList) rowExpansion.getChildren().get(0); PdfPTable pdfTableChild = exportPDFTable(context, list, false, "-"); pdfTableChild.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell = new PdfPCell(); cell.addElement(pdfTableChild); cell.setColspan(pdfTable.getNumberOfColumns()); } } } pdfTable.completeRow(); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addBudgetByMogOne(Paragraph paragraph, PdfPTable table, StringBuffer budgetLabel, IPElement mog, int startYear, int endYear, BudgetType budgetType) { paragraph = new Paragraph(); budgetLabel = new StringBuffer(); paragraph.setFont(TABLE_BODY_FONT);//from w ww . j a v a 2 s .c om budgetLabel.append(mog.getProgram().getAcronym()); budgetLabel.append(" - MOG # "); budgetLabel.append(this.getMOGIndex(mog)); budgetLabel.append(": "); budgetLabel.append(mog.getDescription()); budgetLabel.append(" - " + budgetType.name().replace("_", "/")); paragraph.add(budgetLabel.toString()); this.addCustomTableCell(table, paragraph, Element.ALIGN_JUSTIFIED, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); PdfPCell cell; // year paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // % de amount paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.percentaje", new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // gender paragraph = new Paragraph(this.getText("summaries.project.budget.mog.anual.gender", new String[] { budgetType.name().replace("_", "/") }), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // amount (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // amount (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); double[] totalsByYear = { 0, 0 }; for (int year = startYear; year <= endYear; year++) { paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); this.addBudgetMogByYear(year, paragraph, table, mog, budgetType, totalsByYear); } // Totals paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); // total amount $ paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[0]), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); // total gender $ paragraph = new Paragraph(this.budgetFormatter.format(totalsByYear[1]), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addBudgetPartner(ProjectPartner projectPartner, Paragraph paragraph, PdfPTable table, BudgetType budgetType, int startYear, int endYear) { PdfPCell cell;/*w w w . ja v a 2s . c om*/ paragraph = new Paragraph( projectPartner.getInstitution().getComposedName() + " " + budgetType.name().replace("_", "/"), BODY_TEXT_BOLD_FONT); this.addCustomTableCell(table, paragraph, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); // year paragraph = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // amount paragraph = new Paragraph(this.getText("summaries.project.budget.overall.amount", new String[] { "" }) + budgetType.name().toString().replace("_", "/") + " (USD)", TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setRowspan(2); this.addTableHeaderCell(table, cell); // gender paragraph = new Paragraph(this.getText("summaries.project.budget.overall.gender", new String[] { "" }) + budgetType.name().toString().replace("_", "/"), TABLE_HEADER_FONT); cell = new PdfPCell(paragraph); cell.setColspan(2); this.addTableHeaderCell(table, cell); // gender (%) paragraph = new Paragraph("(%)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); // gender (USD) paragraph = new Paragraph("(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, paragraph); for (int year = startYear; year <= endYear; year++) { paragraph = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); this.addRowBudgetByPartners(paragraph, projectPartner.getInstitution(), year, table, budgetType); } // ************** Totals paragraph = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_CENTER, 0); // amount double value = this.budgetManager.calculateTotalCCAFSBudgetByInstitutionAndType(project.getId(), projectPartner.getInstitution().getId(), budgetType.getValue()); paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, paragraph, Element.ALIGN_RIGHT, 1); // gender value = this.budgetManager.calculateTotalGenderBudgetByInstitutionAndType(project.getId(), projectPartner.getInstitution().getId(), budgetType.getValue()); paragraph = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableColSpanCell(table, paragraph, Element.ALIGN_RIGHT, 1, 2); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This Method is for to calculate the overall or gender summary * //from w w w .j ava 2s .c o m * @param startYear start year to calculate the summary * @param endYear end year to calculate the summary * @param type this is used for to determinate the type the report to create */ private void addBudgetsSummaryByPartners(int startYear, int endYear, int typeSummary) { try { Paragraph cell; if (typeSummary == 0) { cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Overall" }), BODY_TEXT_BOLD_FONT); } else { cell = new Paragraph(this.getText("summaries.project.budget.summary", new String[] { "Gender" }), BODY_TEXT_BOLD_FONT); } PdfPTable table; if (project.isCoFundedProject()) { table = new PdfPTable(4); table.setWidths(new int[] { 2, 3, 3, 3 }); } else { table = new PdfPTable(2); table.setWidths(new int[] { 3, 3 }); } table.setLockedWidth(true); table.setTotalWidth(400); table.setHeaderRows(1); // Add cell with the name summary this.addCustomTableCell(table, cell, Element.ALIGN_CENTER, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); cell = new Paragraph(this.getText("summaries.project.budget.overall.type"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); if (project.isCoFundedProject()) { if (typeSummary == 0) { cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } else { cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { BudgetType.W1_W2.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { BudgetType.W3_BILATERAL.name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } this.addTableHeaderCell(table, cell); // Total column cell = new Paragraph(this.getText("summaries.project.budget.overall.total") + " (USD)", TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); } else { if (typeSummary == 0) { cell = new Paragraph( this.getText("summaries.project.budget.overall.text", new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } else { cell = new Paragraph( this.getText("summaries.project.budget.overall.gender", new String[] { this.getBudgetType().name().replace("_", "/") }) + "(USD)", TABLE_HEADER_FONT); } this.addTableHeaderCell(table, cell); } double value, valueSum; value = 0.0; for (int year = startYear; year <= endYear; year++) { cell = new Paragraph(String.valueOf(year), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0); valueSum = 0.0; if (project.isCoFundedProject()) { if (typeSummary == 0) { // amount w1/w2 value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), BudgetType.W1_W2.getValue(), year); cell = new Paragraph(this.budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; // amount w3/Bilateral value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), BudgetType.W3_BILATERAL.getValue(), year); } else { // gender w1/w2 value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), BudgetType.W1_W2.getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; // gender w3/Bilateral value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), BudgetType.W3_BILATERAL.getValue(), year); } cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); // Total valueSum += value; cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { if (typeSummary == 0) { // amount w1/w2 value = this.budgetManager.calculateProjectBudgetByTypeAndYear(project.getId(), this.getBudgetType().getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { // gender w1/w2 value = this.budgetManager.calculateGenderBudgetByTypeAndYear(project.getId(), this.getBudgetType().getValue(), year); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_FONT); ; this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } } } // ********************** Totals ************* cell = new Paragraph(this.getText("summaries.project.budget.overall.total"), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 0); if (project.isCoFundedProject()) { if (typeSummary == 0) { value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), BudgetType.W1_W2.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), BudgetType.W3_BILATERAL.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum += value; } else { value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), BudgetType.W1_W2.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), BudgetType.W3_BILATERAL.getValue()); cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum += value; } // Total cell = new Paragraph(budgetFormatter.format(valueSum), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); } else { if (typeSummary == 0) { value = budgetManager.calculateTotalCCAFSBudgetByType(project.getId(), this.getBudgetType().getValue()); } else { value = budgetManager.calculateTotalGenderPercentageByType(project.getId(), this.getBudgetType().getValue()); } cell = new Paragraph(budgetFormatter.format(value), TABLE_BODY_BOLD_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_RIGHT, 1); valueSum = value; } document.add(table); cell = new Paragraph(Chunk.NEWLINE); document.add(cell); } catch (DocumentException e) { LOG.error( "-- generatePdf() > There was an error adding the table with content for case study summary. ", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This is an auxiliar method for to get information project partners in the paragrapn block. * /*from w w w . j a va2s . c om*/ * @param partner partner to get information * @param numberPP number of project partner * @param partnersBlock paragraph to add the information */ private void addPartner(ProjectPartner partner, int numberPP) { if (!(partner == null)) { try { PdfPTable table = new PdfPTable(1); table.setTotalWidth(500); table.setLockedWidth(true); // ///////////////////////////////////////////////////////////////////// Paragraph paragraph = new Paragraph(); // Partner # paragraph.setFont(HEADING3_FONT); if (project.getLeader() != null && partner.getId() == project.getLeader().getId()) { paragraph.add(this.getText("summaries.project.partner") + numberPP + " " + this.getText("summaries.project.partner.leader")); } else { paragraph.add(this.getText("summaries.project.partner") + numberPP + " "); } paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); document.add(paragraph); // Organization paragraph = new Paragraph(); paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.add(this.getText("summaries.project.organization")); paragraph.setFont(BODY_TEXT_FONT); if (partner.getInstitution() != null) { if (!((partner.getInstitution().getAcronym() == null) || (partner.getInstitution().getAcronym().isEmpty()))) { paragraph.add(partner.getInstitution().getAcronym()); paragraph.add(" - "); } paragraph.add(this.messageReturn(partner.getInstitution().getName())); } else { paragraph.add("Not defined"); } document.add(paragraph); // CCAFS Partner(s) allocating budget: if (!partner.getInstitution().isPPA()) { table = new PdfPTable(1); table.setTotalWidth(500); table.setLockedWidth(true); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); // title contributing paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.add(this.getText("summaries.project.projectPartners.ccafs.partner.allocating")); List<ProjectPartner> partnersContributings = partner.getPartnerContributors(); if (partnersContributings.isEmpty()) { paragraph.add(": "); paragraph.setFont(BODY_TEXT_FONT); paragraph.add(this.getText("summaries.project.empty")); document.add(paragraph); } else { this.addCustomTableCell(table, paragraph, Element.ALIGN_LEFT, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); for (ProjectPartner partnerContributing : partnersContributings) { paragraph = new Paragraph(); this.addTableBodyCell(table, new Paragraph(partnerContributing.getInstitution().getComposedName(), TABLE_BODY_FONT), Element.ALIGN_JUSTIFIED, 1); } } document.add(table); } paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); document.add(paragraph); // PartnerPersons table = new PdfPTable(3); table.setTotalWidth(500); table.setLockedWidth(true); table.setWidths(new int[] { 1, 3, 6 }); paragraph = new Paragraph(); paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.add(this.getText("summaries.project.partner.partnerPerson")); this.addCustomTableCell(table, paragraph, Element.ALIGN_LEFT, BODY_TEXT_BOLD_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); // ***** Header Partner persons // Person type paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.partner.persontype")); this.addTableHeaderCell(table, paragraph); // contact person paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.add(this.getText("summaries.project.partner.contactperson")); this.addTableHeaderCell(table, paragraph); // responsabities paragraph = new Paragraph(); paragraph.setFont(TABLE_HEADER_FONT); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.add(this.getText("summaries.project.partner.responsibilities")); this.addTableHeaderCell(table, paragraph); paragraph.setFont(TABLE_BODY_FONT); for (PartnerPerson partnerPerson : partner.getPartnerPersons()) { // type paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_FONT); if (partnerPerson.getType() == null) { paragraph.add(this.getText("summary.project.empty")); } else if (partnerPerson.getType().equals("PL")) { paragraph.add(this.getText("planning.projectPartners.types.PL")); } else if (partnerPerson.getType().equals("PC")) { paragraph.add(this.getText("planning.projectPartners.types.PC")); } else { // is CP paragraph.add(this.getText("planning.projectPartners.types.CP")); } this.addTableColSpanCell(table, paragraph, Element.ALIGN_CENTER, 1, 1); // contact person paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_FONT); paragraph.add(this.messageReturn(partnerPerson.getComposedName())); this.addTableColSpanCell(table, paragraph, Element.ALIGN_CENTER, 1, 1); // Responsabilities paragraph = new Paragraph(); paragraph.setFont(TABLE_BODY_FONT); paragraph.add(this.messageReturn(partnerPerson.getResponsibilities())); this.addTableColSpanCell(table, paragraph, Element.ALIGN_JUSTIFIED, 1, 1); } document.add(table); paragraph = new Paragraph(); paragraph.add(Chunk.NEWLINE); paragraph.add(Chunk.NEWLINE); document.add(paragraph); } catch (DocumentException e) { LOG.error( "-- generatePdf() > There was an error adding the table with content for case study summary. ", e); } } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
private void addProjectContributions() { try {//ww w . j av a 2 s .c o m PdfPTable table = new PdfPTable(2); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 7, 3 }); Paragraph cell; StringBuffer projectFocuses = new StringBuffer(); // ************************ Adding flagships and regions ********************************** List<IPProgram> listIPFlagship = project.getFlagships(); List<IPProgram> listIPRegions = project.getRegions(); if (listIPFlagship.isEmpty() && listIPRegions.isEmpty()) { cell = new Paragraph(this.getText("summaries.project.ipContributions"), BODY_TEXT_BOLD_FONT); cell.setFont(BODY_TEXT_BOLD_FONT); cell.add(": "); projectFocuses.append(this.getText("summaries.project.empty")); cell.setFont(BODY_TEXT_FONT); cell.add(projectFocuses.toString()); document.add(cell); document.add(Chunk.NEWLINE); } else { cell = new Paragraph(this.getText("summaries.project.ipContributions"), BODY_TEXT_BOLD_FONT); this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); cell = new Paragraph("", TABLE_HEADER_FONT); cell.setAlignment(Element.ALIGN_LEFT); cell.add(this.getText("summaries.project.ipContributions.flagship")); this.addTableHeaderCell(table, cell); cell = new Paragraph("", TABLE_HEADER_FONT); cell.setAlignment(Element.ALIGN_LEFT); cell.add(this.getText("summaries.project.ipContributions.region")); this.addTableHeaderCell(table, cell); int sizeFlaships = listIPFlagship.size(); int sizeRegions = listIPRegions.size(); if (sizeFlaships < sizeRegions) { this.addEmptyFlashigAndRegion(listIPFlagship, sizeRegions); } else if (sizeFlaships > sizeRegions) { this.addEmptyFlashigAndRegion(listIPRegions, sizeFlaships); } IPProgram program; for (int a = 0; a < listIPRegions.size(); a++) { // Flashing program = listIPFlagship.get(a); if (program.getComposedName() == null || program.getComposedName().isEmpty()) { cell = new Paragraph("", TABLE_BODY_FONT); } else { cell = new Paragraph(program.getComposedName(), TABLE_BODY_FONT); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Regions program = listIPRegions.get(a); if (program.getComposedName() == null || program.getComposedName().isEmpty()) { cell = new Paragraph("", TABLE_BODY_FONT); } else { cell = new Paragraph(program.getComposedName(), TABLE_BODY_FONT); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); } document.add(table); document.add(Chunk.NEWLINE); } // ******************** Adding Bilateral ******************************************** List<Project> listLinkageProject = project.getLinkedProjects(); cell = new Paragraph(); projectFocuses = new StringBuffer(); if (project.isBilateralProject()) { projectFocuses .append(this.getText("summaries.project.ipContributions.project", new String[] { "Core" })); } else { projectFocuses.append( this.getText("summaries.project.ipContributions.project", new String[] { "Bilateral" })); } if (listLinkageProject != null && !listLinkageProject.isEmpty()) { table = new PdfPTable(1); // Set table widths table.setLockedWidth(true); table.setTotalWidth(480); cell.setFont(TABLE_HEADER_FONT); cell.add(projectFocuses.toString()); table.setWidths(new int[] { 5 }); // Adding Header this.addTableHeaderCell(table, cell); for (Project projectContribution : project.getLinkedProjects()) { projectFocuses = new StringBuffer(); projectFocuses.append(projectContribution.getId()); projectFocuses.append(" - "); projectFocuses.append(projectContribution.getTitle()); cell = new Paragraph(projectFocuses.toString(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } document.add(table); document.add(Chunk.NEWLINE); } else { cell.setFont(BODY_TEXT_BOLD_FONT); cell.add(projectFocuses.toString()); cell.add(Chunk.NEWLINE); cell.setFont(BODY_TEXT_FONT); projectFocuses = new StringBuffer(); if (project.isBilateralProject()) { projectFocuses.append( this.getText("summaries.project.ipContributions.noproject", new String[] { "Core" })); } else { projectFocuses.append(this.getText("summaries.project.ipContributions.noproject", new String[] { "Bilateral" })); } cell.add(projectFocuses.toString()); document.add(cell); document.add(Chunk.NEWLINE); } /* * if (project.isBilateralProject()) { * projectFocuses = new StringBuffer(); * cell = new Paragraph(); * cell.setFont(BODY_TEXT_BOLD_FONT); * projectFocuses.append(this.getText("summaries.project.ipContributions.proposal")); * cell.add(projectFocuses.toString()); * cell.setFont(BODY_TEXT_FONT); * cell.add(this.messageReturn(project.getBilateralContractProposalName())); * document.add(cell); * document.add(Chunk.NEWLINE); * } */ } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * This method is used for add Outcomes in the project summary */// w ww . j a v a 2s. co m private void addProjectOutcomes(String number) { Paragraph outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); Paragraph title = new Paragraph(number + ". " + this.getText("summaries.project.outcome"), HEADING2_FONT); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); ; title = new Paragraph(); title.setFont(HEADING3_FONT); title.add(number + ".1 " + this.getText("summaries.project.outcomeNarrative")); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); ; // Project outcome statement Paragraph body = new Paragraph(); body.setFont(BODY_TEXT_BOLD_FONT); body.add(this.getText("summaries.project.outcomeStatement")); // body.setFont(BODY_TEXT_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)) == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement() == null || project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement().equals("")) { body.add(": "); body.setFont(BODY_TEXT_FONT); body.add(this.getText("summaries.project.empty")); } else { body.setFont(BODY_TEXT_FONT); body.add(Chunk.NEWLINE); body.add(this.messageReturn(project.getOutcomes().get(String.valueOf(midOutcomeYear)).getStatement())); } body.add(Chunk.NEWLINE); ; outcomesBlock.add(body); try { document.newPage(); document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } Anchor anchor; currentPlanningYear--; ////////////////// Reporting PdfPTable table; if (project.isReporting()) { for (int year = currentPlanningYear; year < midOutcomeYear; year++) { // Annual progress towards outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress", new String[] { String.valueOf(year) })); outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add( this.messageReturn(project.getOutcomes().get(String.valueOf(year)).getStatement())); } outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } if (year == this.currentPlanningYear) { table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); ///// outcome toward in reporting cycle outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualTowards", new String[] { String.valueOf(year) })); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add(this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getAnualProgress())); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1); ///// outcome communication outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualCommunication")); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { outcomesBlock.add(this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getComunication())); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_JUSTIFIED, 1); // Any evendence outcomesBlock = new Paragraph(); outcomesBlock.setFont(TABLE_BODY_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualEvidence")); outcomesBlock.setFont(TABLE_BODY_FONT); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null || project.getOutcomes().get(String.valueOf(year)).getFile() == null || project.getOutcomes().get(String.valueOf(year)).getFile().equals("")) { outcomesBlock.add(this.getText("summaries.project.empty")); } else { anchor = new Anchor(project.getOutcomes().get(String.valueOf(year)).getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/project_outcome/" + project.getOutcomes().get(String.valueOf(year)).getFile()); outcomesBlock.add(anchor); } this.addTableBodyCell(table, outcomesBlock, Element.ALIGN_LEFT, 1); try { document.add(table); outcomesBlock = new Paragraph(); outcomesBlock.add(Chunk.NEWLINE); document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } } } } ////////////////// Planning else { String outcomeProgress = new String(); for (int year = currentPlanningYear; year < midOutcomeYear; year++) { // Annual progress towards outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this.getText("summaries.project.outcomeAnnualProgress", new String[] { String.valueOf(year) })); if (project.getOutcomes() == null || project.getOutcomes().get(String.valueOf(year)) == null || project.getOutcomes().get(String.valueOf(year)).getStatement() == null || project.getOutcomes().get(String.valueOf(year)).getStatement().equals("")) { outcomesBlock.add(": "); outcomesBlock.setFont(BODY_TEXT_FONT); outcomeProgress = this.getText("summaries.project.empty"); } else { outcomesBlock.add(Chunk.NEWLINE); outcomeProgress = this .messageReturn(project.getOutcomes().get(String.valueOf(year)).getStatement()); outcomesBlock.setFont(BODY_TEXT_FONT); } outcomesBlock.add(outcomeProgress); outcomesBlock.add(Chunk.NEWLINE); ; outcomesBlock.add(Chunk.NEWLINE); ; try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } } } // Lesson regardins outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); if (project.isReporting()) { outcomesBlock.add(this.getText("summaries.project.outcome.reporting.lessonRegarding")); } else { outcomesBlock.add(this.getText("summaries.project.outcome.lessonRegarding")); } outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("outcomes") != null) { outcomesBlock.add(this.messageReturn(project.getComponentLesson("outcomes").getLessons())); } else { outcomesBlock.add(this.messageReturn(null)); } try { document.add(outcomesBlock); } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } // ******************* CCAFS Outcomes***************/ this.addProjectCCAFSOutcomes(number); // ********************************************************************************** // ******************* Other contributions***************/ // ********************************************************************************** OtherContribution otherContribution = project.getIpOtherContribution(); try { outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); title = new Paragraph( number + ".3 " + this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions"), HEADING3_FONT); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(title); outcomesBlock.add(Chunk.NEWLINE); // Contribution to other Impact Pathways: outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); if (project.isReporting()) { outcomesBlock.add(this.getText( "summaries.project.outcome.ccafs.outcomes.reporting.other.contributions.pathways")); } else { outcomesBlock .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.pathways")); } outcomesBlock.setFont(BODY_TEXT_FONT); if (otherContribution == null || otherContribution.getContribution() == null || otherContribution.getContribution().equals("")) { outcomesBlock.add(": " + this.getText("summaries.project.empty")); } else { outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(otherContribution.getContribution()); } outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); document.add(outcomesBlock); document.add(Chunk.NEWLINE); Paragraph cell; if (project.isReporting()) { if (project.getOtherContributions().isEmpty()) { } else { table = new PdfPTable(4); table.setWidths(new int[] { 2, 4, 4, 4 }); table.setLockedWidth(true); table.setTotalWidth(500); // adding headers cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.region"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.indicator"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.describe", new String[] { String.valueOf(this.currentReportingYear) }), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.ablequantily"), TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); // Adding contain for (ProjecteOtherContributions projectOther : project.getOtherContributions()) { cell = new Paragraph(projectOther.getRegion(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(projectOther.getIndicators(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(projectOther.getDescription(), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); cell = new Paragraph(String.valueOf(projectOther.getTarget()), TABLE_BODY_FONT); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } document.add(table); document.add(Chunk.NEWLINE); } // // Collaboration with other CRPs cell = new Paragraph(this.getText("summaries.project.reporting.ccafs.outcomes.collaborating"), BODY_TEXT_BOLD_FONT); if (project.getListCRPContributions().isEmpty()) { cell.add(": "); cell.setFont(BODY_TEXT_FONT); cell.add(this.messageReturn(null)); cell.add(Chunk.NEWLINE); document.add(cell); } else { document.add(cell); document.add(Chunk.NEWLINE); for (CRPContribution crpContribution : project.getListCRPContributions()) { table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); cell = new Paragraph(this.messageReturn(crpContribution.getCrp().getName()), TABLE_BODY_BOLD_FONT); cell.setAlignment(Element.ALIGN_LEFT); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph( this.getText("summaries.project.reporting.ccafs.outcomes.natureCollaboration"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(crpContribution.getNatureCollaboration())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); cell = new Paragraph( this.getText("summaries.project.reporting.ccafs.outcomes.achievedOutcome"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(this.messageReturn(crpContribution.getExplainAchieved())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); document.add(table); document.add(Chunk.NEWLINE); } } } else { outcomesBlock = new Paragraph(); // Contribution to another Center activity: outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock .add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.center")); outcomesBlock.setFont(BODY_TEXT_FONT); if (otherContribution == null || otherContribution.getAdditionalContribution() == null || otherContribution.getAdditionalContribution().equals("")) { outcomesBlock.add(": " + this.getText("summaries.project.empty")); } else { outcomesBlock.add(otherContribution.getAdditionalContribution()); outcomesBlock.add(Chunk.NEWLINE); outcomesBlock.add(Chunk.NEWLINE); } boolean addParagraph = false; cell = new Paragraph(); ; cell.setFont(BODY_TEXT_BOLD_FONT); table = new PdfPTable(2); cell.add(this.getText("summaries.project.outcome.ccafs.outcomes.other.contributions.covered")); if (otherContribution != null) { List<CRPContribution> listCRP = otherContribution.getCrpContributions(); if (listCRP.isEmpty()) { cell.setFont(BODY_TEXT_FONT); cell.add(this.getText("summaries.project.empty")); addParagraph = true; } else { table.setWidths(new int[] { 4, 6 }); table.setLockedWidth(true); table.setTotalWidth(500); this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, table.getNumberOfColumns(), 0, false); // adding headers this.addTableHeaderCell(table, new Paragraph( this.getText( "summaries.project.outcome.ccafs.outcomes.other.contributions.crp"), TABLE_HEADER_FONT)); this.addTableHeaderCell(table, new Paragraph(this.getText( "summaries.project.outcome.ccafs.outcomes.other.contributions.nature"), TABLE_HEADER_FONT)); for (CRPContribution CRPContribution : listCRP) { if (CRPContribution != null && CRPContribution.getCrp() != null) { cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add(CRPContribution.getCrp().getName()); this.addTableBodyCell(table, cell, Element.ALIGN_CENTER, 1); cell = new Paragraph(); cell.setFont(TABLE_BODY_FONT); cell.add(CRPContribution.getNatureCollaboration()); this.addTableBodyCell(table, cell, Element.ALIGN_JUSTIFIED, 1); } } } } else { cell.add(": "); cell.setFont(BODY_TEXT_FONT); cell.add(this.getText("summaries.project.empty")); addParagraph = true; } document.add(outcomesBlock); // Add paragraphs to document if (addParagraph) { document.add(cell); } else { document.add(table); } document.add(Chunk.NEWLINE); // Lesson regardins Other contributions outcomesBlock = new Paragraph(); outcomesBlock.setAlignment(Element.ALIGN_JUSTIFIED); outcomesBlock.setFont(BODY_TEXT_BOLD_FONT); outcomesBlock.add(this .getText("summaries.project.outcome.ccafs.outcomes.other.contributions.lessonRegarding")); outcomesBlock.setFont(BODY_TEXT_FONT); if (project.getComponentLesson("otherContributions") != null) { outcomesBlock .add(this.messageReturn(project.getComponentLesson("otherContributions").getLessons())); } else { outcomesBlock.add(this.messageReturn(null)); } document.add(outcomesBlock); } // ********************************************************************************** // *************************** Outcome Case Studies ************************************* // ********************************************************************************** int counter = 0; if (project.isReporting()) { document.newPage(); title = new Paragraph( number + ".4 " + this.getText("summaries.project.reporting.outcome.case.studies"), HEADING3_FONT); document.add(title); if (project.getCaseStudies().isEmpty()) { document.add( new Paragraph(this.getText("summaries.project.reporting.outcome.not.case.studies"))); } else { title = new Paragraph(); title.add(Chunk.NEWLINE); document.add(title); for (CasesStudies caseStudy : project.getCaseStudies()) { counter++; table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(500); // case study cell = new Paragraph( this.getText("summaries.project.reporting.outcome.case.study") + " #" + counter, TABLE_HEADER_FONT); this.addTableHeaderCell(table, cell); // this.addCustomTableCell(table, cell, Element.ALIGN_LEFT, BODY_TEXT_FONT, Color.WHITE, // table.getNumberOfColumns(), 0, false); // Title cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.title"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getTitle()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Outcome statement cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outcomestatement"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutcomeStatement()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Research outputs cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.researchoutputs"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getResearchOutputs()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Research partners cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.researchPartners"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getResearchPartners()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // activities Contributed cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.activitiesContributed"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getActivities()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Non Research Partners cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.nonResearchPartners"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getNonResearchPartneres()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Output Users cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outputUsers"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutputUsers()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Output Used cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.outputWasUsed"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getOutputUsed()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Evidence cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.evidenceOutcome"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getEvidenceOutcome()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // References cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.references"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getReferencesCase()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Outcome indicators cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.primaryOutcome", new String[] { String.valueOf(this.midOutcomeYear) }), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add("\n"); for (IPIndicator ipIndicator : caseStudy.getCaseStudyIndicators()) { if (ipIndicator.getOutcome() != null) { cell.add(ipIndicator.getOutcome().getDescription()); } cell.add(" " + ipIndicator.getDescription() + "\n"); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // Explain link cell = new Paragraph( this.getText("summaries.project.reporting.outcome.casestudy.explainLink"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(caseStudy.getExplainIndicatorRelation()); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // year cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.year"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); cell.add(String.valueOf(caseStudy.getYear())); this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); // upload cell = new Paragraph(this.getText("summaries.project.reporting.outcome.casestudy.upload"), TABLE_BODY_BOLD_FONT); cell.setFont(TABLE_BODY_FONT); if (caseStudy.getFile() == null || caseStudy.getFile().equals("")) { cell.add(this.messageReturn(null)); } else { anchor = new Anchor(caseStudy.getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/caseStudy/" + caseStudy.getFile()); cell.add(anchor); } this.addTableBodyCell(table, cell, Element.ALIGN_LEFT, 1); document.add(table); document.add(new Paragraph(Chunk.NEWLINE)); } } } } catch (DocumentException e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } }