List of usage examples for com.lowagie.text Anchor setReference
public void setReference(String reference)
Anchor
. From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java
License:Open Source License
/** * This method is used for add Outcomes in the project summary *//* w w w. j a v a 2 s . com*/ private void addProjectOutcomes(String number) { try { 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 (Exception e) { LOG.error("There was an error trying to add the project focuses to the project summary pdf", e); } Anchor anchor; ////////////////// Reporting PdfPTable table; // ********************************************************************************** // *************************** Outcome Case Studies ************************************* // ********************************************************************************** if (project.isReporting()) { document.newPage(); Paragraph cell; 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); } List<Project> lst = projectManager.getAllProjectsBasicInfo(APConstants.REPORTING_SECTION); Collections.sort(lst, new Comparator<Project>() { @Override public int compare(Project s1, Project s2) { Integer p1 = s1.getId(); Integer p2 = s2.getId(); return p1.compareTo(p2); } }); for (Project project : lst) { project = projectManager.getProject(project.getId()); if (project.isWorkplanRequired()) { String workPlanURL = this.getWorkplanURL(); if (workPlanURL != null || project.getWorkplanName() != null) { project.setWorkplanURL(workPlanURL + project.getWorkplanName()); } } // Get a route for the bilateral contract if (project.isBilateralProject()) { String bilateralContractURL = this.getBilateralContractURL(); if (bilateralContractURL != null || project.getBilateralContractProposalName() != null) { project.setWorkplanURL( bilateralContractURL + project.getBilateralContractProposalName()); } } // Getting the information of the Regions program project.setRegions( ipProgramManager.getProjectFocuses(project.getId(), APConstants.REGION_PROGRAM_TYPE)); // Getting the information of the Flagships program project.setFlagships( ipProgramManager.getProjectFocuses(project.getId(), APConstants.FLAGSHIP_PROGRAM_TYPE)); List<ProjectPartner> projectPartnerList = this.partnerManager.getProjectPartners(project, 0); for (ProjectPartner projectPartner : projectPartnerList) { projectPartner .setPartnerPersons(this.partnerPersonManager.getPartnerPersons(projectPartner)); projectPartner.setPartnerContributors( partnerManager.getProjectPartnerContributors(projectPartner)); } project.setProjectPartners(projectPartnerList); this.project = project; List<CasesStudies> caseStudiesList = caseStudiesManager.getCaseStudysByProject(project.getId()); List<IPIndicator> ipIndicatorList; IPIndicator ipIndicator; if (caseStudiesList != null) { if (!caseStudiesList.isEmpty()) { try { this.addProjectTitle(); this.addMainInformationTable(); } catch (Exception e) { System.out.println(project.getId()); e.printStackTrace(); } } for (CasesStudies caseStudie : caseStudiesList) { ipIndicatorList = new ArrayList<IPIndicator>(); for (CaseStudieIndicators indicatorCaseStudie : caseStudie .getCaseStudieIndicatorses()) { ipIndicator = indicatorManager .getIndicatorFlgship(indicatorCaseStudie.getIdIndicator()); ipIndicatorList.add(ipIndicator); } caseStudie.setCaseStudyIndicators(ipIndicatorList); } project.setCaseStudies(caseStudiesList); int counter = 0; 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)); } } document.newPage(); } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * @param deliverable deliverable to add in the summary * @param counter number of deliverable//from w w w. j a v a2 s .co m **/ private void addDelivable(Deliverable deliverable, int counter) { try { if (deliverable != null) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(480); table.setLockedWidth(true); StringBuilder stringBuilder = new StringBuilder(); PdfPCell cell_new; // **** Expected Deliverable #********* Paragraph deliverableBlock = new Paragraph(); deliverableBlock.setFont(HEADING4_FONT); if (project.isReporting()) { deliverableBlock.add(this.getText("summaries.project.deliverable") + " #" + counter); } else { if (deliverable.getYear() < config.getPlanningCurrentYear()) { deliverableBlock.add(this.getText("summaries.project.deliverable") + " #" + counter); } else { deliverableBlock .add(this.getText("summaries.project.deliverable.expected") + " #" + counter); } } deliverableBlock.add(Chunk.NEWLINE); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // **** Deliverable Information ********* deliverableBlock = new Paragraph(); deliverableBlock.setFont(BODY_TEXT_BOLD_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.information")); cell_new = new PdfPCell(deliverableBlock); cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); cell_new.setUseBorderPadding(true); cell_new.setPadding(3); cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(2); this.addTableHeaderCell(table, cell_new); // Title deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.information.title") + ": "); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(deliverable.getTitle())); deliverableBlock.add(Chunk.NEWLINE); ; // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // MOG deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); if (deliverable.getOutput() != null) { stringBuilder = new StringBuilder(); if (deliverable.getOutput().getProgram() != null && deliverable.getOutput().getProgram().getAcronym() != null) { stringBuilder.append(deliverable.getOutput().getProgram().getAcronym()); stringBuilder.append(" - MOG # "); } else { stringBuilder.append("MOG # "); } stringBuilder.append(this.getMOGIndex(deliverable.getOutput())); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); stringBuilder.append(deliverable.getOutput().getDescription()); } else { deliverableBlock.add("MOG :"); stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Main Type deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.main")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getType() != null && deliverable.getType().getCategory() != null) { stringBuilder.append(this.messageReturn(deliverable.getType().getCategory().getName())); } else { stringBuilder.append(this.messageReturn("")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Sub Type deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.sub")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getType() == null) { stringBuilder.append(this.messageReturn(this.getText("summaries.project.empty"))); } else if (deliverable.getType().getId() == 38) { stringBuilder.append(this.getText("summaries.project.deliverable.other.expected")); stringBuilder.append("("); stringBuilder.append(this.messageReturn(deliverable.getTypeOther())); stringBuilder.append(")"); } else { stringBuilder.append(this.messageReturn(deliverable.getType().getName())); } deliverableBlock.add(this.messageReturn(stringBuilder.toString())); deliverableBlock.add(Chunk.NEWLINE); ; // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Year deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.year")); stringBuilder.append(": "); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); stringBuilder.append(deliverable.getYear()); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); // Status deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.statuts")); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder = new StringBuilder(); if (deliverable.getStatus() != 0) { if (deliverable.getStatus() == Integer.parseInt(ProjectStatusEnum.Cancelled.getStatusId())) { deliverableBlock.setFont(TABLE_BODY_FONT_RED); } stringBuilder.append(this.statuses.get(String.valueOf(deliverable.getStatus()))); } else { stringBuilder.append(this.messageReturn(null)); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); // document.add(deliverableBlock); if (deliverable.isStatusCancelled() || deliverable.isStatusExtended() || deliverable.isStatusOnGoing()) { this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 1); // Justification deliverableBlock = new Paragraph(); stringBuilder = new StringBuilder(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); stringBuilder.append(this.getText("summaries.project.deliverable.information.justification")); deliverableBlock.add(stringBuilder.toString()); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(deliverable.getStatusDescription())); deliverableBlock.add(Chunk.NEWLINE); this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 1); } else { this.addTableColSpanCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1, 2); } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Next Users************************************** counter = 1; List<NextUser> nextUsers = deliverable.getNextUsers(); for (NextUser nextUser : nextUsers) { if (nextUser != null) { table = new PdfPTable(1); table.setTotalWidth(480); table.setLockedWidth(true); // Next user title deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); if (nextUsers.size() == 1) { deliverableBlock.add(this.getText("summaries.project.deliverable.next.user")); } else { deliverableBlock .add(this.getText("summaries.project.deliverable.next.user") + " #" + counter); } this.addTableHeaderCell(table, deliverableBlock); // Next user stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(nextUser.getUser()); deliverableBlock.add(this.messageReturn(stringBuilder.toString())); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Expected Changes stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.deliverable.next.user.expected.change")); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(this.messageReturn(nextUser.getExpectedChanges())); deliverableBlock.add(stringBuilder.toString()); // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); // Strategies stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.next.user.strategies")); deliverableBlock.setFont(TABLE_BODY_FONT); stringBuilder.append(this.messageReturn(nextUser.getStrategies())); deliverableBlock.add(stringBuilder.toString()); // document.add(deliverableBlock); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); counter++; } } // ********** Deliverable partnership**************************** // ******************Partner contributing counter = 1; table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); // Title partners contributing deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.partnership")); deliverableBlock.setFont(TABLE_HEADER_FONT); this.addTableHeaderCell(table, deliverableBlock); // Organization stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.deliverable.partnership.organization") + " #" + counter + " (Responsible)" + ": "); deliverableBlock.setFont(TABLE_BODY_FONT); DeliverablePartner deliverableResponsiblePartner = deliverable.getResponsiblePartner(); PartnerPerson partnerPersonResponsible = null; if (deliverableResponsiblePartner != null) { partnerPersonResponsible = deliverableResponsiblePartner.getPartner(); } if (deliverableResponsiblePartner != null && partnerPersonResponsible != null) { stringBuilder.append(this.messageReturn(partnerPersonResponsible.getComposedName())); stringBuilder.append(", "); stringBuilder .append(this.mapPartnerPersons.get(String.valueOf(partnerPersonResponsible.getId()))); } else { stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); ; this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); counter = 1; // ************** Other Partners List<DeliverablePartner> listOtherPartner = deliverable.getOtherPartners(); PartnerPerson otherResponsiblepartnerPerson = null; if (!listOtherPartner.isEmpty()) { for (DeliverablePartner deliverablePartner : listOtherPartner) { if (deliverablePartner != null) { counter++; // Title partners contributing deliverableBlock = new Paragraph(); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.setFont(BODY_TEXT_BOLD_FONT); if (listOtherPartner.size() == 1) { deliverableBlock.add(this.getText("summaries.project.deliverable.partnership")); } else { deliverableBlock.add( this.getText("summaries.project.deliverable.partnership") + " #" + counter); } // Organization stringBuilder = new StringBuilder(); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.deliverable.partnership.organization") + " #" + counter + ": "); deliverableBlock.add(""); deliverableBlock.setFont(TABLE_BODY_FONT); otherResponsiblepartnerPerson = deliverablePartner.getPartner(); if (otherResponsiblepartnerPerson != null) { stringBuilder.append( this.messageReturn(otherResponsiblepartnerPerson.getComposedName())); stringBuilder.append(", "); stringBuilder.append(this.mapPartnerPersons .get(String.valueOf(otherResponsiblepartnerPerson.getId()))); } else { stringBuilder.append(this.getText("summaries.project.empty")); } deliverableBlock.add(stringBuilder.toString()); deliverableBlock.add(Chunk.NEWLINE); ; this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_JUSTIFIED, 1); } } } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); } // ********** Ranking************************************** PdfPCell cell_new; if (project.isReporting()) { PdfPTable table = new PdfPTable(2); table.setLockedWidth(true); table.setTotalWidth(480); table.setWidths(new int[] { 7, 3 }); DeliverablesRanking deliverableRanking = deliverable.getRanking(); // summaries.project.reporting.deliverable.ranking Paragraph deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.ranking")); cell_new = new PdfPCell(deliverableBlock); cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_HEADER_BACKGROUND); cell_new.setUseBorderPadding(true); cell_new.setPadding(3); cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(2); this.addTableHeaderCell(table, cell_new); // address gender deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.addres.gender")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getAddress() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getAddress().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Get Potential deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.contribution.outcome")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getPotential() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getPotential().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Level deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.shared.ownership")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getLevel() != null) { deliverableBlock.add(this.messageReturn(deliverableRanking.getLevel().toString())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); // Personal perspective deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.personal.prespective")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableRanking != null && deliverableRanking.getPersonalPerspective() != null) { deliverableBlock .add(this.messageReturn(String.valueOf(deliverableRanking.getPersonalPerspective()))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_CENTER, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Dissemination************************************** DeliverableDissemination deliverableDissemination = deliverable.getDissemination(); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination")); this.addTableHeaderCell(table, deliverableBlock); // Open access deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.open")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { if (deliverableDissemination.getIsOpenAccess() != null && deliverableDissemination.getIsOpenAccess().booleanValue()) { deliverableBlock.add("Yes"); } else if (deliverableDissemination.getIntellectualProperty() != null && deliverableDissemination.getIntellectualProperty().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.intellectual")); } else if (deliverableDissemination.getLimitedExclusivity() != null && deliverableDissemination.getLimitedExclusivity().booleanValue()) { deliverableBlock .add(this.getText("summaries.project.reporting.deliverable.dissemination.limited")); } else if (deliverableDissemination.getRestrictedUseAgreement() != null && deliverableDissemination.getRestrictedUseAgreement().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.restricted")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock .add(this.getText("summaries.project.reporting.deliverable.dissemination.access")); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(deliverableDissemination.getRestrictedAccessUntilText()); } else if (deliverableDissemination.getEffectiveDateRestriction() != null && deliverableDissemination.getEffectiveDateRestriction().booleanValue()) { deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.effective")); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add( this.getText("summaries.project.reporting.deliverable.dissemination.embargoed")); deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(deliverableDissemination.getRestrictedEmbargoedText()); } else { deliverableBlock.add(this.messageReturn(null)); } } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // License adopted deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.license")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { if (deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LICENSE) != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LICENSE))); } else { deliverableBlock.add("No"); } } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // // Dissemination channel deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.channel")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableDissemination != null) { deliverableBlock.add(this.messageReturn(deliverableDissemination.getDisseminationChannel())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Dissemination URL deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.dissemination.url")); deliverableBlock.setFont(TABLE_BODY_FONT_LINK); if (deliverableDissemination != null) { deliverableBlock.add(this.messageReturn(deliverableDissemination.getDisseminationUrl())); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Metadata************************************** DeliverablePublicationMetadata deliverableMetadata = deliverable.getPublicationMetadata(); table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata")); this.addTableHeaderCell(table, deliverableBlock); // Description deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.description")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_DESCRIPTION))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // creator deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.creator")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn( deliverable.getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_CREATOR))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // authorID deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.authorID")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_CREATOR_ID))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Creation deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.creation")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_PUBLICATION))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Language deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.language")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_LANGUAGE)))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); // Coverage deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.metadata.coverage")); deliverableBlock.setFont(TABLE_BODY_FONT); if (deliverableMetadata != null) { deliverableBlock.add(this.messageReturn(deliverable .getMetadataValueByEncondedName(APConstants.DELIVERABLE_ENCONDING_COVERAGE))); } else { deliverableBlock.add(this.messageReturn(null)); } this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); // ********** Deliverable Data Sharing************************************** table = new PdfPTable(1); table.setLockedWidth(true); table.setTotalWidth(480); deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_HEADER_FONT); deliverableBlock.setAlignment(Element.ALIGN_LEFT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.datasharing")); this.addTableHeaderCell(table, deliverableBlock); // Files deliverableBlock = new Paragraph(); deliverableBlock.setFont(TABLE_BODY_BOLD_FONT); deliverableBlock.add(this.getText("summaries.project.reporting.deliverable.datasharing.files")); deliverableBlock.add("\n"); deliverableBlock.setFont(TABLE_BODY_FONT); List<DeliverableDataSharingFile> deliverableDataSharingFileList = deliverable.getDataSharingFile(); cell_new = new PdfPCell(deliverableBlock); cell_new.setHorizontalAlignment(Element.ALIGN_CENTER); cell_new.setVerticalAlignment(Element.ALIGN_MIDDLE); cell_new.setBackgroundColor(TABLE_BODY_ODD_ROW_BACKGROUND); cell_new.setUseBorderPadding(true); cell_new.setPadding(3); cell_new.setBorderColor(TABLE_CELL_BORDER_COLOR); cell_new.setColspan(2); Anchor anchor; Phrase myurl; counter = 0; if (deliverableDataSharingFileList != null) { for (DeliverableDataSharingFile deliverableDataSharingFile : deliverableDataSharingFileList) { if (deliverableDataSharingFile != null) { anchor = new Anchor(deliverableDataSharingFile.getFile(), TABLE_BODY_FONT_LINK); anchor.setReference(config.getDownloadURL() + "/projects/" + project.getId() + "/deliverableDataSharing/" + deliverableDataSharingFile.getFile()); myurl = new Phrase(); myurl.add(anchor); myurl.setFont(TABLE_BODY_FONT_LINK); cell_new.addElement(myurl); if (counter > 1) { cell_new.addElement(new Paragraph("\n")); } counter++; } } table.addCell(cell_new); } else { deliverableBlock.setFont(TABLE_BODY_FONT); deliverableBlock.add(this.messageReturn(null)); this.addTableBodyCell(table, deliverableBlock, Element.ALIGN_LEFT, 1); } document.add(table); deliverableBlock = new Paragraph(); deliverableBlock.add(Chunk.NEWLINE); deliverableBlock.add(Chunk.NEWLINE); document.add(deliverableBlock); } } 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 method is used for add Outcomes in the project summary */// w ww . j a v a 2 s . c o 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); } }
From source file:org.eclipse.osee.ats.rest.internal.build.report.table.BuildTraceTable.java
License:Open Source License
private Anchor setHyperlink(String element, String link) { Anchor anchor = new Anchor(element); anchor.setReference(link); return anchor; }
From source file:org.eclipse.osee.ats.rest.internal.build.report.table.UrlListTable.java
License:Open Source License
public void addUrl(Pair<String, String>... urls) { List<Anchor> toAdd = new LinkedList<Anchor>(); for (Pair<String, String> url : urls) { Anchor anchor = new Anchor(url.getFirst()); anchor.setReference(url.getSecond()); // Save to a sorted set until complete then add to table in 'close()' toAdd.add(anchor);// w w w . ja v a 2 s.c om } sortedList.add(toAdd); }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add external links section.//from w w w . j a v a2 s. com * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addExternalLinks(Document doc, Eml eml) throws DocumentException { if (!eml.getPhysicalData().isEmpty()) { Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setFont(font); p.add(new Phrase(getText("rtf.dtasets.external"), fontTitle)); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); for (PhysicalData data : eml.getPhysicalData()) { p.add(new Phrase(getText("rtf.datasets.description"), fontTitle)); p.add(Chunk.NEWLINE); if (exists(data.getName())) { p.add(new Phrase(getText("rtf.datasets.object") + ": ", fontTitle)); p.add(data.getName()); p.add(Chunk.NEWLINE); } if (exists(data.getCharset())) { p.add(new Phrase(getText("rtf.datasets.character") + ": ", fontTitle)); p.add(data.getCharset()); p.add(Chunk.NEWLINE); } if (exists(data.getFormat())) { p.add(new Phrase(getText("rtf.datasets.format") + ": ", fontTitle)); p.add(data.getFormat()); p.add(Chunk.NEWLINE); } if (exists(data.getFormatVersion())) { p.add(new Phrase(getText("rtf.datasets.format.version") + ": ", fontTitle)); p.add(data.getFormatVersion()); p.add(Chunk.NEWLINE); } if (exists(data.getDistributionUrl())) { p.add(new Phrase(getText("rtf.datasets.distribution") + ": ", fontTitle)); Anchor distributionLink = new Anchor(data.getDistributionUrl(), fontLink); distributionLink.setReference(data.getDistributionUrl()); p.add(distributionLink); p.add(Chunk.NEWLINE); } p.add(Chunk.NEWLINE); } doc.add(p); p.clear(); } }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Construct IPT URL public resource link, and add it to the document. Only public or registered resources can * have a public resource link./*w w w . jav a 2s . c o m*/ * </p> * e.g. Data published through GBIF: http://localhost:8090/ipt/resource.do?r=shortName * * @param doc Document * @param resource Resource * @throws DocumentException if an error in adding to the document was encountered */ private void addResourceLink(Document doc, Resource resource) throws DocumentException { if (resource.getStatus() != PublicationStatus.PRIVATE) { // begin new paragraph Paragraph p = new Paragraph(); p.setFont(font); // construct GBIF link p.add(new Phrase(getText("rtf.resourceLink") + " ", fontTitle)); Anchor gbifLink = new Anchor("GBIF", fontLinkTitle); gbifLink.setReference(Constants.GBIF_HOME_PAGE_URL); //p.add(gbifLink); p.add(": "); // attach the IPT Public URL resource link URL url = resourceManager.getPublicResourceLink(resource.getShortname()); String link = (url != null) ? url.toString() : null; // the link only gets added, if it isn't null if (link != null) { Anchor resourceLink = new Anchor(link, fontLink); resourceLink.setReference(link); p.add(resourceLink); p.add(Chunk.NEWLINE); doc.add(p); p.clear(); } } }
From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java
License:Open Source License
/** * Emits a URL with the specified cover text. Creates a clickable link in the PDF doc. * If no cover text is null (so, not specified), then the text defaults to the URL itself. * (In other words, http://pz.org would print as is.) * * @param url the URL of the link//from w w w .j ava 2s . co m * @param text words to be printed and made linkable (in lieu of printing the URL) */ public void addUrl(final String url, final String text) { if (url == null) { return; } String coverText = text; if (coverText == null) { coverText = url; } Anchor anchor = new Anchor(coverText, pdfData.getFont().getItextFont()); anchor.setReference(url); try { makeSureOutfileIsOpen(); } catch (IOException ioe) { return; } if (iTPara == null) { startNewParagraph(); } iTPara.add(anchor); }
From source file:org.revager.export.ProtocolPDFExporter.java
License:Open Source License
/** * Write the title page of the protocol. * /* w w w. ja v a 2s . co m*/ * @param meetings * the meetings * @param attachProdExtRefs * true, if the external reference of the product should be part * of the protocol * * @throws ExportException * If an error occurs while writing the title page */ protected void writeTitlePage(List<Meeting> meetings, boolean attachProdExtRefs) throws ExportException { try { Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font plainFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 11); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 11); Font boldItalicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 8); Font protocolFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 20); Font reviewFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 15); Font meetingFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 13); /* * Title of the protocol */ PdfPTable tableTitlePage = new PdfPTable(new float[] { 0.6f, 0.4f }); tableTitlePage.setWidthPercentage(100); tableTitlePage.setSplitRows(false); tableTitlePage.getDefaultCell().setBorder(0); tableTitlePage.getDefaultCell().setPadding(0); String protocolTitle = translate("Findings List of the Review"); if (meetings.size() == 1) { protocolTitle = translate("Findings List of the Review Meeting"); } PdfPCell cellProtocol = new PdfPCell(new Phrase(protocolTitle, protocolFontTitle)); cellProtocol.setHorizontalAlignment(Element.ALIGN_CENTER); cellProtocol.setColspan(2); cellProtocol.setBorderWidth(0); cellProtocol.setPaddingTop(PDFTools.cmToPt(0.4f)); cellProtocol.setPaddingBottom(PDFTools.cmToPt(0.2f)); tableTitlePage.addCell(cellProtocol); /* * Name of the review */ PdfPCell cellRevName = new PdfPCell( new Phrase(Application.getInstance().getReviewMgmt().getReviewName(), reviewFontTitle)); cellRevName.setHorizontalAlignment(Element.ALIGN_CENTER); cellRevName.setColspan(2); cellRevName.setBorderWidth(0); cellRevName.setPaddingBottom(PDFTools.cmToPt(1.6f)); tableTitlePage.addCell(cellRevName); /* * Review meeting date and location */ if (meetings.size() == 1) { sdfDate.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone()); sdfTime.setTimeZone(meetings.get(0).getProtocol().getDate().getTimeZone()); String meetingDate = sdfDate.format(meetings.get(0).getProtocol().getDate().getTime()); String meetingTime = sdfTime.format(meetings.get(0).getProtocol().getStart().getTime()) + " - " + sdfTime.format(meetings.get(0).getProtocol().getEnd().getTime()) + " [" + meetings.get(0).getProtocol().getEnd().getTimeZone().getDisplayName() + "]"; Phrase phraseMeeting = new Phrase(meetingDate + " (" + meetingTime + ")", meetingFontTitle); PdfPCell cellMeeting = new PdfPCell(phraseMeeting); cellMeeting.setColspan(2); cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER); cellMeeting.setPadding(0); cellMeeting.setBorderWidth(0); tableTitlePage.addCell(cellMeeting); String location = meetings.get(0).getProtocol().getLocation(); if (location.trim().equals("")) { location = "--"; } cellMeeting = new PdfPCell(new Phrase(translate("Location") + ": " + location, meetingFontTitle)); cellMeeting.setColspan(2); cellMeeting.setHorizontalAlignment(Element.ALIGN_CENTER); cellMeeting.setPadding(0); cellMeeting.setBorderWidth(0); cellMeeting.setPaddingTop(PDFTools.cmToPt(0.15f)); cellMeeting.setPaddingBottom(PDFTools.cmToPt(1.9f)); tableTitlePage.addCell(cellMeeting); } /* * Review description and comments */ PdfPCell cellRevDesc = new PdfPCell(new Phrase(translate("Review Description:"), boldItalicFont)); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); tableTitlePage.addCell(cellRevDesc); cellRevDesc = new PdfPCell(new Phrase(translate("Review Comments"), boldFont)); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setBackgroundColor(cellBackground); tableTitlePage.addCell(cellRevDesc); String revDesc = Application.getInstance().getReviewMgmt().getReviewDescription(); if (revDesc.trim().equals("")) { revDesc = "--"; } Phrase phrDesc = new Phrase(revDesc, plainFont); phrDesc.setLeading(leading); cellRevDesc = new PdfPCell(); cellRevDesc.addElement(phrDesc); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setPaddingBottom(padding * 1.8f); tableTitlePage.addCell(cellRevDesc); String revComm = Application.getInstance().getReviewMgmt().getReviewComments(); if (revComm.trim().equals("")) { revComm = "--"; } Phrase phrComm = new Phrase(revComm, italicFont); phrComm.setLeading(leading); cellRevDesc = new PdfPCell(); cellRevDesc.addElement(phrComm); cellRevDesc.setBorderWidth(0); cellRevDesc.setPadding(padding); cellRevDesc.setPaddingBottom(padding * 1.8f); cellRevDesc.setBackgroundColor(cellBackground); tableTitlePage.addCell(cellRevDesc); tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2)); /* * Product title */ PdfPTable tableProduct = new PdfPTable(new float[] { 0.07f, 0.93f }); tableProduct.setWidthPercentage(100); tableProduct.setSplitRows(false); tableProduct.getDefaultCell().setBorderWidth(0); tableProduct.getDefaultCell().setPadding(0); PdfPCell cellProdTitle = new PdfPCell(new Phrase(translate("Reviewed Product:"), boldItalicFont)); cellProdTitle.setColspan(2); cellProdTitle.setPadding(padding); cellProdTitle.setBorder(0); tableProduct.addCell(cellProdTitle); /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); cellListPoint.setPaddingBottom(0); /* * Write name and version of the reviewed product */ String prodName = Data.getInstance().getResiData().getReview().getProduct().getName(); if (prodName.trim().equals("")) { prodName = "--"; } Phrase phrName = new Phrase(translate("Product Name") + ": " + prodName, plainFont); phrName.setLeading(leading); PdfPCell cellName = new PdfPCell(); cellName.addElement(phrName); cellName.setBorderWidth(0); cellName.setPadding(padding); cellName.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellName); String prodVersion = Data.getInstance().getResiData().getReview().getProduct().getVersion(); if (prodVersion.trim().equals("")) { prodVersion = "--"; } Phrase phrVersion = new Phrase(translate("Product Version") + ": " + prodVersion, plainFont); phrVersion.setLeading(leading); PdfPCell cellVersion = new PdfPCell(); cellVersion.addElement(phrVersion); cellVersion.setBorderWidth(0); cellVersion.setPadding(padding); cellVersion.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellVersion); if (Application.getInstance().getReviewMgmt().getNumberOfProdRefs() > 0) { /* * Table of product references */ PdfPCell cellRefTitle = new PdfPCell(new Phrase(translate("Product References:"), boldItalicFont)); cellRefTitle.setBorderWidth(0); cellRefTitle.setPadding(padding); cellRefTitle.setPaddingTop(padding * 4); cellRefTitle.setColspan(2); tableProduct.addCell(cellRefTitle); /* * Textual references */ for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) { Phrase phraseRef = new Phrase(ref, plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); tableProduct.addCell(cellListPoint); tableProduct.addCell(cellRef); } /* * External file references */ for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), plainFont)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFont)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); tableProduct.addCell(cellListPoint); if (attachProdExtRefs) { cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); } tableProduct.addCell(cellRef); } } /* * Add the product table to the base table */ PdfPCell cellProduct = new PdfPCell(tableProduct); cellProduct.setBorder(0); cellProduct.setPadding(0); tableTitlePage.addCell(cellProduct); /* * List the meetings of this review */ PdfPCell cellInfos = new PdfPCell(); cellInfos.setBorder(0); cellInfos.setPadding(0); /* * meeting list title or meeting info title */ PdfPTable tableInfos = new PdfPTable(new float[] { 0.09f, 0.91f }); tableInfos.setWidthPercentage(100); tableInfos.setSplitRows(false); tableInfos.getDefaultCell().setBorderWidth(0); tableInfos.getDefaultCell().setPadding(0); String title = translate("Meeting Information:"); if (meetings.size() > 1) { title = translate("Findings Lists of the Review Meetings:"); } PdfPCell cellInfosTitle = new PdfPCell(new Phrase(title, boldFont)); cellInfosTitle.setColspan(2); cellInfosTitle.setPadding(padding); cellInfosTitle.setBorder(0); tableInfos.addCell(cellInfosTitle); if (meetings.size() > 1) { /* * list the meetings of this review (for review protocols) */ for (Meeting m : meetings) { Protocol protocol = m.getProtocol(); if (protocol != null) { String meetingDate = sdfDate.format(protocol.getDate().getTime()); String meetingTime = sdfTime.format(protocol.getStart().getTime()) + " - " + sdfTime.format(protocol.getEnd().getTime()) + " [" + protocol.getEnd().getTimeZone().getDisplayName() + "]"; String protLoc = protocol.getLocation(); if (protLoc.trim().equals("")) { protLoc = "--"; } Phrase phraseMeet = new Phrase( translate("Date") + ": " + meetingDate + "\n" + translate("Time") + ": " + meetingTime + "\n" + translate("Location") + ": " + protLoc, italicFont); Paragraph paraMeet = new Paragraph(); paraMeet.setLeading(leading); Anchor anchor = new Anchor(phraseMeet); anchor.setReference("#" + Long.toString( protocol.getDate().getTimeInMillis() + protocol.getStart().getTimeInMillis())); paraMeet.add(anchor); PdfPCell cellMeet = new PdfPCell(); cellMeet.addElement(paraMeet); cellMeet.setBorderWidth(0); cellMeet.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeet); } } } else { Protocol prot = meetings.get(0).getProtocol(); Duration meetDur = DatatypeFactory.newInstance() .newDuration(prot.getEnd().getTimeInMillis() - prot.getStart().getTimeInMillis()); Phrase phraseMeetInfo = new Phrase( translate("Duration of the meeting") + ":\n" + meetDur.getHours() + " " + translate("Hour(s)") + ", " + meetDur.getMinutes() + " " + translate("Minute(s)"), italicFont); phraseMeetInfo.setLeading(leading); PdfPCell cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); /* * meeting number of findings */ phraseMeetInfo = new Phrase(translate("Number of findings") + ": " + prot.getFindings().size(), italicFont); phraseMeetInfo.setLeading(leading); cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); /* * meeting number of attendees */ phraseMeetInfo = new Phrase( translate("Number of attendees") + ": " + protMgmt.getAttendees(prot).size(), italicFont); phraseMeetInfo.setLeading(leading); cellMeetInfo = new PdfPCell(); cellMeetInfo.addElement(phraseMeetInfo); cellMeetInfo.setBorderWidth(0); cellMeetInfo.setPadding(padding); tableInfos.addCell(cellListPoint); tableInfos.addCell(cellMeetInfo); } cellInfos.addElement(tableInfos); cellInfos.setBackgroundColor(cellBackground); cellInfos.setPaddingBottom(padding); tableTitlePage.addCell(cellInfos); /* * Insert vertical strut */ tableTitlePage.addCell(createVerticalStrut(PDFTools.cmToPt(1.0f), 2)); /* * Write general impression and recommendation */ PdfPTable tableRevInfo = new PdfPTable(new float[] { 0.5f, 0.5f }); tableRevInfo.setWidthPercentage(100); tableRevInfo.setSplitRows(false); tableRevInfo.getDefaultCell().setBorderWidth(0); tableRevInfo.getDefaultCell().setPadding(0); /* * Insert vertical strut */ tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.5f), 2)); PdfPCell cellImpr = new PdfPCell( new Phrase(translate("General impressions of the product:"), boldFont)); cellImpr.setBorderWidth(0); cellImpr.setPadding(padding); cellImpr.setBorderColor(verticalBorderColor); cellImpr.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellImpr); PdfPCell cellReco = new PdfPCell( new Phrase(translate("Final recommendation for the product:"), boldFont)); cellReco.setBorderWidth(0); cellReco.setPadding(padding); cellReco.setBorderColor(verticalBorderColor); cellReco.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellReco); String impression = Application.getInstance().getReviewMgmt().getImpression(); if (impression.trim().equals("")) { impression = "--"; } Phrase phrImpr = new Phrase(impression, italicFont); phrImpr.setLeading(leading); cellImpr = new PdfPCell(); cellImpr.addElement(phrImpr); cellImpr.setBorderWidth(0); cellImpr.setPadding(padding); cellImpr.setPaddingBottom(padding * 1.8f); cellImpr.setBorderColor(verticalBorderColor); cellImpr.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellImpr); String recommendation = Application.getInstance().getReviewMgmt().getRecommendation(); if (recommendation.trim().equals("")) { recommendation = "--"; } Phrase phrReco = new Phrase(recommendation, italicFont); phrReco.setLeading(leading); cellReco = new PdfPCell(); cellReco.addElement(phrReco); cellReco.setBorderWidth(0); cellReco.setPadding(padding); cellReco.setPaddingBottom(padding * 1.8f); cellReco.setBorderColor(verticalBorderColor); cellReco.setBorderWidthLeft(verticalBorderWidth); tableRevInfo.addCell(cellReco); /* * Add vertical strut */ tableRevInfo.addCell(createVerticalStrut(PDFTools.cmToPt(0.8f), 2)); /* * Write possible severities for this review */ String severities = ""; String separator = ""; for (String sev : Application.getInstance().getSeverityMgmt().getSeverities()) { severities = severities + separator + sev; separator = "; "; } Phrase phrSeverities = new Phrase(); phrSeverities.add(new Chunk( translate("The severities of the findings in this review (descending order of importance):"), italicFontSmall)); phrSeverities.add(new Chunk(" " + severities, boldItalicFontSmall)); phrSeverities.setLeading(leading); PdfPCell cellSevs = new PdfPCell(); cellSevs.setColspan(2); cellSevs.addElement(phrSeverities); cellSevs.setBorderWidth(0); cellSevs.setPadding(padding); tableRevInfo.addCell(cellSevs); /* * Short review statistics */ if (meetings.size() > 1) { Phrase phrRevStat = new Phrase(MessageFormat.format(translate( "This review consists of {0} attendees, {1} findings, {2} meetings and {3} aspects."), Application.getInstance().getReviewMgmt().getNumberOfAttendees(), Application.getInstance().getReviewMgmt().getNumberOfFindings(), Application.getInstance().getReviewMgmt().getNumberOfMeetings(), Application.getInstance().getReviewMgmt().getNumberOfAspects()), italicFontSmall); phrRevStat.setLeading(leading); PdfPCell cellRevStat = new PdfPCell(); cellRevStat.setColspan(2); cellRevStat.setHorizontalAlignment(Element.ALIGN_CENTER); cellRevStat.addElement(phrRevStat); cellRevStat.setBorderWidth(0); cellRevStat.setPadding(padding); cellRevStat.setPaddingTop(0); tableRevInfo.addCell(cellRevStat); } /* * Write the date of creation */ String creationDate = sdfDate.format(new Date().getTime()); Phrase phrCreationDate = new Phrase( translate("This finding has been created with RevAger on") + " " + creationDate, plainFontSmall); phrCreationDate.setLeading(leading); PdfPCell cellCrDate = new PdfPCell(); cellCrDate.setColspan(2); cellCrDate.setHorizontalAlignment(Element.ALIGN_CENTER); cellCrDate.addElement(phrCreationDate); cellCrDate.setBorderWidth(0); cellCrDate.setPadding(0); cellCrDate.setPaddingLeft(padding); cellCrDate.setPaddingRight(padding); tableRevInfo.addCell(cellCrDate); /* * Add content to the base table */ PdfPCell cellRevInfo = new PdfPCell(); cellRevInfo.setColspan(2); cellRevInfo.setBorder(0); cellRevInfo.setPadding(0); cellRevInfo.addElement(tableRevInfo); tableTitlePage.addCell(cellRevInfo); pdfDoc.add(tableTitlePage); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot generate front page of the PDF document.")); } }
From source file:ro.nextreports.engine.exporter.RtfExporter.java
License:Apache License
private RtfCell renderRtfCell(BandElement bandElement, Object value, int gridRow, int gridColumn, int rowSpan, int colSpan, boolean image) { Map<String, Object> style = buildCellStyleMap(bandElement, value, gridRow, gridColumn, colSpan); String stringValue;//from w w w.j av a 2 s .c om FontFactoryImp fact = new FontFactoryImp(); Font fnt; if (bandElement != null) { String fontName = (String) style.get(StyleFormatConstants.FONT_NAME_KEY); int size = ((Float) style.get(StyleFormatConstants.FONT_SIZE)).intValue(); fnt = getFont(fontName, size); } else { fnt = getFont(10); } RtfCell cell = null; boolean specialCell = false; if (image) { try { if (value == null) { cell = new RtfCell(new Phrase(IMAGE_NOT_FOUND)); } else { ImageBandElement ibe = (ImageBandElement) bandElement; byte[] imageBytes = getImage((String) value, ibe.getWidth(), ibe.getHeight()); cell = new RtfCell(Image.getInstance(imageBytes)); } } catch (Exception e) { cell = new RtfCell(IMAGE_NOT_LOADED); } specialCell = true; } else if (bandElement instanceof HyperlinkBandElement) { Hyperlink hyperlink = ((HyperlinkBandElement) bandElement).getHyperlink(); Anchor anchor = new Anchor(hyperlink.getText(), fnt); anchor.setReference(hyperlink.getUrl()); Phrase ph = new Phrase(); ph.add(anchor); try { cell = new RtfCell(ph); } catch (BadElementException e) { e.printStackTrace(); cell = new RtfCell(hyperlink.getText()); } specialCell = true; } else if (bandElement instanceof ReportBandElement) { Report report = ((ReportBandElement) bandElement).getReport(); ExporterBean eb = null; try { eb = getSubreportExporterBean(report); RtfExporter subExporter = new RtfExporter(eb); subExporter.export(); Table innerTable = subExporter.getTable(); cell = new RtfCell(innerTable); } catch (Exception e) { cell = new RtfCell(); e.printStackTrace(); } finally { if ((eb != null) && (eb.getResult() != null)) { eb.getResult().close(); } } specialCell = true; } else if (bandElement instanceof VariableBandElement) { VariableBandElement vbe = (VariableBandElement) bandElement; Variable var = VariableFactory.getVariable(vbe.getVariable()); if (var instanceof PageNoVariable) { cell = new RtfCell(); cell.add(new RtfPageNumber()); cell.setBorderWidth(0); specialCell = true; } } else if (bandElement instanceof ExpressionBandElement) { // special case pageNo inside an expression // bandName is not important here (it is used for groupRow // computation) PrefixSuffix pf = interpretPageNo(bandElement); if (pf != null) { updateFont(fnt, style); cell = new RtfCell(); if (!"".equals(pf.getPrefix())) { cell.add(new Phrase(pf.getPrefix(), fnt)); } cell.add(new RtfPageNumber(fnt)); if (!"".equals(pf.getSuffix())) { cell.add(new Phrase(pf.getSuffix(), fnt)); } specialCell = true; } } else if (bandElement instanceof ImageColumnBandElement) { try { String v = StringUtil.getValueAsString(value, null); if (StringUtil.BLOB.equals(v)) { cell = new RtfCell(new Phrase(StringUtil.BLOB)); } else { ImageColumnBandElement icbe = (ImageColumnBandElement) bandElement; byte[] imageD = StringUtil.decodeImage(v); byte[] imageBytes = getImage(imageD, icbe.getWidth(), icbe.getHeight()); cell = new RtfCell(Image.getInstance(imageBytes)); } } catch (Exception e) { cell = new RtfCell(IMAGE_NOT_LOADED); } specialCell = true; } if (!specialCell) { if (style.containsKey(StyleFormatConstants.PATTERN)) { stringValue = StringUtil.getValueAsString(value, (String) style.get(StyleFormatConstants.PATTERN), getReportLanguage()); } else { stringValue = StringUtil.getValueAsString(value, null, getReportLanguage()); } if (stringValue == null) { stringValue = ""; } Phrase ph; if (stringValue.startsWith("<html>")) { StringReader reader = new StringReader(stringValue); List<Element> elems = new ArrayList<Element>(); try { elems = HTMLWorker.parseToList(reader, new StyleSheet()); ph = new Phrase(); for (int i = 0; i < elems.size(); i++) { Element elem = (Element) elems.get(i); ph.add(elem); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); ph = new Phrase(stringValue, fnt); } } else { ph = new Phrase(stringValue, fnt); } try { cell = new RtfCell(ph); } catch (BadElementException e) { e.printStackTrace(); cell = new RtfCell(stringValue); } } cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (colSpan > 1) { cell.setColspan(colSpan); } if (rowSpan > 1) { cell.setRowspan(rowSpan); } setCellStyle(fnt, style, cell); return cell; }