Search in sources :

Example 1 with GargoyleFileAlreadyExistException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException in project Gargoyle by callakrsos.

the class VoEditorController method btnExcelExportOnMouseClick.

/**
	 * 엑셀 export
	 *
	 * @param e
	 */
@FXML
public void btnExcelExportOnMouseClick(MouseEvent e) {
    File saveFile = DialogUtil.showFileSaveCheckDialog(SharedMemory.getPrimaryStage(), new Consumer<FileChooser>() {

        @Override
        public void accept(FileChooser choser) {
            String fileName = txtClassName.getText();
            File dir = SystemUtils.getUserDir();
            choser.setInitialFileName(fileName);
            choser.setInitialDirectory(dir);
            choser.getExtensionFilters().add(new ExtensionFilter(GargoyleExtensionFilters.XLSX_NAME, GargoyleExtensionFilters.XLSX));
        }
    });
    boolean isSuccess = false;
    if (saveFile != null) {
        try {
            File createExcelFile = VoWizardUtil.createExcelFile(saveFile.getParentFile(), saveFile.getName(), tbVoEditor.getItems(), true);
            if (createExcelFile != null && createExcelFile.exists()) {
                isSuccess = true;
            }
        } catch (GargoyleFileAlreadyExistException e1) {
            ValueUtil.toString(e1);
            DialogUtil.showExceptionDailog(e1);
            return;
        }
    }
    if (isSuccess) {
        if (chkWriteThenOpen.isSelected()) {
            if (Desktop.isDesktopSupported()) {
                try {
                    Desktop.getDesktop().open(saveFile);
                } catch (IOException e1) {
                    DialogUtil.showExceptionDailog(e1);
                }
            }
        }
    }
}
Also used : ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) File(java.io.File) FXML(javafx.fxml.FXML)

Example 2 with GargoyleFileAlreadyExistException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException in project Gargoyle by callakrsos.

the class VoWizardUtil method createExcelFile.

/**
	 * 엑셀파일생성
	 *
	 * @param pathDir
	 * @param _fileName
	 * @param models
	 * @return 생성된 엑셀파일에 대한 파일 객체
	 * @throws GargoyleFileAlreadyExistException
	 */
public static File createExcelFile(File pathDir, String _fileName, List<TableModelDVO> models, boolean isOverWrite) throws GargoyleFileAlreadyExistException {
    File saveFile = null;
    if (!pathDir.exists() || !pathDir.isDirectory())
        return saveFile;
    String fileName = _fileName;
    String createFilePathName = pathDir.getAbsolutePath() + File.separator + fileName;
    if (!_fileName.endsWith(".xlsx")) {
        createFilePathName.concat(".xlsx");
    }
    saveFile = new File(createFilePathName);
    if (saveFile.exists() && !isOverWrite) {
        throw new GargoyleFileAlreadyExistException("already exists. file");
    }
    // 로우번호 채번링
    AtomicInteger atomicInteger = new AtomicInteger(2);
    List<ExcelDataDVO> collect = models.stream().map(vo -> {
        List<ExcelDataDVO> list = new ArrayList<ExcelDataDVO>();
        String columnName = vo.getDatabaseColumnName();
        String dataType = vo.getType();
        String dataSize = vo.getSize();
        String desc = vo.getDesc();
        int row = atomicInteger.getAndIncrement();
        list.add(new ExcelDataDVO(row, 0, ValueUtil.toCamelCase(ValueUtil.decode(columnName, columnName, vo.getName()).toString())));
        list.add(new ExcelDataDVO(row, 1, dataType));
        list.add(new ExcelDataDVO(row, 2, dataSize));
        list.add(new ExcelDataDVO(row, 3, desc));
        return list;
    }).collect(() -> {
        /* 컬럼헤더처리 */
        ArrayList<ExcelDataDVO> arrayList = new ArrayList<ExcelDataDVO>();
        arrayList.add(new ExcelDataDVO(1, 0, VoWizardUtil.COLUMN_NAME, /* "컬럼명" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 1, VoWizardUtil.TYPE, /* "데이터타입" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 2, VoWizardUtil.DATA_LENGTH, /* "데이터사이즈" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 3, VoWizardUtil.COMMENTS, /* "설명" */
        Color.GREEN));
        return arrayList;
    }, (t, u) -> t.addAll(u), (t, u) -> t.addAll(u));
    ExcelSVO svo = new ExcelSVO();
    svo.addSheetExcelDVO(SHEET_NAME, collect);
    try {
        ExcelUtil.createExcel(saveFile.getAbsolutePath(), svo, false);
    } catch (Exception e1) {
        ValueUtil.toString(e1);
        saveFile = null;
    }
    return saveFile;
}
Also used : Color(java.awt.Color) TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) ClassMeta(com.kyj.fx.voeditor.core.model.meta.ClassMeta) Logger(org.slf4j.Logger) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) LoggerFactory(org.slf4j.LoggerFactory) File(java.io.File) VoEditor(com.kyj.fx.voeditor.core.VoEditor) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) ExcelDataDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO) ExcelSVO(com.kyj.fx.voeditor.visual.excels.base.ExcelSVO) DatabaseTypeMappingFunction(com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction) ExcelDataDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExcelSVO(com.kyj.fx.voeditor.visual.excels.base.ExcelSVO) File(java.io.File) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) SQLException(java.sql.SQLException)

Aggregations

GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)2 File (java.io.File)2 VoEditor (com.kyj.fx.voeditor.core.VoEditor)1 ClassMeta (com.kyj.fx.voeditor.core.model.meta.ClassMeta)1 ExcelDataDVO (com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO)1 ExcelSVO (com.kyj.fx.voeditor.visual.excels.base.ExcelSVO)1 DatabaseTypeMappingFunction (com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction)1 Color (java.awt.Color)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FXML (javafx.fxml.FXML)1 FileChooser (javafx.stage.FileChooser)1 ExtensionFilter (javafx.stage.FileChooser.ExtensionFilter)1 TableMasterDVO (kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO)1 TableModelDVO (kyj.Fx.dao.wizard.core.model.vo.TableModelDVO)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1