Search in sources :

Example 1 with FXMLController

use of com.kyj.fx.voeditor.visual.framework.annotation.FXMLController 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)

Example 2 with FXMLController

use of com.kyj.fx.voeditor.visual.framework.annotation.FXMLController in project Gargoyle by callakrsos.

the class FxUtil method load.

/********************************
	 * 작성일 : 2016. 5. 21. 작성자 : KYJ
	 *
	 * FXMLController 어노테이션 에 정의된 내용을 기준으로 FXML을 로드한다. </br>
	 * 아래메소드를 활용하는 경우
	 *
	 * PostInitialize 어노테이션을 활용하여 initialize() 수행후 후처리를 지정할 수 있음.
	 *
	 * @param controllerClass
	 * @param option
	 * @return
	 * @throws GargoyleException
	 * @throws NullPointerException
	 * @throws IOException
	 ********************************/
public static <N, C> N load(Class<C> controllerClass, Object rootInstance, Consumer<N> option, Consumer<C> controllerAction) throws Exception {
    if (controllerClass == null)
        throw new NullPointerException("controller is null.");
    String fullClassName = controllerClass.getCanonicalName();
    FXMLController controller = getFxmlController(controllerClass);
    if (controller == null) {
        throw new GargoyleException("this is not FXMLController. check @FXMLController");
    }
    //controller.value();
    String fxml = getFxml(controller);
    if (ValueUtil.isEmpty(fxml))
        throw new IllegalArgumentException("value is empty..");
    InstanceTypes type = controller.instanceType();
    N newInstance = null;
    switch(type) {
        case Singleton:
            Node node = FxMemory.get(fullClassName);
            if (node == null) {
                newInstance = newInstance(controllerClass, rootInstance, controller.isSelfController(), fxml, option, controllerAction);
                FxMemory.put(fullClassName, (Node) newInstance);
            } else {
                newInstance = (N) node;
            }
            break;
        case RequireNew:
            newInstance = newInstance(controllerClass, rootInstance, controller.isSelfController(), fxml, option, controllerAction);
            break;
    }
    return newInstance;
}
Also used : DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) Node(javafx.scene.Node) InstanceTypes(com.kyj.fx.voeditor.visual.framework.InstanceTypes) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)

Aggregations

DockNode (com.kyj.fx.voeditor.visual.component.dock.pane.DockNode)2 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)2 InstanceTypes (com.kyj.fx.voeditor.visual.framework.InstanceTypes)2 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)2 Node (javafx.scene.Node)2 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 SvnChagnedCodeComposite (com.kyj.fx.voeditor.visual.component.scm.SvnChagnedCodeComposite)1 JavaTextArea (com.kyj.fx.voeditor.visual.component.text.JavaTextArea)1 FxPostInitialize (com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize)1 GargoyleBuilderFactory (com.kyj.fx.voeditor.visual.framework.builder.GargoyleBuilderFactory)1 GargoyleButtonBuilder (com.kyj.fx.voeditor.visual.framework.builder.GargoyleButtonBuilder)1 FxContextManager (com.kyj.fx.voeditor.visual.framework.contextmenu.FxContextManager)1 ToExcelFileFunction (com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction)1 CloseableParent (com.kyj.fx.voeditor.visual.main.layout.CloseableParent)1 FxMemory (com.kyj.fx.voeditor.visual.momory.FxMemory)1