Search in sources :

Example 1 with InstanceTypes

use of com.kyj.fx.voeditor.visual.framework.InstanceTypes 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)1 GargoyleException (com.kyj.fx.voeditor.visual.exceptions.GargoyleException)1 InstanceTypes (com.kyj.fx.voeditor.visual.framework.InstanceTypes)1 FXMLController (com.kyj.fx.voeditor.visual.framework.annotation.FXMLController)1 Node (javafx.scene.Node)1