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;
}
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;
}
Aggregations