Example usage for org.apache.poi.ss.usermodel Cell setCellStyle

List of usage examples for org.apache.poi.ss.usermodel Cell setCellStyle

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Cell setCellStyle.

Prototype

void setCellStyle(CellStyle style);

Source Link

Document

Set the style for the cell.

Usage

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

private void addLeveragingSheetHeader(Workbook p_workbook, Sheet p_sheet) throws Exception {
    int row = ROWNUMBER, column = 0;

    Row thirRow = getRow(p_sheet, row);/*from w  ww . ja va  2  s  .c om*/
    Cell cell_A = getCell(thirRow, column++);
    cell_A.setCellValue(bundle.getString("lb_lang"));
    cell_A.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_B = getCell(thirRow, column++);
    cell_B.setCellValue(bundle.getString("jobinfo.tradosmatches.invoice.per100matches"));
    cell_B.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_C = getCell(thirRow, column++);
    cell_C.setCellValue(bundle.getString("lb_95_99"));
    cell_C.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_D = getCell(thirRow, column++);
    cell_D.setCellValue(bundle.getString("lb_85_94"));
    cell_D.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_E = getCell(thirRow, column++);
    cell_E.setCellValue(bundle.getString("lb_75_84"));
    cell_E.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_F = getCell(thirRow, column++);
    cell_F.setCellValue(bundle.getString("lb_no_match"));
    cell_F.setCellStyle(getHeaderOrangeStyle(p_workbook));

    p_sheet.setColumnWidth(column, 10 * 256);
    Cell cell_G = getCell(thirRow, column++);
    cell_G.setCellValue(bundle.getString("lb_repetition_word_cnt"));
    cell_G.setCellStyle(getHeaderOrangeStyle(p_workbook));

    if (headers[0] != null) {
        p_sheet.setColumnWidth(column, 10 * 256);
        Cell cell_InContext = getCell(thirRow, column++);
        cell_InContext.setCellValue(bundle.getString("lb_in_context_tm"));
        cell_InContext.setCellStyle(getHeaderOrangeStyle(p_workbook));
    }
    if (headers[1] != null) {
        p_sheet.setColumnWidth(column, 10 * 256);
        Cell cell_Context = getCell(thirRow, column++);
        cell_Context.setCellValue(bundle.getString("lb_context_matches"));
        cell_Context.setCellStyle(getHeaderOrangeStyle(p_workbook));
    }

    Cell cell_Total = getCell(thirRow, column++);
    cell_Total.setCellValue(bundle.getString("lb_total"));
    cell_Total.setCellStyle(getHeaderOrangeStyle(p_workbook));

    p_sheet.setColumnWidth(column, 13 * 256);
    Cell cell_Leveraging = getCell(thirRow, column++);
    cell_Leveraging.setCellValue(bundle.getString("lb_leveraging"));
    cell_Leveraging.setCellStyle(getHeaderOrangeStyle(p_workbook));
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

private void addLeveragingSheetData(Workbook p_workbook, Sheet p_sheet,
        Map<String, ReportWordCount> p_wordCounts) throws Exception {
    // Prepare report data
    Map<String, ReportWordCount> sumWordCounts = new HashMap<String, ReportWordCount>();
    for (String key : p_wordCounts.keySet()) {
        ReportWordCount monthWordCount = p_wordCounts.get(key);
        String sumKey = key.substring(0, 5);
        ReportWordCount sumWordCount = sumWordCounts.get(sumKey);
        if (sumWordCount == null) {
            sumWordCounts.put(sumKey, monthWordCount.clone());
        } else {/*from   w ww. ja  v a2s.c  om*/
            sumWordCount.addTradosWordCount(monthWordCount);
        }
    }

    // Display report data.
    int row = ROWNUMBER + 1;
    int column = 0;
    List<String> sumKeyList = new ArrayList<String>(sumWordCounts.keySet());
    SortUtil.sort(sumKeyList);
    for (String sumKey : sumKeyList) {
        ReportWordCount sumWordCount = sumWordCounts.get(sumKey);
        if (sumWordCount != null) {
            Cell cell_A_Lang = getCell(getRow(p_sheet, row), column++);
            cell_A_Lang.setCellValue(sumKey);
            cell_A_Lang.setCellStyle(getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row, sumWordCount.getTrados100WordCount(),
                    getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row, sumWordCount.getTrados95to99WordCount(),
                    getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row, sumWordCount.getTrados85to94WordCount(),
                    getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row, sumWordCount.getTrados75to84WordCount(),
                    getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row,
                    sumWordCount.getTradosNoMatchWordCount() + sumWordCount.getTrados50to74WordCount(),
                    getHeaderStyle(p_workbook));

            addNumberCell(p_sheet, column++, row, sumWordCount.getTradosRepsWordCount(),
                    getHeaderStyle(p_workbook));

            if (headers[0] != null) {
                addNumberCell(p_sheet, column++, row, sumWordCount.getTradosInContextMatchWordCount(),
                        getHeaderStyle(p_workbook));
            }
            if (headers[1] != null) {
                addNumberCell(p_sheet, column++, row, sumWordCount.getTradosContextMatchWordCount(),
                        getHeaderStyle(p_workbook));
            }

            addNumberCell(p_sheet, column++, row, sumWordCount.getTradosTotalWordCount(),
                    getHeaderStyle(p_workbook));
            String leveraging = "(1-F" + (row + 1) + "/" + getColumnName(column - 1) + (row + 1) + ")*100";

            Cell cell_TotalLeveraging = getCell(getRow(p_sheet, row), column++);
            cell_TotalLeveraging.setCellFormula(leveraging);
            cell_TotalLeveraging.setCellStyle(getFloatStyle(p_workbook));

            row++;
            column = 0;
        }
    }

    addLeveragingSheetTotal(p_workbook, p_sheet, row);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

private void addLeveragingSheetTotal(Workbook p_workbook, Sheet p_sheet, int row) throws Exception {
    // Total Row/* w  w w  .  j  a  v  a 2  s  .c  o m*/
    if (row > (ROWNUMBER + 1)) {
        int column = 0;
        Cell cell_GrandTotal = getCell(getRow(p_sheet, row), column++);
        cell_GrandTotal.setCellValue(bundle.getString("lb_grandTotal"));
        cell_GrandTotal.setCellStyle(getHeaderOrangeStyle(p_workbook));
        while (column < (p_sheet.getRow(row - 1).getPhysicalNumberOfCells() - 1)) {
            Cell totalCell = getCell(getRow(p_sheet, row), column);
            totalCell.setCellFormula(getSumOfColumn(ROWNUMBER + 1, row - 1, column));
            totalCell.setCellStyle(getHeaderOrangeStyle(p_workbook));
            column++;
        }
        String leveraging = "(1-F" + (row + 1) + "/" + getColumnName(column - 1) + (row + 1) + ")*100";

        Cell cell_TotalLeveraging = getCell(getRow(p_sheet, row), column++);
        cell_TotalLeveraging.setCellFormula(leveraging);
        cell_TotalLeveraging.setCellStyle(getFloatSumStyle(p_workbook));
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

/**
 * Creates Leveraging Sheet/*  w  w  w  . j av a2s . co  m*/
 */
private void createCostsSheet(Workbook p_workbook, Sheet p_sheet, ReportSearchOptions p_options,
        Map<String, ReportWordCount> p_wordCounts) throws Exception {
    int rowLen = p_sheet.getPhysicalNumberOfRows();
    int colLen = p_sheet.getRow(2).getPhysicalNumberOfCells();
    int wordTotalCol = colLen - 2;
    int row = ROWNUMBER, column = colLen - 1;
    int costCol;
    Map<String, Double> p_ratesMap = null;
    for (int r = 2; r < rowLen + ROWNUMBER; r++) {
        Row theRow = getRow(p_sheet, r);
        theRow.removeCell(getCell(theRow, column));
    }
    p_sheet.removeColumnBreak(column);
    // Rates Columns
    for (int dis = column - 1; column < colLen + dis - 2; column++) {
        Cell cell_From = p_sheet.getRow(row).getCell(column - dis);
        Cell cell_To = getCell(p_sheet.getRow(row), column);
        cell_To.setCellValue(cell_From.getStringCellValue());
        cell_To.setCellStyle(cell_From.getCellStyle());
        p_sheet.setColumnWidth(column, p_sheet.getColumnWidth(column - dis));
        // Adds Rates for Match Type
        for (int rateRow = row + 1; rateRow <= rowLen; rateRow++) {
            String matchType = p_sheet.getRow(ROWNUMBER).getCell(column).getStringCellValue();
            String targetLocale = p_sheet.getRow(rateRow).getCell(0).getStringCellValue();
            double rate = getRate(matchType, targetLocale, p_ratesMap);
            addNumberCell(p_sheet, column, rateRow, rate, getMoneyStyle(p_workbook));
        }
    }

    // Cost Columns Head
    costCol = column;
    p_sheet.setColumnWidth(column, 20 * 256);
    Cell cell_CostWithLeveraging = getCell(getRow(p_sheet, row), column++);
    cell_CostWithLeveraging.setCellValue(bundle.getString("lb_report_costWithLeveraging"));
    cell_CostWithLeveraging.setCellStyle(getHeaderOrangeStyle(p_workbook));

    p_sheet.setColumnWidth(column, 20 * 256);
    Cell cell_CostNoLeveraging = getCell(getRow(p_sheet, row), column++);
    cell_CostNoLeveraging.setCellValue(bundle.getString("lb_report_costNoLeveraging"));
    cell_CostNoLeveraging.setCellStyle(getHeaderOrangeStyle(p_workbook));

    p_sheet.setColumnWidth(column, 15 * 256);
    Cell cell_Savings = getCell(getRow(p_sheet, row), column++);
    cell_Savings.setCellValue(bundle.getString("lb_savings"));
    cell_Savings.setCellStyle(getHeaderOrangeStyle(p_workbook));

    Cell cell_Percent = getCell(getRow(p_sheet, row), column++);
    cell_Percent.setCellValue("%");
    cell_Percent.setCellStyle(getHeaderOrangeStyle(p_workbook));
    // Cost Columns Data
    for (row = ROWNUMBER + 1; row < (rowLen + ROWNUMBER); row++) {
        String leveragingForm = getCostWithLeveraging(1, wordTotalCol - 1, wordTotalCol, (row + 1));
        String noLeveragingForm = getColumnName(wordTotalCol) + (row + 1) + "*"
                + getColumnName(wordTotalCol + 5) + (row + 1);
        String savingForm = getColumnName(costCol + 1) + (row + 1) + "-" + getColumnName(costCol) + (row + 1);
        String percent = getColumnName(costCol + 2) + (row + 1) + "/" + getColumnName(costCol + 1) + (row + 1);

        Row theRow = getRow(p_sheet, row);
        Cell cell_Leveraging = getCell(theRow, costCol);
        cell_Leveraging.setCellFormula(leveragingForm);
        cell_Leveraging.setCellStyle(getMoneyStyle(p_workbook));

        Cell cell_NoLeveraging = getCell(theRow, costCol + 1);
        cell_NoLeveraging.setCellFormula(noLeveragingForm);
        cell_NoLeveraging.setCellStyle(getMoneyStyle(p_workbook));

        Cell cell_Saving = getCell(theRow, costCol + 2);
        cell_Saving.setCellFormula(savingForm);
        cell_Saving.setCellStyle(getMoneyStyle(p_workbook));

        Cell cell_PercentData = getCell(theRow, costCol + 3);
        cell_PercentData.setCellFormula(percent);
        cell_PercentData.setCellStyle(getPercentStyle(p_workbook));
    }

    if (rowLen > 1) {
        row = rowLen + 1;
        column = 1;
        for (; column < colLen - 1; column++) {
            Cell cell_Total = getCell(getRow(p_sheet, row), column);
            cell_Total.setCellFormula(getSumOfColumn(ROWNUMBER + 1, row - 1, column));
            cell_Total.setCellStyle(getHeaderOrangeStyle(p_workbook));
        }
        for (; column < costCol; column++) {
            Cell cell = getCell(getRow(p_sheet, row), column);
            cell.setCellValue("");
            cell.setCellStyle(getHeaderOrangeStyle(p_workbook));
        }

        // Summary Cost Columns
        Cell cell_SumLeveraging = getCell(getRow(p_sheet, row), column);
        cell_SumLeveraging.setCellFormula(getSumOfColumn(ROWNUMBER + 1, row - 1, column++));
        cell_SumLeveraging.setCellStyle(getMoneySumStyle(p_workbook));

        Cell cell_SumNoLeveraging = getCell(getRow(p_sheet, row), column);
        cell_SumNoLeveraging.setCellFormula(getSumOfColumn(ROWNUMBER + 1, row - 1, column++));
        cell_SumNoLeveraging.setCellStyle(getMoneySumStyle(p_workbook));

        Cell cell_SumSaving = getCell(getRow(p_sheet, row), column);
        cell_SumSaving.setCellFormula(getSumOfColumn(ROWNUMBER + 1, row - 1, column++));
        cell_SumSaving.setCellStyle(getMoneySumStyle(p_workbook));

        String percent = getColumnName(column - 1) + (row + 1) + "/" + getColumnName(column - 2) + (row + 1);
        Cell cell_AvgPercent = getCell(getRow(p_sheet, row), column);
        cell_AvgPercent.setCellFormula(percent);
        cell_AvgPercent.setCellStyle(getPercentSumStyle(p_workbook));
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

private void createCriteriaSheet(Workbook p_workbook, Sheet p_sheet, ReportSearchOptions p_options,
        Map<String, ReportWordCount> p_wordCounts) throws Exception {
    StringBuffer temp = new StringBuffer();
    int row = -1;
    String mark = ": ";
    p_sheet.setColumnWidth(0, 20 * 256);
    p_sheet.setColumnWidth(1, 50 * 256);
    Cell cell_A_Title = getCell(getRow(p_sheet, ++row), 0);
    cell_A_Title.setCellValue(bundle.getString("lb_report_criteria"));
    cell_A_Title.setCellStyle(getContentStyle(p_workbook));

    Cell cell_CompanyName = getCell(getRow(p_sheet, ++row), 0);
    cell_CompanyName.setCellValue(bundle.getString("lb_company_name") + mark);
    cell_CompanyName.setCellStyle(getContentStyle(p_workbook));

    Cell cell_CompanyNameData = getCell(getRow(p_sheet, row), 1);
    cell_CompanyNameData.setCellValue(p_options.getCurrentCompanyName());
    cell_CompanyNameData.setCellStyle(getContentStyle(p_workbook));

    Cell cell_StartDate = getCell(getRow(p_sheet, ++row), 0);
    cell_StartDate.setCellValue(bundle.getString("lb_report_startDate") + mark);
    cell_StartDate.setCellStyle(getContentStyle(p_workbook));

    Cell cell_StartDateData = getCell(getRow(p_sheet, row), 1);
    cell_StartDateData.setCellValue(p_options.getStartDateStr());
    cell_StartDateData.setCellStyle(getContentStyle(p_workbook));

    Cell cell_EndDate = getCell(getRow(p_sheet, ++row), 0);
    cell_EndDate.setCellValue(bundle.getString("lb_report_endDate") + mark);
    cell_EndDate.setCellStyle(getContentStyle(p_workbook));

    Cell cell_EndDateData = getCell(getRow(p_sheet, row), 1);
    cell_EndDateData.setCellValue(p_options.getEndDateStr());
    cell_EndDateData.setCellStyle(getContentStyle(p_workbook));

    // Project Search option
    Cell cell_Project = getCell(getRow(p_sheet, ++row), 0);
    cell_Project.setCellValue(bundle.getString("lb_project") + mark);
    cell_Project.setCellStyle(getContentStyle(p_workbook));
    if (p_options.isAllProjects()) {
        temp.setLength(0);//from   ww w  .j  ava 2  s . c o m
        temp.append(bundle.getString("lb_all"));
    } else {
        temp.setLength(0);
        for (long projectId : p_options.getProjectIdList()) {
            Project proj = ServerProxy.getProjectHandler().getProjectById(projectId);
            temp.append(proj.getName()).append(",");
        }
        temp = new StringBuffer(temp.substring(0, temp.length() - 1));
    }
    Cell cell_ProjectData = getCell(getRow(p_sheet, row), 1);
    cell_ProjectData.setCellValue(temp.toString());
    cell_ProjectData.setCellStyle(getContentStyle(p_workbook));

    // Status Search option
    Cell cell_Status = getCell(getRow(p_sheet, ++row), 0);
    cell_Status.setCellValue(bundle.getString("lb_status") + mark);
    cell_Status.setCellStyle(getContentStyle(p_workbook));
    if (p_options.isAllJobStatus()) {
        temp.setLength(0);
        temp.append(bundle.getString("lb_all"));
    } else {
        temp.setLength(0);
        for (String status : p_options.getJobStatusList()) {
            temp.append(ReportHelper.getJobStatusDisplayName(status)).append(",");
        }
        temp = new StringBuffer(temp.substring(0, temp.length() - 1));
    }
    Cell cell_StatusData = getCell(getRow(p_sheet, row), 1);
    cell_StatusData.setCellValue(temp.toString());
    cell_StatusData.setCellStyle(getContentStyle(p_workbook));

    // Target Locales Search option
    Cell cell_TargetLang = getCell(getRow(p_sheet, ++row), 0);
    cell_TargetLang.setCellValue(bundle.getString("lb_target_language") + mark);
    cell_TargetLang.setCellStyle(getContentStyle(p_workbook));
    if (p_options.isAllTargetLangs()) {

        temp.setLength(0);
        temp.append(bundle.getString("lb_all"));
    } else {
        temp.setLength(0);
        for (GlobalSightLocale gl : p_options.getTargetLocaleList()) {
            temp.append(gl.getDisplayName()).append(",");
        }
        temp = new StringBuffer(temp.substring(0, temp.length() - 1));
    }
    Cell cell_TargetLangData = getCell(getRow(p_sheet, row), 1);
    cell_TargetLangData.setCellValue(temp.toString());
    cell_TargetLangData.setCellStyle(getContentStyle(p_workbook));

    // Currency Search Option
    Cell cell_Currency = getCell(getRow(p_sheet, ++row), 0);
    cell_Currency.setCellValue(bundle.getString("lb_currency") + mark);
    cell_Currency.setCellStyle(getContentStyle(p_workbook));

    Cell cell_CurrencyData = getCell(getRow(p_sheet, row), 1);
    cell_CurrencyData.setCellValue(p_options.getCurrency());
    cell_CurrencyData.setCellStyle(getContentStyle(p_workbook));
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.SummaryReportGenerator.java

License:Apache License

private void addNumberCell(Sheet p_sheet, int p_column, int p_row, double p_value, CellStyle cs) {
    try {//from   w ww  .  j  a v  a  2 s  . c o  m
        Cell cell = getCell(getRow(p_sheet, p_row), p_column);
        cell.setCellValue(p_value);
        if (cs != null)
            cell.setCellStyle(cs);
    } catch (Exception e) {
        logger.warn("addNumberCell Error1.[" + p_sheet.getSheetName() + ", " + p_column + ", " + p_row + ", "
                + p_value + "]", e);
    }
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java

License:Apache License

/**
 * Add title to the sheet/*from w w  w.  ja va  2s  .  c om*/
 * 
 * @param p_workBook
 * @param p_sheet
 *            the sheet
 * @throws Exception
 */
private void addTitle(Workbook p_workBook, Sheet p_sheet) throws Exception {
    Font titleFont = p_workBook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    CellStyle cs = p_workBook.createCellStyle();
    cs.setFont(titleFont);

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(m_bundle.getString("lb_translation_edit_report"));
    titleCell.setCellStyle(cs);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java

License:Apache License

/**
 * Add hidden info "TER_taskID" for offline uploading. When upload, system
 * can know the report type and current task ID report generated from.
 * //from   w  w  w .ja  v  a  2  s  . c  om
 * @param p_workbook
 * @param p_sheet
 * @param p_job
 * @param p_targetLocale
 * @throws Exception
 */
private void addHidenInfoForUpload(Workbook p_workbook, Sheet p_sheet, Job p_job,
        GlobalSightLocale p_targetLocale) throws Exception {
    String reportInfo = "";
    for (Workflow wf : p_job.getWorkflows()) {
        if (p_targetLocale.getId() == wf.getTargetLocale().getId()) {
            Collection tasks = ServerProxy.getTaskManager().getCurrentTasks(wf.getId());
            if (tasks != null) {
                for (Iterator it = tasks.iterator(); it.hasNext();) {
                    Task task = (Task) it.next();
                    reportInfo = ReportConstants.TRANSLATIONS_EDIT_REPORT_ABBREVIATION + "_" + task.getId();
                }
            }
        }
    }

    Row titleRow = getRow(p_sheet, 0);
    Cell taskIdCell = getCell(titleRow, 26);
    taskIdCell.setCellValue(reportInfo);
    taskIdCell.setCellStyle(contentStyle);

    p_sheet.setColumnHidden(26, true);
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java

License:Apache License

/**
 * Add segment header to the sheet//  ww  w  . j a  v a 2  s .  com
 * 
 * @param p_workBook
 * @param p_sheet
 *            the sheet
 * @throws Exception
 */
private void addSegmentHeader(Workbook p_workBook, Sheet p_sheet) throws Exception {
    int col = 0;
    int row = SEGMENT_HEADER_ROW;
    Row segHeaderRow = getRow(p_sheet, row);

    Cell cell_A = getCell(segHeaderRow, col);
    cell_A.setCellValue(m_bundle.getString("lb_source_segment"));
    cell_A.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell cell_B = getCell(segHeaderRow, col);
    cell_B.setCellValue(m_bundle.getString("lb_target_segment"));
    cell_B.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell cell_C = getCell(segHeaderRow, col);
    cell_C.setCellValue(m_bundle.getString("lb_modify_the_translation"));
    cell_C.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 50 * 256);
    col++;

    Cell cell_D = getCell(segHeaderRow, col);
    cell_D.setCellValue(m_bundle.getString("latest_comments"));
    cell_D.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell cell_E = getCell(segHeaderRow, col);
    cell_E.setCellValue(m_bundle.getString("translation_comments"));
    cell_E.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell cell_F = getCell(segHeaderRow, col);
    cell_F.setCellValue(m_bundle.getString("lb_category_failure"));
    cell_F.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 40 * 256);
    col++;

    Cell cell_G = getCell(segHeaderRow, col);
    cell_G.setCellValue(m_bundle.getString("lb_comment_status"));
    cell_G.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    Cell cell_H = getCell(segHeaderRow, col);
    cell_H.setCellValue(m_bundle.getString("lb_tm_match_original"));
    cell_H.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 20 * 256);
    col++;

    Cell cell_I = getCell(segHeaderRow, col);
    cell_I.setCellValue(m_bundle.getString("lb_glossary_source"));
    cell_I.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 25 * 256);
    col++;

    Cell cell_J = getCell(segHeaderRow, col);
    cell_J.setCellValue(m_bundle.getString("lb_glossary_target"));
    cell_J.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 25 * 256);
    col++;

    Cell cell_K = getCell(segHeaderRow, col);
    cell_K.setCellValue(m_bundle.getString("lb_job_id_report"));
    cell_K.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    Cell cell_L = getCell(segHeaderRow, col);
    cell_L.setCellValue(m_bundle.getString("lb_segment_id"));
    cell_L.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;

    Cell cell_M = getCell(segHeaderRow, col);
    cell_M.setCellValue(m_bundle.getString("lb_page_name"));
    cell_M.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 25 * 256);
    col++;

    Cell cell_N = getCell(segHeaderRow, col);
    cell_N.setCellValue(m_bundle.getString("lb_sid"));
    cell_N.setCellStyle(getHeaderStyle(p_workBook));
    p_sheet.setColumnWidth(col, 15 * 256);
    col++;
}

From source file:com.globalsight.everest.webapp.pagehandler.administration.reports.generator.TranslationsEditReportGenerator.java

License:Apache License

/**
 * For Translations Edit Report, Write segment information into each row of
 * the sheet.//ww w .jav a 2 s  .  c om
 * 
 * @param p_sheet
 *            the sheet
 * @param p_jobId
 *            the job id
 * @param p_targetLang
 *            the target locale String
 * @param p_srcPageId
 *            the source page id
 * @param p_dateFormat
 *            the data format
 * @param p_row
 *            the segment row in sheet
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
private int writeSegmentInfo(Workbook p_workBook, Sheet p_sheet, Job p_job, GlobalSightLocale p_targetLocale,
        String p_srcPageId, String p_dateFormat, int p_row) throws Exception {
    Vector<TargetPage> targetPages = new Vector<TargetPage>();

    TranslationMemoryProfile tmp = null;
    Vector<String> excludItems = null;

    for (Workflow workflow : p_job.getWorkflows()) {
        if (cancel)
            return 0;

        if (Workflow.PENDING.equals(workflow.getState()) || Workflow.CANCELLED.equals(workflow.getState())
        // || Workflow.EXPORT_FAILED.equals(workflow.getState())
                || Workflow.IMPORT_FAILED.equals(workflow.getState())) {
            continue;
        }
        if (p_targetLocale.getId() == workflow.getTargetLocale().getId()) {
            targetPages = workflow.getTargetPages();
            tmp = workflow.getJob().getL10nProfile().getTranslationMemoryProfile();
            if (tmp != null) {
                excludItems = tmp.getJobExcludeTuTypes();
            }
        }
    }

    if (targetPages.isEmpty()) {
        // If no corresponding target page exists, set the cell blank
        writeBlank(p_sheet, p_row, 11);
    } else {
        LeverageMatchLingManager lmLingManager = LingServerProxy.getLeverageMatchLingManager();
        TermLeverageManager termLeverageManager = ServerProxy.getTermLeverageManager();

        Locale sourcePageLocale = p_job.getSourceLocale().getLocale();
        Locale targetPageLocale = p_targetLocale.getLocale();
        TermLeverageOptions termLeverageOptions = getTermLeverageOptions(sourcePageLocale, targetPageLocale,
                p_job.getL10nProfile().getProject().getTermbaseName(), String.valueOf(p_job.getCompanyId()));
        Map<Long, Set<TermLeverageMatch>> termLeverageMatchResultMap = null;
        if (termLeverageOptions != null) {
            termLeverageMatchResultMap = termLeverageManager.getTermMatchesForPages(p_job.getSourcePages(),
                    p_targetLocale);
        }

        String category = null;
        PseudoData pData = new PseudoData();
        pData.setMode(PseudoConstants.PSEUDO_COMPACT);
        String sid = null;
        Set<Integer> rowsWithCommentSet = new HashSet<Integer>();
        for (int i = 0; i < targetPages.size(); i++) {
            if (cancel)
                return 0;

            TargetPage targetPage = (TargetPage) targetPages.get(i);
            SourcePage sourcePage = targetPage.getSourcePage();

            if (!"".equals(p_srcPageId) && !p_srcPageId.equals(String.valueOf(sourcePage.getId()))) {
                // ignore the source pages not equal to the one
                // if the request comes from pop up editor
                continue;
            }

            SegmentTuUtil.getTusBySourcePageId(sourcePage.getId());
            List sourceTuvs = SegmentTuvUtil.getSourceTuvs(sourcePage);
            List targetTuvs = SegmentTuvUtil.getTargetTuvs(targetPage);

            MatchTypeStatistics tuvMatchTypes = lmLingManager.getMatchTypesForStatistics(
                    sourcePage.getIdAsLong(), targetPage.getLocaleId(), p_job.getLeverageMatchThreshold());
            Map<Long, Set<LeverageMatch>> fuzzyLeverageMatchMap = lmLingManager
                    .getFuzzyMatches(sourcePage.getIdAsLong(), new Long(targetPage.getLocaleId()));

            sourcePageLocale = sourcePage.getGlobalSightLocale().getLocale();
            targetPageLocale = targetPage.getGlobalSightLocale().getLocale();

            boolean m_rtlSourceLocale = EditUtil.isRTLLocale(sourcePageLocale.toString());
            boolean m_rtlTargetLocale = EditUtil.isRTLLocale(targetPageLocale.toString());

            // Find segment all comments belong to this target page
            Map<Long, IssueImpl> issuesMap = CommentHelper.getIssuesMap(targetPage.getId());

            for (int j = 0; j < targetTuvs.size(); j++) {
                if (cancel)
                    return 0;

                int col = 0;
                Tuv targetTuv = (Tuv) targetTuvs.get(j);
                Tuv sourceTuv = (Tuv) sourceTuvs.get(j);

                category = sourceTuv.getTu(p_job.getId()).getTuType();
                if (excludItems != null && excludItems.contains(category)) {
                    continue;
                }

                // Comment
                List issueHistories = null;
                String lastComment = "";
                String failure = "";
                String commentStatus = "";
                Issue issue = issuesMap.get(targetTuv.getId());
                if (issue != null) {
                    issueHistories = issue.getHistory();
                    failure = issue.getCategory();
                    commentStatus = issue.getStatus();
                }
                if (issueHistories != null && issueHistories.size() > 0) {
                    IssueHistory issueHistory = (IssueHistory) issueHistories.get(0);
                    lastComment = issueHistory.getComment();
                }

                sid = sourceTuv.getSid();

                StringBuilder matches = getMatches(fuzzyLeverageMatchMap, tuvMatchTypes, excludItems,
                        sourceTuvs, targetTuvs, sourceTuv, targetTuv, p_job.getId());

                // Get Terminology/Glossary Source and Target.
                String sourceTerms = "";
                String targetTerms = "";
                if (termLeverageMatchResultMap != null && termLeverageMatchResultMap.size() > 0) {
                    Set<TermLeverageMatch> termLeverageMatchSet = termLeverageMatchResultMap
                            .get(sourceTuv.getId());
                    if (termLeverageMatchSet != null && termLeverageMatchSet.size() > 0) {
                        TermLeverageMatch tlm = termLeverageMatchSet.iterator().next();
                        sourceTerms = tlm.getMatchedSourceTerm();
                        targetTerms = tlm.getMatchedTargetTerm();
                    }
                }

                Row currentRow = getRow(p_sheet, p_row);

                // Source segment with compact tags
                CellStyle srcStyle = m_rtlSourceLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_A = getCell(currentRow, col);
                cell_A.setCellValue(getSegment(pData, sourceTuv, m_rtlSourceLocale, p_job.getId()));
                cell_A.setCellStyle(srcStyle);
                col++;

                // Target segment with compact tags
                CellStyle trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook)
                        : getContentStyle(p_workBook);
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId()));
                cell_B.setCellStyle(trgStyle);
                col++;

                // Modify the translation
                CellStyle modifyTranslationStyle = m_rtlTargetLocale ? getUnlockedRightStyle(p_workBook)
                        : getUnlockedStyle(p_workBook);
                Cell cell_C = getCell(currentRow, col);
                cell_C.setCellValue("");
                cell_C.setCellStyle(modifyTranslationStyle);
                col++;

                //Reviewers Comments
                Cell cell_D = getCell(currentRow, col);
                cell_D.setCellValue(lastComment);
                cell_D.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Translators Comments
                Cell cell_E = getCell(currentRow, col);
                cell_E.setCellValue("");
                cell_E.setCellStyle(getUnlockedStyle(p_workBook));
                col++;

                // Category failure
                Cell cell_F = getCell(currentRow, col);
                cell_F.setCellValue(failure);
                cell_F.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Comment Status
                Cell cell_G = getCell(currentRow, col);
                cell_G.setCellValue(commentStatus);
                CellStyle commentCS = p_workBook.createCellStyle();
                commentCS.cloneStyleFrom(getContentStyle(p_workBook));
                commentCS.setLocked(false);
                cell_G.setCellStyle(commentCS);
                // add comment status drop down list for current row.
                String[] statusArray = getCommentStatusList(lastComment);
                if (statusArray.length > 1) {
                    rowsWithCommentSet.add(p_row);
                }
                col++;

                // TM match
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue(matches.toString());
                cell_H.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary source
                Cell cell_I = getCell(currentRow, col);
                cell_I.setCellValue(sourceTerms);
                cell_I.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Glossary target
                Cell cell_J = getCell(currentRow, col);
                cell_J.setCellValue(targetTerms);
                cell_J.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Job Id
                Cell cell_K = getCell(currentRow, col);
                cell_K.setCellValue(p_job.getId());
                cell_K.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Segment id
                Cell cell_L = getCell(currentRow, col);
                cell_L.setCellValue(sourceTuv.getTu(p_job.getId()).getId());
                cell_L.setCellStyle(getContentStyle(p_workBook));
                col++;

                // Fix for GBS-1484
                String externalPageId = sourcePage.getExternalPageId();
                String[] pathNames = externalPageId.split("\\\\");
                String name = pathNames[pathNames.length - 1];
                boolean temp = pathNames[0].contains(")");
                if (temp) {
                    String[] firstNames = pathNames[0].split("\\)");
                    String detailName = firstNames[0];
                    name = name + detailName + ")";
                }
                //Page Name
                Cell cell_M = getCell(currentRow, col);
                cell_M.setCellValue(name);
                cell_M.setCellStyle(getContentStyle(p_workBook));
                col++;

                // SID
                Cell cell_N = getCell(currentRow, col);
                cell_N.setCellValue(sid);
                cell_N.setCellStyle(getContentStyle(p_workBook));
                col++;

                p_row++;
            }
        }
        //Add comment status
        addCommentStatus(p_sheet, rowsWithCommentSet, p_row);
        // Add category failure drop down list here.
        addCategoryFailureValidation(p_sheet, SEGMENT_START_ROW, p_row - 1, CATEGORY_FAILURE_COLUMN,
                CATEGORY_FAILURE_COLUMN);
    }

    return p_row;
}