org.tsukuba_bunko.lilac.helper.port.impl.ExportLabelHelperImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.tsukuba_bunko.lilac.helper.port.impl.ExportLabelHelperImpl.java

Source

/*
 * All Rights Reserved.
 * Copyright (C) 2012 Tsukuba Bunko.
 *
 * Licensed under the BSD License ("the License"); you may not use
 * this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * $Id:$
 */
package org.tsukuba_bunko.lilac.helper.port.impl;

import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.seasar.extension.jdbc.AutoSelect;
import org.tsukuba_bunko.lilac.entity.Label;
import org.tsukuba_bunko.lilac.helper.port.ExportDataHelper;

/**
 * ?? {@link ExportDataHelper} ??
 * @author $Author: $
 * @version $Revision: $ $Date: $
 */
public class ExportLabelHelperImpl extends ExportDataHelperBase<Label> {

    private XSSFCellStyle flagCellStyle;

    private XSSFCellStyle noteCellStyle;

    private int maxLabelNameLength;

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#getSheetName()
     */
    @Override
    protected String getSheetName() {
        return "";
    }

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#prepare(org.apache.poi.xssf.usermodel.XSSFWorkbook)
     */
    @Override
    protected void prepare(XSSFWorkbook book) {
        flagCellStyle = book.createCellStyle();
        flagCellStyle.setAlignment(HorizontalAlignment.CENTER);
        flagCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);

        noteCellStyle = book.createCellStyle();
        XSSFFont noteFont = book.createFont();
        noteFont.setFontHeightInPoints((short) 9);
        noteCellStyle.setFont(noteFont);
        noteCellStyle.setAlignment(HorizontalAlignment.LEFT);
        noteCellStyle.setVerticalAlignment(VerticalAlignment.TOP);
        noteCellStyle.setWrapText(true);
    }

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#buildQuery()
     */
    @Override
    protected AutoSelect<Label> buildQuery() {
        return jdbcManager.from(Label.class).orderBy("name ASC");
    }

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#processHeaderRow(org.apache.poi.xssf.usermodel.XSSFRow)
     */
    @Override
    protected void processHeaderRow(XSSFRow row) {
        createHeaderCell(row, 0, "S");
        createHeaderCell(row, 1, "??");
        createHeaderCell(row, 2, "");
        createHeaderCell(row, 3, "Web");
    }

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#processRow(java.lang.Object, org.apache.poi.xssf.usermodel.XSSFRow, int)
     */
    @Override
    protected void processRow(Label entity, XSSFRow row, int index) {
        //
        setCellValue(createCell(row, 0, flagCellStyle), "U");
        //??
        setCellValue(createCell(row, 1, null), entity.name);
        //
        setCellValue(createCell(row, 2, noteCellStyle), entity.note);
        //Web
        setCellValue(createCell(row, 3, noteCellStyle), entity.website);

        //??
        if (entity.name.length() > maxLabelNameLength) {
            maxLabelNameLength = entity.name.length();
        }
    }

    /**
     * @see org.tsukuba_bunko.lilac.helper.port.impl.ExportDataHelperBase#finish(org.apache.poi.xssf.usermodel.XSSFWorkbook)
     */
    @Override
    protected void finish(XSSFWorkbook book) {
        sheet.setColumnWidth(0, 768);
        sheet.setColumnWidth(1, maxLabelNameLength * 512);
        sheet.setColumnWidth(2, 20 * 256);
        sheet.setColumnWidth(3, 20 * 256);
    }
}