Class ExternalControllerFxWeaver

java.lang.Object
net.rgielen.fxweaver.core.FxWeaver
cz.masci.commons.springfx.autoconfigure.ExternalControllerFxWeaver

@Component public class ExternalControllerFxWeaver extends net.rgielen.fxweaver.core.FxWeaver

Reasons to extend FxWeaver class.

  • When using abstract class annotated with FxmlView the controller is not set.
  • When using root fxml inside the fxml the root controller is not loaded.

Overrides method FxWeaver.load(Class, String, ResourceBundle) adding to FxmlLoader

  • builder factory
  • set the controller
  • set the root

Builder factory is used for loading controllers defined as inner elements in fxml. If the class is annotated with FxmlView, it uses this loader to load the controller.

When an abstract class is annotated with FxmlView but the controller is subclass of it the FxmlController annotation is used to instantiate the controller. If the controller class (subclass of the abstract) is not annotated with FxmlController, the FXMLLoader use the abstract class as a controller.

When the fxml is defined as fx:root the controller class has to be annotated with FxmlRoot.

Author:
Daniel MaĊĦek
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExternalControllerFxWeaver(org.springframework.context.ConfigurableApplicationContext context)
    Create ExternalControllerFXWeaver instance
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Build a FXML view location reference for controller classes, based on FxmlView annotation or simple classname.
    protected <C, V extends javafx.scene.Node>
    net.rgielen.fxweaver.core.FxControllerAndView<C,V>
    load(Class<C> controllerClass, String location, ResourceBundle resourceBundle)
    Load controller instance, potentially weaved with a FXML view declaring the given class as fx:controller.

    Methods inherited from class net.rgielen.fxweaver.core.FxWeaver

    getBean, load, load, loadController, loadController, loadController, loadController, loadView, loadView, loadView, loadView, shutdown

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExternalControllerFxWeaver

      public ExternalControllerFxWeaver(org.springframework.context.ConfigurableApplicationContext context)
      Create ExternalControllerFXWeaver instance
      Parameters:
      context - Spring context
  • Method Details

    • load

      protected <C, V extends javafx.scene.Node> net.rgielen.fxweaver.core.FxControllerAndView<C,V> load(Class<C> controllerClass, String location, ResourceBundle resourceBundle)
      Load controller instance, potentially weaved with a FXML view declaring the given class as fx:controller.

      The possible FXML resource is inferred from a FxmlView annotation at the controller class or the simple classname and package of said class if it was not annotated like this. If the FXML file is resolvable, the defined view within will be loaded by FXMLLoader. The controller will then be instantiated based on the fx:controller attribute, using the bean factory from FxWeaver(Callback, Runnable). If the bean factory is based on a dependency management framework such as Spring, Guice or CDI, this means that the instance will be fully managed and injected as declared.

      If the controller class does not come with a resolvable FXML view resource, the controller will be instantiated by the given bean factory directly.

      Overrides:
      load in class net.rgielen.fxweaver.core.FxWeaver
      Type Parameters:
      V - The view type
      C - The controller type
      Parameters:
      controllerClass - The controller class of which a weaved instance should be provided
      location - The location of the FXML view to load as a classloader resource. May be null or not resolvable, in which case the controller will be directly instantiated by the given bean factory.
      resourceBundle - The optional ResourceBundle to use for view creation. May be null
      Returns:
      A SimpleFxControllerAndView container with the managed instance of the requested controller and the corresponding view, if applicable
      See Also:
      • FxWeaver
      • FXMLLoader
    • buildFxmlReference

      protected String buildFxmlReference(Class<?> c)
      Build a FXML view location reference for controller classes, based on FxmlView annotation or simple classname.
      Overrides:
      buildFxmlReference in class net.rgielen.fxweaver.core.FxWeaver
      Parameters:
      c - The class to build a FXML location for. If it does not contain a FxmlView annotation to specify resource to load, it is assumed that the view resides in the same package, named {c.getSimpleName()}.fxml
      Returns:
      a resource location suitable for loading by Class.getResource(String)