Example usage for org.apache.poi.ss.usermodel Workbook createCellStyle

List of usage examples for org.apache.poi.ss.usermodel Workbook createCellStyle

Introduction

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

Prototype

CellStyle createCellStyle();

Source Link

Document

Create a new Cell style and add it to the workbook's style table

Usage

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

License:Apache License

/**
 * For Translations Edit Report, Write segment information into each row of
 * the sheet.//w  w  w . j a v a  2 s  .  com
 * 
 * @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()));
            Map<Long, Tuv> allTuvMap = this.getAllTuvsMap(targetPage);

            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++;

                // the translation after the translation activity
                CellStyle trgStyle = null;
                String previousSegments = getPreviousSegments(allTuvMap, targetTuv.getId(), targetTuv,
                        p_job.getId(), pData);
                String currentSegments = getSegment(pData, targetTuv, m_rtlTargetLocale, p_job.getId());
                Cell cell_B = getCell(currentRow, col);
                cell_B.setCellValue(previousSegments);
                if (StringUtil.isNotEmpty(previousSegments) && !previousSegments.endsWith(currentSegments)) {
                    trgStyle = m_rtlTargetLocale ? getRtlContentStyle1(p_workBook)
                            : getContentStyle1(p_workBook);
                } else {
                    trgStyle = m_rtlTargetLocale ? getRtlContentStyle(p_workBook) : getContentStyle(p_workBook);
                }
                cell_B.setCellStyle(trgStyle);
                col++;

                // the translation after the review activity
                // CellStyle trgStyle = m_rtlTargetLocale ?
                // getRtlContentStyle(p_workBook)
                // : getContentStyle(p_workBook);
                Cell cell_C = getCell(currentRow, col);
                cell_C.setCellValue(currentSegments);
                cell_C.setCellStyle(trgStyle);
                col++;

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

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

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

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

                // Comment Status
                Cell cell_H = getCell(currentRow, col);
                cell_H.setCellValue(commentStatus);
                CellStyle commentCS = p_workBook.createCellStyle();
                commentCS.cloneStyleFrom(getContentStyle(p_workBook));
                commentCS.setLocked(false);
                cell_H.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_I = getCell(currentRow, col);
                cell_I.setCellValue(matches.toString());
                cell_I.setCellStyle(getContentStyle(p_workBook));
                col++;

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

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

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

                // Segment id
                Cell cell_M = getCell(currentRow, col);
                cell_M.setCellValue(sourceTuv.getTu(p_job.getId()).getId());
                cell_M.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_N = getCell(currentRow, col);
                cell_N.setCellValue(name);
                cell_N.setCellStyle(getContentStyle(p_workBook));
                col++;

                // SID
                Cell cell_O = getCell(currentRow, col);
                cell_O.setCellValue(sid);
                cell_O.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;
}

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

License:Apache License

private CellStyle getContentStyle1(Workbook p_workbook) {
    CellStyle style = p_workbook.createCellStyle();
    style.setWrapText(true);// ww  w . jav a2  s.  co m
    style.setAlignment(CellStyle.ALIGN_LEFT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    Font font = p_workbook.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);
    style.setFont(font);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());

    return style;
}

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

License:Apache License

private CellStyle getRtlContentStyle1(Workbook p_workbook) {
    Font font = p_workbook.createFont();
    font.setFontName("Arial");
    font.setFontHeightInPoints((short) 10);

    CellStyle style = p_workbook.createCellStyle();
    style.setFont(font);//  w  ww. ja va 2s  .co  m
    style.setWrapText(true);
    style.setAlignment(CellStyle.ALIGN_RIGHT);
    style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
    style.setFillPattern(CellStyle.SOLID_FOREGROUND);
    style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());

    return style;
}

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

License:Apache License

private CellStyle getTitleStyle(Workbook p_workbook) {
    if (titleStyle == null) {
        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);//w w  w.  ja v  a  2 s .  c om

        titleStyle = cs;
    }

    return titleStyle;
}

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

License:Apache License

private CellStyle getRejectedStyle(Workbook p_workbook) throws Exception {
    if (rejectedStyle == null) {
        Font rejectedFont = p_workbook.createFont();
        rejectedFont.setFontName("Times");
        rejectedFont.setUnderline(Font.U_NONE);
        rejectedFont.setFontHeightInPoints((short) 11);
        rejectedFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
        rejectedFont.setColor(IndexedColors.RED.getIndex());

        CellStyle style = p_workbook.createCellStyle();
        style.setFont(rejectedFont);//from w ww . ja  v  a  2 s  . co  m
        style.setWrapText(true);

        rejectedStyle = style;
    }

    return rejectedStyle;
}

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

License:Apache License

private CellStyle getRedStyle(Workbook p_workbook) throws Exception {
    if (redStyle == null) {
        Font redFont = p_workbook.createFont();
        redFont.setFontName("Arial");
        redFont.setUnderline(Font.U_NONE);
        redFont.setFontHeightInPoints((short) 10);

        CellStyle style = p_workbook.createCellStyle();
        style.setFont(redFont);/*from w  ww . j  a  v  a2 s . c o m*/
        style.setWrapText(true);
        style.setFillPattern(CellStyle.SOLID_FOREGROUND);
        style.setFillForegroundColor(IndexedColors.RED.getIndex());

        redStyle = style;
    }

    return redStyle;
}

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

License:Apache License

/**
 * Returns a cell format that the wrap has been set to true.
 *///from w w w .  j  a  va2  s.  c o  m
private CellStyle getWrapStyle(Workbook p_workbook) throws Exception {
    if (wrapStyle == null) {
        CellStyle style = p_workbook.createCellStyle();
        style.setWrapText(true);
        wrapStyle = style;
    }

    return wrapStyle;
}

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

License:Apache License

/**
 * Add title to the sheet//w  ww.j a v a  2 s.  c o m
 * 
 * @param p_sheet
 *            the sheet
 * @throws Exception
 */
private void addTitle(Workbook p_workbook, Sheet p_sheet) throws Exception {
    ResourceBundle bundle = PageHandler.getBundle(request.getSession());
    // Title font is black bold on white
    Font titleFont = p_workbook.createFont();
    titleFont.setUnderline(Font.U_NONE);
    titleFont.setFontName("Times");
    titleFont.setFontHeightInPoints((short) 14);
    titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
    titleFont.setColor(IndexedColors.BLACK.getIndex());

    CellStyle titleStyle = p_workbook.createCellStyle();
    titleStyle.setFont(titleFont);
    titleStyle.setWrapText(false);

    Row titleRow = getRow(p_sheet, 0);
    Cell titleCell = getCell(titleRow, 0);
    titleCell.setCellValue(bundle.getString("implemented_comments_check_report"));
    titleCell.setCellStyle(titleStyle);
    p_sheet.setColumnWidth(0, 40 * 256);
}

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

License:Apache License

/**
 * //  www.  j  a  v  a  2 s.  c o m
 * @return format of the report content
 * @throws Exception
 */
private CellStyle getRtlContentStyle(Workbook p_workbook) throws Exception {
    if (rtlContentStyle == null) {
        CellStyle style = p_workbook.createCellStyle();
        Font font = p_workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 10);
        style.setFont(font);
        style.setWrapText(true);
        style.setAlignment(CellStyle.ALIGN_LEFT);

        rtlContentStyle = style;
    }

    return rtlContentStyle;
}

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

License:Apache License

private CellStyle getContentStyle(Workbook p_workbook) throws Exception {
    if (contentStyle == null) {
        CellStyle style = p_workbook.createCellStyle();
        Font font = p_workbook.createFont();
        font.setFontName("Arial");
        font.setFontHeightInPoints((short) 10);
        style.setFont(font);/*from  ww w .j  a va2 s. com*/
        style.setWrapText(true);
        style.setAlignment(CellStyle.ALIGN_LEFT);

        contentStyle = style;
    }

    return contentStyle;
}