Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell PdfPCell.

Prototype

public PdfPCell(PdfPCell cell) 

Source Link

Document

Constructs a deep copy of a PdfPCell.

Usage

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableFacet(FacesContext context, PdfPTable pdfTable, DataTable table, int columnCount,
        String facetType) {/*from w  w w. java 2 s . c om*/
    Map<String, UIComponent> map = table.getFacets();
    UIComponent component = map.get(facetType);
    if (component != null) {
        String headerValue = null;
        if (component instanceof HtmlCommandButton) {
            headerValue = exportValue(context, component);
        } else if (component instanceof HtmlCommandLink) {
            headerValue = exportValue(context, component);
        } else if (component instanceof UIPanel || component instanceof OutputPanel) {
            String header = "";
            for (UIComponent child : component.getChildren()) {
                headerValue = exportValue(context, child);
                header = header + headerValue;
            }

            PdfPCell cell = new PdfPCell(new Paragraph((header), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            //addColumnAlignments(component,cell);
            cell.setColspan(columnCount);
            pdfTable.addCell(cell);
            pdfTable.completeRow();

            return;
        } else {
            headerValue = exportFacetValue(context, component);
        }

        PdfPCell cell = new PdfPCell(new Paragraph((headerValue), this.facetFont));
        if (facetBackground != null) {
            cell.setBackgroundColor(facetBackground);
        }

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        //addColumnAlignments(component,cell);
        cell.setColspan(columnCount);
        pdfTable.addCell(cell);
        pdfTable.completeRow();
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableFacet(FacesContext context, PdfPTable pdfTable, SubTable table, int columnCount,
        String facetType) {/*from ww w  . ja  v a  2  s . com*/
    Map<String, UIComponent> map = table.getFacets();
    UIComponent component = map.get(facetType);
    if (component != null) {
        String headerValue = null;
        if (component instanceof HtmlCommandButton) {
            headerValue = exportValue(context, component);
        } else if (component instanceof HtmlCommandLink) {
            headerValue = exportValue(context, component);
        } else if (component instanceof UIPanel || component instanceof OutputPanel) {
            String header = "";
            for (UIComponent child : component.getChildren()) {
                headerValue = exportValue(context, child);
                header = header + headerValue;
            }

            PdfPCell cell = new PdfPCell(new Paragraph((header), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            cell.setHorizontalAlignment(Element.ALIGN_CENTER);

            //addColumnAlignments(component,cell);
            cell.setColspan(columnCount);
            pdfTable.addCell(cell);
            pdfTable.completeRow();

            return;
        } else {
            headerValue = exportFacetValue(context, component);
        }

        PdfPCell cell = new PdfPCell(new Paragraph((headerValue), this.facetFont));
        if (facetBackground != null) {
            cell.setBackgroundColor(facetBackground);
        }

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);

        // addColumnAlignments(component,cell);
        cell.setColspan(columnCount);
        pdfTable.addCell(cell);
        pdfTable.completeRow();
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableColumnGroup(PdfPTable pdfTable, DataTable table, String facetType) {
    ColumnGroup cg = table.getColumnGroup(facetType);
    List<UIComponent> headerComponentList = null;
    if (cg != null) {
        headerComponentList = cg.getChildren();
    }/*  w  w  w .j av  a2  s.c o  m*/

    if (headerComponentList != null) {
        for (UIComponent component : headerComponentList) {
            if (component instanceof Row) {
                Row row = (Row) component;
                for (UIComponent rowComponent : row.getChildren()) {
                    UIColumn column = (UIColumn) rowComponent;
                    String value = null;
                    if (facetType.equalsIgnoreCase("header")) {
                        value = column.getHeaderText();
                    } else {
                        value = column.getFooterText();
                    }

                    int rowSpan = column.getRowspan();
                    int colSpan = column.getColspan();
                    PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont));
                    if (facetBackground != null) {
                        cell.setBackgroundColor(facetBackground);
                    }

                    if (rowSpan > 1) {
                        cell.setVerticalAlignment(Element.ALIGN_CENTER);
                        cell.setRowspan(rowSpan);
                    }

                    if (colSpan > 1) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setColspan(colSpan);
                    }

                    // addColumnAlignments(component,cell);
                    if (facetType.equalsIgnoreCase("header")) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    }

                    pdfTable.addCell(cell);
                }
            }
        }
    }

    pdfTable.completeRow();
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void tableColumnGroup(PdfPTable pdfTable, SubTable table, String facetType) {
    ColumnGroup cg = table.getColumnGroup(facetType);
    List<UIComponent> headerComponentList = null;
    if (cg != null) {
        headerComponentList = cg.getChildren();
    }/* w  ww.j  a va  2 s  .  co m*/

    if (headerComponentList != null) {
        for (UIComponent component : headerComponentList) {
            if (component instanceof Row) {
                Row row = (Row) component;
                for (UIComponent rowComponent : row.getChildren()) {
                    UIColumn column = (UIColumn) rowComponent;
                    String value = null;
                    if (facetType.equalsIgnoreCase("header")) {
                        value = column.getHeaderText();
                    } else {
                        value = column.getFooterText();
                    }

                    int rowSpan = column.getRowspan();
                    int colSpan = column.getColspan();
                    PdfPCell cell = new PdfPCell(new Paragraph(value, this.facetFont));
                    if (facetBackground != null) {
                        cell.setBackgroundColor(facetBackground);
                    }

                    if (rowSpan > 1) {
                        cell.setVerticalAlignment(Element.ALIGN_CENTER);
                        cell.setRowspan(rowSpan);
                    }

                    if (colSpan > 1) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                        cell.setColspan(colSpan);
                    }

                    // addColumnAlignments(component,cell);
                    if (facetType.equalsIgnoreCase("header")) {
                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    }

                    pdfTable.addCell(cell);
                }
            }
        }
    }

    pdfTable.completeRow();
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void exportRow(DataTable table, PdfPTable pdfTable, int rowIndex) {
    table.setRowIndex(rowIndex);//from  ww w .java2  s  . c om

    if (!table.isRowAvailable()) {
        return;
    }

    exportCells(table, pdfTable, rowIndex);
    SummaryRow sr = table.getSummaryRow();

    if (sr != null && sr.isInView()) {
        for (UIComponent summaryComponent : sr.getChildren()) {
            UIColumn column = (UIColumn) summaryComponent;
            StringBuilder builder = new StringBuilder();

            for (UIComponent component : column.getChildren()) {
                if (component.isRendered()) {
                    String value = exportValue(FacesContext.getCurrentInstance(), component);

                    if (value != null) {
                        builder.append(value);
                    }
                }
            }

            int rowSpan = column.getRowspan();
            int colSpan = column.getColspan();
            PdfPCell cell = new PdfPCell(new Paragraph(builder.toString(), this.facetFont));
            if (facetBackground != null) {
                cell.setBackgroundColor(facetBackground);
            }

            if (rowSpan > 1) {
                cell.setVerticalAlignment(Element.ALIGN_CENTER);
                cell.setRowspan(rowSpan);
            }

            if (colSpan > 1) {
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(colSpan);
            }

            pdfTable.addCell(cell);
        }
    }
}

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);
            }/*  w  w w  .  j  a  v  a  2 s  . 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:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void addColumnFacets(DataTable table, PdfPTable pdfTable, ColumnType columnType) {
    for (UIColumn col : table.getColumns()) {
        if (!col.isRendered()) {
            continue;
        }/*from   www.  j a v  a2s  .c om*/

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyModel();
        }

        PdfPCell cell = null;
        if (col.isExportable()) {
            if (col.getHeaderText() != null && columnType.name().equalsIgnoreCase("header")) {
                cell = new PdfPCell(new Paragraph(col.getHeaderText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }

                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfTable.addCell(cell);
            } else if (col.getFooterText() != null && columnType.name().equalsIgnoreCase("footer")) {
                cell = new PdfPCell(new Paragraph(col.getFooterText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }

                pdfTable.addCell(cell);
            } else {
                UIComponent component = (UIComponent) col;

                //Adding RowIndex for Custom Exporter
                if (component.getId().equalsIgnoreCase("subject")) {
                    String value = "Index";
                    PdfPCell cellIndex = new PdfPCell(new Paragraph(value));
                    //addColumnAlignments(component, cell);

                    if (facetBackground != null) {
                        cellIndex.setBackgroundColor(facetBackground);
                    }

                    cellIndex.setHorizontalAlignment(Element.ALIGN_CENTER);

                    pdfTable.addCell(cellIndex);
                }

                addColumnValue(pdfTable, col.getFacet(columnType.facet()), this.facetFont, columnType.name());
            }
        }
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void addColumnFacets(SubTable table, PdfPTable pdfTable, ColumnType columnType) {
    for (UIColumn col : table.getColumns()) {
        if (!col.isRendered()) {
            continue;
        }/*  w  w  w .j a v  a2s . c o  m*/

        if (col instanceof DynamicColumn) {
            ((DynamicColumn) col).applyModel();
        }

        PdfPCell cell = null;
        if (col.isExportable()) {
            if (col.getHeaderText() != null && columnType.name().equalsIgnoreCase("header")) {
                cell = new PdfPCell(new Paragraph(col.getHeaderText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }

                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                pdfTable.addCell(cell);
            } else if (col.getFooterText() != null && columnType.name().equalsIgnoreCase("footer")) {
                cell = new PdfPCell(new Paragraph(col.getFooterText(), this.facetFont));
                if (facetBackground != null) {
                    cell.setBackgroundColor(facetBackground);
                }

                pdfTable.addCell(cell);
            } else {
                addColumnValue(pdfTable, col.getFacet(columnType.facet()), this.facetFont, columnType.name());
            }
        }
    }
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void addColumnValue(PdfPTable pdfTable, UIComponent component, Font font, String columnType) {
    String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component);
    PdfPCell cell = new PdfPCell(new Paragraph(value, font));
    //addColumnAlignments(component, cell);

    if (facetBackground != null) {
        cell.setBackgroundColor(facetBackground);
    }/*  ww w .j  a  v  a  2 s . com*/

    if (columnType.equalsIgnoreCase("header")) {
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    }

    pdfTable.addCell(cell);
}

From source file:com.crm.webapp.util.PDFCustomExporter.java

License:Apache License

protected void addColumnValue(PdfPTable pdfTable, List<UIComponent> components, Font font, String columnType) {
    StringBuilder builder = new StringBuilder();

    for (UIComponent component : components) {
        if (component.isRendered()) {
            String value = exportValue(FacesContext.getCurrentInstance(), component);

            if (value != null) {
                builder.append(value);/*from www  .ja v  a 2  s .  c o m*/
            }
        }
    }

    PdfPCell cell = new PdfPCell(new Paragraph(builder.toString(), font));

    //addColumnAlignments(components, cell);
    if (columnType.equalsIgnoreCase("header")) {
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    }

    pdfTable.addCell(cell);
}