Example usage for com.lowagie.text.pdf PdfPTable setTableEvent

List of usage examples for com.lowagie.text.pdf PdfPTable setTableEvent

Introduction

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

Prototype

public void setTableEvent(PdfPTableEvent event) 

Source Link

Document

Sets the table event for this table.

Usage

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

@Override
protected void buildPdfContent(final Document document, final Entity entity, final Locale locale)
        throws DocumentException {
    String documentTitle = translationService.translate("costCalculation.costCalculationDetails.report.title",
            locale);//from  w w  w .ja va  2 s . com
    String documentAuthor = translationService.translate("qcadooReport.commons.generatedBy.label", locale);

    pdfHelper.addDocumentHeader(document, "", documentTitle, documentAuthor, new Date());

    DataDefinition dataDefCostCalculation = dataDefinitionService
            .get(CostCalculationConstants.PLUGIN_IDENTIFIER, CostCalculationConstants.MODEL_COST_CALCULATION);
    Entity costCalculation = dataDefCostCalculation.find("where id = " + entity.getId().toString())
            .uniqueResult();

    PdfPTable leftPanelColumn = addLeftPanelToReport(costCalculation, locale);

    PdfPTable rightPanelColumn = addRightPanelToReport(costCalculation, locale);

    PdfPTable panelTable = pdfHelper.createPanelTable(2);

    panelTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    panelTable.addCell(leftPanelColumn);
    panelTable.addCell(rightPanelColumn);
    panelTable.setSpacingAfter(20);
    panelTable.setSpacingBefore(20);

    panelTable.setTableEvent(null);
    panelTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    document.add(panelTable);

    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph", locale),
            FontUtils.getDejavuBold11Dark()));
    PdfPTable materialsTable = addMaterialsTable(costCalculation, locale);
    document.add(materialsTable);

    document.add(Chunk.NEWLINE);
    document.add(new Paragraph(
            translationService.translate("costCalculation.costCalculationDetails.report.paragraph2", locale),
            FontUtils.getDejavuBold11Dark()));

    CalculateOperationCostMode calculateOperationCostMode = CalculateOperationCostMode
            .parseString(costCalculation.getStringField(CostCalculationFields.CALCULATE_OPERATION_COSTS_MODE));

    if (CalculateOperationCostMode.HOURLY.equals(calculateOperationCostMode)) {
        document.add(addHourlyCostsTable(costCalculation, locale));
    } else if (CalculateOperationCostMode.PIECEWORK.equals(calculateOperationCostMode)) {
        document.add(addTableAboutPieceworkCost(costCalculation, locale));
    } else {
        throw new IllegalStateException("Unsupported CalculateOperationCostMode");
    }

    printMaterialAndOperationNorms(document, costCalculation, locale);
}

From source file:com.qcadoo.mes.costCalculation.print.CostCalculationPdfService.java

License:Open Source License

public void addOptionTablePrintOperationNormsHourly(final Document document, final Entity costCalculation,
        final Locale locale) throws DocumentException {
    List<String> optionTableHeader = Lists.newArrayList();

    for (String translate : Arrays.asList(
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER,
            L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NAME)) {
        optionTableHeader.add(translationService.translate(translate, locale));
    }/*  w w  w .j a  va2s  . c  o m*/

    List<Entity> calculationOperationComponents = entityTreeUtilsService.getSortedEntities(
            costCalculation.getTreeField(CostCalculationFields.CALCULATION_OPERATION_COMPONENTS));

    for (Entity calculationOperationComponent : calculationOperationComponents) {
        PdfPTable panelTableHeader = pdfHelper.createPanelTable(2);
        PdfPTable panelTableContent = pdfHelper.createPanelTable(2);
        panelTableHeader.setSpacingBefore(10);
        panelTableContent.getDefaultCell().setBackgroundColor(null);
        panelTableContent.setTableEvent(null);

        Entity technologyOperationComponent = calculationOperationComponent
                .getBelongsToField(CalculationOperationComponentFields.TECHNOLOGY_OPERATION_COMPONENT);
        Entity operation = calculationOperationComponent
                .getBelongsToField(CalculationOperationComponentFields.OPERATION);

        panelTableHeader
                .addCell(new Phrase(
                        translationService.translate(
                                L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NUMBER, locale)
                                + ": " + operation.getStringField(OperationFields.NUMBER),
                        FontUtils.getDejavuRegular7Dark()));

        panelTableHeader
                .addCell(new Phrase(
                        translationService.translate(
                                L_COST_CALCULATION_COST_CALCULATION_DETAILS_REPORT_COLUMN_HEADER_NAME, locale)
                                + ": " + operation.getStringField(OperationFields.NAME),
                        FontUtils.getDejavuRegular7Dark()));

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.productionSetUpTime.label",
                        locale) + ":",
                timeConverterService.convertTimeToString(technologyOperationComponent
                        .getIntegerField(TechnologyOperationComponentFieldsTNFO.TPZ)) + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.machineUtilization.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsTNFO.MACHINE_UTILIZATION)));

        addTableCellAsTwoColumnsTable(panelTableContent, translationService.translate(
                "costCalculation.costCalculationDetails.report.columnHeader.productionTimeForOneCycle.label",
                locale) + ":",
                timeConverterService.convertTimeToString(
                        technologyOperationComponent.getIntegerField(TechnologyOperationComponentFieldsTNFO.TJ))
                        + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.laborUtilization.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsTNFO.LABOR_UTILIZATION)));

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.additionalTime.label",
                        locale) + ":",
                timeConverterService
                        .convertTimeToString(technologyOperationComponent
                                .getIntegerField(TechnologyOperationComponentFieldsTNFO.TIME_NEXT_OPERATION))
                        + " (g:m:s)");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.machineHourlyCost.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsCNFO.MACHINE_HOURLY_COST)));

        addTableCellAsTwoColumnsTable(panelTableContent, "", "");

        addTableCellAsTwoColumnsTable(panelTableContent,
                translationService.translate(
                        "costCalculation.costCalculationDetails.report.columnHeader.laborHourlyCost.label",
                        locale) + ":",
                numberService.format(technologyOperationComponent
                        .getDecimalField(TechnologyOperationComponentFieldsCNFO.LABOR_HOURLY_COST)));

        document.add(panelTableHeader);
        document.add(panelTableContent);
    }
}

From source file:com.qcadoo.mes.productionCountingWithCosts.pdf.ProductionBalanceWithCostsPdfService.java

License:Open Source License

public PdfPTable createParametersForCostsPanel(final Entity productionBalance, final Locale locale) {
    PdfPTable parametersForCostsPanel = pdfHelper.createPanelTable(1);

    parametersForCostsPanel.addCell(new Phrase(translationService
            .translate("productionCounting.productionBalance.report.panel.parametersForCosts", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    PdfPTable content = pdfHelper.createPanelTable(2);
    content.setTableEvent(null);

    String sourceOfMaterialCostsField = productionBalance
            .getStringField(ProductionBalanceFieldsPCWC.SOURCE_OF_MATERIAL_COSTS);
    String sourceOfMaterialCosts = translationService.translate(
            "productionCounting.productionBalance.sourceOfMaterialCosts.value." + sourceOfMaterialCostsField,
            locale);/*from   w  w  w  .j  a v  a 2  s .c  o m*/
    pdfHelper.addTableCellAsTable(content,
            translationService.translate("productionCounting.productionBalance.sourceOfMaterialCosts.label",
                    locale),
            sourceOfMaterialCosts, FontUtils.getDejavuBold9Dark(), FontUtils.getDejavuRegular7Dark(), 2);

    String calculateMaterialCostsModeField = productionBalance
            .getStringField(ProductionBalanceFieldsPCWC.CALCULATE_MATERIAL_COSTS_MODE);
    String calculateMaterialCostsMode = translationService
            .translate("productionCounting.productionBalance.calculateMaterialCostsMode.value."
                    + calculateMaterialCostsModeField, locale);
    pdfHelper.addTableCellAsTable(content,
            translationService
                    .translate("productionCounting.productionBalance.calculateMaterialCostsMode.label", locale),
            calculateMaterialCostsMode, FontUtils.getDejavuBold9Dark(), FontUtils.getDejavuRegular7Dark(), 2);

    parametersForCostsPanel.addCell(content);

    return parametersForCostsPanel;
}

From source file:com.qcadoo.mes.productionCountingWithCosts.pdf.ProductionBalanceWithCostsPdfService.java

License:Open Source License

private PdfPTable createAssumptionsForCumulatedRecordsPanel(final Entity productionBalance,
        final Locale locale) {
    PdfPTable parametersForCostsPanel = pdfHelper.createPanelTable(1);

    parametersForCostsPanel.addCell(new Phrase(translationService.translate(
            "productionCounting.productionBalance.report.panel.assumptionsForCumulatedRecords", locale) + ":",
            FontUtils.getDejavuBold10Dark()));

    PdfPTable content = pdfHelper.createPanelTable(2);
    content.setTableEvent(null);

    BigDecimal averageMachineHourlyCost = productionBalance
            .getDecimalField(ProductionBalanceFieldsPCWC.AVERAGE_MACHINE_HOURLY_COST);
    String averageMachineHourlyCostLabel = translationService
            .translate("productionCounting.productionBalance.averageMachineHourlyCost.label", locale);
    pdfHelper.addTableCellAsTable(content, averageMachineHourlyCostLabel,
            numberService.format(averageMachineHourlyCost), FontUtils.getDejavuBold9Dark(),
            FontUtils.getDejavuRegular7Dark(), 2);

    BigDecimal averageLaborHourlyCost = productionBalance
            .getDecimalField(ProductionBalanceFieldsPCWC.AVERAGE_LABOR_HOURLY_COST);
    String averageLaborHourlyCostLabel = translationService
            .translate("productionCounting.productionBalance.averageLaborHourlyCost.label", locale);
    pdfHelper.addTableCellAsTable(content, averageLaborHourlyCostLabel,
            numberService.format(averageLaborHourlyCost), FontUtils.getDejavuBold9Dark(),
            FontUtils.getDejavuRegular7Dark(), 2);

    parametersForCostsPanel.addCell(content);

    return parametersForCostsPanel;
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addWorkPlanTitle(Document document, Entity workPlan, String title, Locale locale)
        throws DocumentException {

    PdfPTable headerTable = pdfHelper.createPanelTable(2);

    PdfPCell titleCell = new PdfPCell();
    titleCell.setBorder(Rectangle.NO_BORDER);
    Paragraph workPlanTitle = new Paragraph(
            new Phrase(getWorkPlanTitle(locale), FontUtils.getDejavuBold11Light()));
    workPlanTitle.add(new Phrase(" " + getWorkPlanName(workPlan), FontUtils.getDejavuBold11Dark()));
    titleCell.addElement(workPlanTitle);

    PdfPCell divisionCell = new PdfPCell();
    divisionCell.setBorder(Rectangle.NO_BORDER);
    Paragraph divisionTitle = new Paragraph(
            new Phrase(getDivisionTitle(locale), FontUtils.getDejavuBold11Light()));
    divisionTitle.add(new Phrase(" " + getDivisionFromTitle(title, locale), FontUtils.getDejavuBold11Dark()));
    divisionTitle.setAlignment(Element.ALIGN_RIGHT);
    divisionCell.addElement(divisionTitle);

    headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    headerTable.setTableEvent(null);
    headerTable.setSpacingAfter(4.0f);//www .j a  v a 2s. c o  m
    headerTable.addCell(titleCell);
    headerTable.addCell(divisionCell);
    document.add(headerTable);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOperationTable(PdfWriter pdfWriter, GroupingContainer groupingContainer, Document document,
        OrderOperationComponent orderOperationComponent, Locale locale) throws DocumentException {

    Map<Long, Map<OperationProductColumn, ColumnAlignment>> outputProductsMap = groupingContainer
            .getOperationComponentIdProductOutColumnToAlignment();

    Map<Long, Map<OperationProductColumn, ColumnAlignment>> inputProductsMap = groupingContainer
            .getOperationComponentIdProductInColumnToAlignment();

    Entity operationComponent = orderOperationComponent.getOperationComponent();
    Entity order = orderOperationComponent.getOrder();
    Entity product = order.getBelongsToField(OrderFields.PRODUCT);

    Map<OperationProductColumn, ColumnAlignment> inputProductColumnAlignmentMap = inputProductsMap
            .get(operationComponent.getId());
    Map<OperationProductColumn, ColumnAlignment> outputProductColumnAlignmentMap = outputProductsMap
            .get(operationComponent.getId());

    PdfPTable table = pdfHelper.createPanelTable(3);

    PdfPCell headerCell = new PdfPCell();
    headerCell.setBorder(Rectangle.NO_BORDER);
    headerCell.setColspan(2);//w  ww  .  j  av a2  s .c o m

    PdfPCell inputCell = new PdfPCell();
    inputCell.setBorder(Rectangle.NO_BORDER);
    PdfPCell outputCell = new PdfPCell();
    outputCell.setBorder(Rectangle.NO_BORDER);
    PdfPCell codeCell = new PdfPCell();
    codeCell.setBorder(Rectangle.NO_BORDER);
    codeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    codeCell.setVerticalAlignment(Element.ALIGN_TOP);
    codeCell.setRowspan(2);

    // addOperationSummary(headerCell, operationComponent);

    addOrderSummary(headerCell, order, product, operationComponent);

    addOperationProductsTable(inputCell, operationProductInComponents(operationComponent, order),
            inputProductColumnAlignmentMap, ProductDirection.IN, locale);
    addOperationProductsTable(outputCell, operationProductOutComponents(operationComponent, order),
            outputProductColumnAlignmentMap, ProductDirection.OUT, locale);

    codeCell.addElement(createBarcode(pdfWriter, operationComponent));

    float[] tableColumnWidths = new float[] { 70f, 70f, 10f };
    table.setWidths(tableColumnWidths);
    table.setTableEvent(null);
    table.addCell(headerCell);
    table.addCell(codeCell);
    table.addCell(inputCell);
    table.addCell(outputCell);
    table.setKeepTogether(true);
    document.add(table);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOperationSummary(PdfPCell cell, Entity operationComponent) throws DocumentException {
    Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);

    PdfPTable operationTable = pdfHelper.createPanelTable(1);

    PdfPCell numberCell = new PdfPCell();
    numberCell.setBorder(Rectangle.NO_BORDER);
    Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - "
            + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark());
    numberCell.addElement(operationName);

    PdfPCell descriptionCell = new PdfPCell();
    descriptionCell.setBorder(Rectangle.NO_BORDER);
    String comment = operation.getStringField(OperationFields.COMMENT);
    Paragraph description = null;/*from   w w w.j av  a2s.co m*/
    if (!StringUtils.isEmpty(comment)) {
        description = new Paragraph(comment, FontUtils.getDejavuBold7Dark());
    }

    operationTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    operationTable.setTableEvent(null);
    operationTable.addCell(numberCell);
    if (description != null) {
        descriptionCell.addElement(description);
        operationTable.addCell(descriptionCell);
    } else {
        operationTable.addCell("");
    }
    cell.addElement(operationTable);
}

From source file:com.qcadoo.mes.workPlans.pdf.document.WorkPlanPdfForDivision.java

License:Open Source License

private void addOrderSummary(PdfPCell cell, Entity order, Entity product, Entity operationComponent)
        throws DocumentException {
    Entity operation = operationComponent.getBelongsToField(TechnologyOperationComponentFields.OPERATION);
    PdfPTable orderTable = pdfHelper.createPanelTable(3);
    PdfPCell operationCell = new PdfPCell();
    operationCell.setBorder(Rectangle.NO_BORDER);
    Paragraph operationName = new Paragraph(operation.getStringField(OperationFields.NUMBER) + " - "
            + operation.getStringField(OperationFields.NAME), FontUtils.getDejavuBold7Dark());
    operationCell.addElement(operationName);

    PdfPCell numberCell = new PdfPCell();
    numberCell.setBorder(Rectangle.NO_BORDER);
    Paragraph number = new Paragraph(order.getStringField(OrderFields.NUMBER), FontUtils.getDejavuBold7Dark());
    number.setAlignment(Element.ALIGN_RIGHT);
    numberCell.addElement(number);/* w w  w. j  av  a  2  s.  c  o  m*/

    PdfPCell quantityCell = new PdfPCell();
    quantityCell.setBorder(Rectangle.NO_BORDER);
    Paragraph quantity = new Paragraph(
            numberService.formatWithMinimumFractionDigits(order.getDecimalField(OrderFields.PLANNED_QUANTITY),
                    0) + " " + product.getStringField(ProductFields.UNIT),
            FontUtils.getDejavuBold7Dark());
    quantity.setAlignment(Element.ALIGN_CENTER);
    quantityCell.addElement(quantity);

    PdfPCell descriptionCell = new PdfPCell();
    descriptionCell.setBorder(Rectangle.NO_BORDER);
    descriptionCell.setColspan(3);
    String comment = operationComponent.getStringField(TechnologyOperationComponentFields.COMMENT);
    Paragraph description = null;
    if (!StringUtils.isEmpty(comment)) {
        description = new Paragraph(comment, FontUtils.getDejavuBold7Dark());
    }

    float[] tableColumnWidths = new float[] { 160f, 30f, 10f };
    orderTable.setWidths(tableColumnWidths);
    orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    orderTable.setTableEvent(null);
    orderTable.addCell(operationCell);
    orderTable.addCell(numberCell);
    orderTable.addCell(quantityCell);
    if (description != null) {
        descriptionCell.addElement(description);
        orderTable.addCell(descriptionCell);
    }
    cell.addElement(orderTable);
}

From source file:com.qcadoo.report.internal.PdfHelperImpl.java

License:Open Source License

@Override
public PdfPTable createPanelTable(final int column) {
    PdfPTable mainData = new PdfPTable(column);
    mainData.setWidthPercentage(100f);//from   ww  w .jav  a  2  s.c  o  m
    mainData.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    mainData.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP);
    mainData.getDefaultCell().setPadding(4.0f);
    mainData.setTableEvent(new TableBorderEvent());
    return mainData;
}

From source file:org.mapfish.print.PDFUtils.java

License:Open Source License

/**
 * When we have to do some custom drawing in a block that is layed out by
 * iText, we first give an empty table with the good dimensions to iText,
 * then iText will call a callback with the actual position. When that
 * happens, we use the given drawer to do the actual drawing.
 *//*from w  w  w .j  av a  2  s.  c o  m*/
public static PdfPTable createPlaceholderTable(double width, double height, double spacingAfter,
        ChunkDrawer drawer, HorizontalAlign align, PDFCustomBlocks customBlocks) {
    PdfPTable placeHolderTable = new PdfPTable(1);
    placeHolderTable.setLockedWidth(true);
    placeHolderTable.setTotalWidth((float) width);
    final PdfPCell placeHolderCell = new PdfPCell();
    placeHolderCell.setMinimumHeight((float) height);
    placeHolderCell.setPadding(0f);
    placeHolderCell.setBorder(PdfPCell.NO_BORDER);
    placeHolderTable.addCell(placeHolderCell);
    customBlocks.addChunkDrawer(drawer);
    placeHolderTable.setTableEvent(drawer);
    placeHolderTable.setComplete(true);

    final PdfPCell surroundingCell = new PdfPCell(placeHolderTable);
    surroundingCell.setPadding(0f);
    surroundingCell.setBorder(PdfPCell.NO_BORDER);
    if (align != null) {
        placeHolderTable.setHorizontalAlignment(align.getCode());
        surroundingCell.setHorizontalAlignment(align.getCode());
    }

    PdfPTable surroundingTable = new PdfPTable(1);
    surroundingTable.setSpacingAfter((float) spacingAfter);
    surroundingTable.addCell(surroundingCell);
    surroundingTable.setComplete(true);

    return surroundingTable;
}