Search in sources :

Example 1 with GargoyleException

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

the class SAXPasrerUtil method saveXml.

// private static final Logger LOGGER =
// LoggerFactory.getLogger(SAXPasrerUtil.class);
/**
	 * 특정객체를 파일로 저장
	 *
	 * 단.. 클래스에 XmlRootElement 어노테이션이 붙어 있을것
	 *
	 * @작성자 : KYJ
	 * @작성일 : 2016. 3. 16.
	 * @param file
	 * @param job
	 * @throws JAXBException
	 * @throws GargoyleException
	 */
public static <T> void saveXml(File file, T job) throws JAXBException, GargoyleException {
    if (job.getClass().getAnnotation(XmlRootElement.class) == null)
        throw new GargoyleException("this object is not contains XmlRootElement annotation");
    JAXBContext context = JAXBContext.newInstance(job.getClass());
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    m.marshal(job, file);
}
Also used : XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Marshaller(javax.xml.bind.Marshaller) JAXBContext(javax.xml.bind.JAXBContext) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException)

Example 2 with GargoyleException

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

the class DbUtil method tables.

/********************************
	 * 작성일 : 2016. 8. 11. 작성자 : KYJ
	 *
	 * 2016-11-10
	 * 모든 테이블탐색후 대소문자무시 검색으로 수정
	 *</br>
	 *</br>
	 		1.TABLE_CAT String => table catalog (may be null)  </br>
			2.TABLE_SCHEM String => table schema (may be null) </br>
			3.TABLE_NAME String => table name </br>
			4.TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". </br>
			5.REMARKS String => explanatory comment on the table </br>
			6.TYPE_CAT String => the types catalog (may be null) </br>
			7.TYPE_SCHEM String => the types schema (may be null) </br>
			8.TYPE_NAME String => type name (may be null) </br>
			9.SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null) </br>
			10.REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null) </br>
	
	 * @param converter
	 * @return
	 * @throws Exception
	 ********************************/
public static <T> List<T> tables(String tableNamePattern, Function<ResultSet, T> converter) throws Exception {
    if (converter == null)
        throw new GargoyleException(GargoyleException.ERROR_CODE.PARAMETER_EMPTY, "converter is null ");
    List<T> tables = new ArrayList<>();
    try (Connection connection = getConnection()) {
        DatabaseMetaData metaData = connection.getMetaData();
        ResultSet rs = metaData.getTables(null, null, "%", /* + tableNamePattern + "%"*/
        new String[] { "TABLE" });
        String tableNamePatternUpperCase = tableNamePattern.toUpperCase();
        while (rs.next()) {
            // 2016-08-18 특정데이터베이스(sqlite)에서는 인덱스 트리거정보도 동시에 출력된다.
            String tableType = rs.getString(4);
            if ("TABLE".equals(tableType)) {
                String tableName = rs.getString(3);
                if (tableName.toUpperCase().indexOf(tableNamePatternUpperCase) != -1) {
                    T apply = converter.apply(rs);
                    if (apply != null)
                        tables.add(apply);
                }
            }
        }
    }
    return tables;
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 3 with GargoyleException

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

the class DbUtil method columns.

/**
	 	1. TABLE_CAT String => table catalog (may be null) </br>
		2.TABLE_SCHEM String => table schema (may be null) </br>
		3.TABLE_NAME String => table name  </br>
		4.COLUMN_NAME String => column name </br>
		5.DATA_TYPE int => SQL type from java.sql.Types </br>
		6.TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified </br>
		7.COLUMN_SIZE int => column size.  </br>
		8.BUFFER_LENGTH is not used.  </br>
		9.DECIMAL_DIGITS int => the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable. </br>
		10.NUM_PREC_RADIX int => Radix (typically either 10 or 2)  </br>
		11.NULLABLE int => is NULL allowed. ◦ columnNoNulls - might not allow NULL values </br>
		◦ columnNullable - definitely allows NULL values  </br>
		◦ columnNullableUnknown - nullability unknown  </br>
		</br>
		12.REMARKS String => comment describing column (may be null) </br>
		13.COLUMN_DEF String => default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be null) </br>
		14.SQL_DATA_TYPE int => unused  </br>
		15.SQL_DATETIME_SUB int => unused  </br>
		16.CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column </br>
		17.ORDINAL_POSITION int => index of column in table (starting at 1)  </br>
		18.IS_NULLABLE String => ISO rules are used to determine the nullability for a column. ◦ YES --- if the column can include NULLs </br>
		◦ NO --- if the column cannot include NULLs  </br>
		◦ empty string --- if the nullability for the column is unknown </br>
		</br>
		19.SCOPE_CATALOG String => catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF) </br>
		20.SCOPE_SCHEMA String => schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF) </br>
		21.SCOPE_TABLE String => table name that this the scope of a reference attribute (null if the DATA_TYPE isn't REF) </br>
		22.SOURCE_DATA_TYPE short => source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated REF) </br>
		23.IS_AUTOINCREMENT String => Indicates whether this column is auto incremented ◦ YES --- if the column is auto incremented  </br>
		◦ NO --- if the column is not auto incremented  </br>
		◦ empty string --- if it cannot be determined whether the column is auto incremented </br>
		</br>
		24.IS_GENERATEDCOLUMN String => Indicates whether this is a generated column ◦ YES --- if this a generated column </br>
		◦ NO --- if this not a generated column  </br>
		◦ empty string --- if it cannot be determined whether this is a generated column </br>
	 * @작성자 : KYJ
	 * @작성일 : 2016. 11. 10.
	 * @param connection
	 * @param tableNamePattern
	 * @param converter
	 * @return
	 * @throws Exception
	 */
public static <T> List<T> columns(Connection connection, String tableNamePattern, Function<ResultSet, T> converter) throws Exception {
    if (converter == null)
        throw new GargoyleException(GargoyleException.ERROR_CODE.PARAMETER_EMPTY, "converter is null ");
    List<T> tables = new ArrayList<>();
    // try (Connection connection = getConnection()) {
    DatabaseMetaData metaData = connection.getMetaData();
    // metaData.getColumns(null,
    ResultSet rs = COLUMN_CONVERTER.apply(tableNamePattern, metaData);
    while (rs.next()) {
        tables.add(converter.apply(rs));
    }
    return tables;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 4 with GargoyleException

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

the class FxExcelUtil method createExcel.

/**
	 *  엑셀파일을 생성한다.
	 * @작성자 : KYJ
	 * @작성일 : 2016. 9. 6.
	 *  
	 * @param exportExcelFile 
	 *   	export하려는 파일 확장자는 .xlsx 사용 권고
	 *   
	 * @param dataSource 
	 *      데이터셋.  개발자 혼동(순서)을 피하기 위해 LinkedMap(순서유지)을 강제적으로 사용
	 *      값은 Map<Sheet명, Map<컬럼메타,List<값>> 순 매핑이되어있다.
	 * 
	 * @param handler
	 *     데이터 컨버터, 데이터내에 특화가 필요한 처리가 필요한경우 구현하여 사용하도록한다.
	 *     
	 * @throws Exception
	 */
public static void createExcel(File exportExcelFile, LinkedHashMap<String, LinkedHashMap<ExcelColumnExpression, List<Object>>> dataSource, IExcelDataSetHandler<Sheet, LinkedHashMap<ExcelColumnExpression, List<Object>>> handler, Map<String, Map<String, String>> metadata, boolean overwrite) throws Exception {
    //파일이 이미 존재하는 상황에서 overrite하려는 경우 에러.
    if (exportExcelFile.exists() && !overwrite) {
        throw new GargoyleException(String.format("output File : {%s} already exists.!", exportExcelFile.getName()));
    }
    Workbook createNewWorkBookXlsx = createNewWorkBookXlsx();
    //시트를 의미하는 iterator.
    Iterator<String> iterator = dataSource.keySet().iterator();
    int sheetIndex = 0;
    while (iterator.hasNext()) {
        String sheetName = iterator.next();
        Sheet createSheet = createNewWorkBookXlsx.createSheet(sheetName);
        Map<String, String> meta = metadata.get(sheetName);
        if (meta == null || meta.isEmpty())
            continue;
        //각 헤더컬럼의 개수(높이)
        String columnMaxHeight = meta.get($$META_COLUMN_MAX_HEIGHT$$);
        int maxColumnRowSize = ValueUtil.decode(columnMaxHeight, val -> Integer.parseInt(val), () -> 0);
        LinkedHashMap<ExcelColumnExpression, List<Object>> linkedHashMap = dataSource.get(sheetName);
        createHeaders(handler, createSheet, linkedHashMap, maxColumnRowSize);
        //컬럼 + 데이터리스트로 이루어진 데이터셋
        LinkedHashMap<ExcelColumnExpression, List<Object>> dataSet = dataSource.get(sheetName);
        drawBody(handler, createSheet, maxColumnRowSize, dataSet);
        //(short) (createSheet.getRow(maxColumnRowSize + 1).getLastCellNum() - 1);
        short lastColumnNum = (short) dataSet.size();
        IExcelScreenHandler screenHandler = handler.getExcelScreenHandler();
        if (handler.isApplyAutoFit()) {
            for (int i = 0; i < lastColumnNum; i++) {
                createSheet.autoSizeColumn(i);
            }
        }
        if (screenHandler != null) {
            //사용자 정의 sheet 처리를 지원한다.
            screenHandler.customSheetHandle(sheetIndex, createSheet);
            sheetIndex++;
        }
        //로고 이미지 처리.
        Utils.createDefaultLogo(createSheet);
        createSheet.setAutoFilter(new CellRangeAddress((maxColumnRowSize), (maxColumnRowSize), START_COLUMN_INDEX, lastColumnNum));
        createSheet.createFreezePane(0, (maxColumnRowSize + 1));
    }
    //사용자 정의 workbook 처리를 지원함.
    IExcelScreenHandler excelScreenHandler = handler.getExcelScreenHandler();
    if (excelScreenHandler != null)
        excelScreenHandler.customWorkbookHandle(createNewWorkBookXlsx);
    //파일 write처리.
    try (FileOutputStream fileOutputStream = new FileOutputStream(exportExcelFile)) {
        createNewWorkBookXlsx.write(fileOutputStream);
    }
}
Also used : IExcelScreenHandler(com.kyj.fx.voeditor.visual.framework.excel.IExcelScreenHandler) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook) ExcelColumnExpression(com.kyj.fx.voeditor.visual.framework.excel.ExcelColumnExpression) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Sheet(org.apache.poi.ss.usermodel.Sheet)

Example 5 with GargoyleException

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

the class FxUtil method newInstance.

private static <T, C> T newInstance(Class<?> controllerClass, Object rootInstance, boolean isSelfController, String _fxml, Consumer<T> option, Consumer<C> controllerAction) throws Exception {
    String fxml = _fxml;
    if (fxml == null) {
        FXMLController controller = getFxmlController(controllerClass);
        if (controller == null) {
            throw new GargoyleException("this is not FXMLController. check @FXMLController");
        }
        //controller.value();
        fxml = getFxml(controller);
    }
    URL resource = controllerClass.getResource(fxml);
    FXMLLoader loader = createNewFxmlLoader();
    loader.setLocation(resource);
    if (isSelfController && rootInstance != null) {
        try {
            loader.setRoot(rootInstance);
            loader.setController(rootInstance);
        } catch (Exception e) {
            throw new GargoyleException(e);
        }
    }
    T load = loader.load();
    C instanceController = loader.getController();
    // show warning...
    if (load == null) {
        LOGGER.warn("load result is empty.. controller class : {} ", controllerClass);
    }
    Method[] declaredMethods = controllerClass.getDeclaredMethods();
    //  2017-02-07 findfirst에서 어노테이션으로 선언된 다건의 함수를 호출하게 다시 유도.
    //  findfirst로 수정. @FxPostInitialize가 여러건있는경우를 잘못된 로직 유도를 방지.
    Stream.of(declaredMethods).filter(m -> m.getParameterCount() == 0 && m.getAnnotation(FxPostInitialize.class) != null).forEach(m -> {
        if (m.getModifiers() == Modifier.PUBLIC) {
            try {
                if (instanceController != null) {
                    Platform.runLater(() -> {
                        try {
                            m.setAccessible(true);
                            m.invoke(instanceController);
                        } catch (Exception e) {
                            LOGGER.error(ValueUtil.toString(e));
                        }
                    });
                }
            } catch (Exception e) {
                LOGGER.error(ValueUtil.toString(e));
            }
        }
    });
    if (option != null) {
        option.accept(load);
    }
    if (controllerAction != null)
        controllerAction.accept(instanceController);
    Platform.runLater(() -> {
        Parent parent = (Parent) load;
        List<Node> findAllByNodes = FxUtil.findAllByNodes(parent, v -> v instanceof Button);
        findAllByNodes.forEach(v -> {
            GargoyleButtonBuilder.applyStyleClass((Button) v, SkinManager.BUTTON_STYLE_CLASS_NAME);
        });
    });
    return load;
}
Also used : StageStyle(javafx.stage.StageStyle) PageOrientation(javafx.print.PageOrientation) Printer(javafx.print.Printer) SnapshotParameters(javafx.scene.SnapshotParameters) Transition(javafx.animation.Transition) AnimationType(jidefx.animation.AnimationType) PageLayout(javafx.print.PageLayout) TabPane(javafx.scene.control.TabPane) FontPosture(javafx.scene.text.FontPosture) Map(java.util.Map) Point2D(javafx.geometry.Point2D) PopOver(org.controlsfx.control.PopOver) Rectangle2D(javafx.geometry.Rectangle2D) Pair(javafx.util.Pair) Set(java.util.Set) SnapshotResult(javafx.scene.SnapshotResult) KeyEvent(javafx.scene.input.KeyEvent) Screen(javafx.stage.Screen) ScmCommitComposite(com.kyj.fx.voeditor.visual.component.scm.ScmCommitComposite) Platform(javafx.application.Platform) Stream(java.util.stream.Stream) Region(javafx.scene.layout.Region) FxContextManager(com.kyj.fx.voeditor.visual.framework.contextmenu.FxContextManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) FXMLLoader(javafx.fxml.FXMLLoader) GargoyleButtonBuilder(com.kyj.fx.voeditor.visual.framework.builder.GargoyleButtonBuilder) Color(javafx.scene.paint.Color) Properties(java.util.Properties) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) PopupFeatures(javafx.scene.web.PopupFeatures) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileChooser(javafx.stage.FileChooser) Tab(javafx.scene.control.Tab) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) WebEvent(javafx.scene.web.WebEvent) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) SvnChagnedCodeComposite(com.kyj.fx.voeditor.visual.component.scm.SvnChagnedCodeComposite) Parent(javafx.scene.Parent) FileSystemView(javax.swing.filechooser.FileSystemView) Task(javafx.concurrent.Task) InstanceTypes(com.kyj.fx.voeditor.visual.framework.InstanceTypes) ImageIO(javax.imageio.ImageIO) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) Method(java.lang.reflect.Method) AutoCompletionTextFieldBinding(impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding) FxSVNHistoryDataSupplier(com.kyj.fx.voeditor.visual.component.scm.FxSVNHistoryDataSupplier) TextField(javafx.scene.control.TextField) GargoyleLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleLoadBar) Paper(javafx.print.Paper) BufferedImage(java.awt.image.BufferedImage) Predicate(java.util.function.Predicate) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) Font(javafx.scene.text.Font) Icon(javax.swing.Icon) Collectors(java.util.stream.Collectors) FxPostInitialize(com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize) MarginType(javafx.print.Printer.MarginType) List(java.util.List) Modifier(java.lang.reflect.Modifier) Scale(javafx.scene.transform.Scale) Optional(java.util.Optional) FontWeight(javafx.scene.text.FontWeight) AnimationUtils(jidefx.animation.AnimationUtils) Scene(javafx.scene.Scene) GargoyleBuilderFactory(com.kyj.fx.voeditor.visual.framework.builder.GargoyleBuilderFactory) WebEngine(javafx.scene.web.WebEngine) TextArea(javafx.scene.control.TextArea) MouseEvent(javafx.scene.input.MouseEvent) WebViewConsole(com.kyj.fx.voeditor.visual.component.console.WebViewConsole) Function(java.util.function.Function) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) Charset(java.nio.charset.Charset) State(javafx.concurrent.Worker.State) JavaTextView(com.kyj.fx.voeditor.visual.component.popup.JavaTextView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) FxMemory(com.kyj.fx.voeditor.visual.momory.FxMemory) PrinterJob(javafx.print.PrinterJob) OutputStream(java.io.OutputStream) KeyCode(javafx.scene.input.KeyCode) WebView(javafx.scene.web.WebView) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) TablePosition(javafx.scene.control.TablePosition) WritableImage(javafx.scene.image.WritableImage) FileInputStream(java.io.FileInputStream) Consumer(java.util.function.Consumer) GargoyleSynchLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleSynchLoadBar) Stage(javafx.stage.Stage) Closeable(java.io.Closeable) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Window(javafx.stage.Window) ChangeListener(javafx.beans.value.ChangeListener) InputStream(java.io.InputStream) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) Parent(javafx.scene.Parent) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) Node(javafx.scene.Node) Method(java.lang.reflect.Method) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) FXMLLoader(javafx.fxml.FXMLLoader) URL(java.net.URL) IOException(java.io.IOException) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) MouseButton(javafx.scene.input.MouseButton) Button(javafx.scene.control.Button) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)

Aggregations

GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)9 ArrayList (java.util.ArrayList)5 DatabaseMetaData (java.sql.DatabaseMetaData)4 ResultSet (java.sql.ResultSet)4 DockNode (com.kyj.fx.voeditor.visual.component.dock.pane.DockNode)2 InstanceTypes (com.kyj.fx.voeditor.visual.framework.InstanceTypes)2 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 List (java.util.List)2 ObservableList (javafx.collections.ObservableList)2 Node (javafx.scene.Node)2 FileWrapper (com.kyj.fx.voeditor.visual.component.FileWrapper)1 GargoyleLoadBar (com.kyj.fx.voeditor.visual.component.bar.GargoyleLoadBar)1 GargoyleSynchLoadBar (com.kyj.fx.voeditor.visual.component.bar.GargoyleSynchLoadBar)1 WebViewConsole (com.kyj.fx.voeditor.visual.component.console.WebViewConsole)1 JavaTextView (com.kyj.fx.voeditor.visual.component.popup.JavaTextView)1 FxSVNHistoryDataSupplier (com.kyj.fx.voeditor.visual.component.scm.FxSVNHistoryDataSupplier)1 ScmCommitComposite (com.kyj.fx.voeditor.visual.component.scm.ScmCommitComposite)1