Search in sources :

Example 16 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class VoEditorController method btnExcelImporOnMouseClick.

@FXML
public void btnExcelImporOnMouseClick() {
    File selectFile = DialogUtil.showFileDialog(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, GargoyleExtensionFilters.XLS));
        }
    });
    if (selectFile != null && selectFile.exists()) {
        try {
            String simpleName = selectFile.getName();
            String className = simpleName.substring(0, simpleName.indexOf("."));
            txtClassName.setText(className);
            // TODO 좀 더 깔끔한 방법으로 작성하는걸 고려.. ex) template기반
            List<TableModelDVO> list = ExcelUtil.toK(selectFile, new BiFunction<File, Workbook, List<TableModelDVO>>() {

                @Override
                public List<TableModelDVO> apply(File file, Workbook xlsx) {
                    List<TableModelDVO> llist = new ArrayList<>();
                    Sheet sheetAt = xlsx.getSheetAt(0);
                    // 데이터부 처리
                    for (int _row = 3; _row <= sheetAt.getLastRowNum(); _row++) {
                        Row row = sheetAt.getRow(_row);
                        Cell column = row.getCell(0);
                        Cell type = row.getCell(1);
                        Cell size = row.getCell(2);
                        Cell comment = row.getCell(3);
                        TableModelDVO modelDVO = new TableModelDVO();
                        modelDVO.setName(column.getStringCellValue());
                        modelDVO.setType(type.getStringCellValue());
                        modelDVO.setSize(size.getStringCellValue());
                        modelDVO.setDesc(comment.getStringCellValue());
                        llist.add(modelDVO);
                    }
                    return llist;
                }
            });
            tbVoEditor.getItems().clear();
            tbVoEditor.getItems().addAll(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) Workbook(org.apache.poi.ss.usermodel.Workbook) FileNotFoundException(java.io.FileNotFoundException) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) ParseException(com.github.javaparser.ParseException) IOException(java.io.IOException) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) FileChooser(javafx.stage.FileChooser) List(java.util.List) ObservableList(javafx.collections.ObservableList) ArrayList(java.util.ArrayList) Row(org.apache.poi.ss.usermodel.Row) File(java.io.File) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) FXML(javafx.fxml.FXML)

Aggregations

TableModelDVO (kyj.Fx.dao.wizard.core.model.vo.TableModelDVO)16 List (java.util.List)7 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 TableMasterDVO (kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO)5 ClassMeta (com.kyj.fx.voeditor.core.model.meta.ClassMeta)4 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)4 DatabaseTypeMappingFunction (com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction)4 ObservableList (javafx.collections.ObservableList)4 FXML (javafx.fxml.FXML)4 ParseException (com.github.javaparser.ParseException)3 FieldMeta (com.kyj.fx.voeditor.core.model.meta.FieldMeta)3 DatabaseTableView (com.kyj.fx.voeditor.visual.component.popup.DatabaseTableView)3 JavaTextView (com.kyj.fx.voeditor.visual.component.popup.JavaTextView)3 CommonContextMenuEvent (com.kyj.fx.voeditor.visual.events.CommonContextMenuEvent)3 SQLException (java.sql.SQLException)3 TableDVO (kyj.Fx.dao.wizard.core.model.vo.TableDVO)3 VoEditor (com.kyj.fx.voeditor.core.VoEditor)2 EditorUtil (com.kyj.fx.voeditor.util.EditorUtil)2