/ReactiveDeskFX

JavaFX micro-framework that follows MVVM Pattern with Google Guice dependency Injection

Primary LanguageJavaGNU Lesser General Public License v3.0LGPL-3.0

ReactiveDeskFX (JavaFX and Google Guice MVVM Pattern micro-framework)

JavaFX micro-framework to develop very fast JavaFX components with minimal code following MVVM architecture pattern with passive view.

FXML auto-loading with Google Guice dependency Injection.

License: LGPL v3 Build Status Quality Gate Status


Installation

This library is compatible with java 11 or higher version, lower versions are not supported

Maven artifact

<dependency>
  <groupId>com.tangorabox</groupId>
  <artifactId>reactive-desk-fx</artifactId>
  <version>1.0.2</version>
</dependency>

Features

  • An a 'ready to go' ReactiveApplication class that extends Application to auto-instance the Guice Injector, simply extend it and override the startReactiveApp(Stage primaryStage) to start your JavaFX Application with Guice Injection. @Inject attributes of your Application class are ready to use in startReactiveApp method call

  • Automatic FXML file loading (your component must be inyected, don't use new)

  • ReactiveModel combines multiple JavaFX properties in only one model which has invalidation events

  • Injection of custom components inside your view (through @Inject)

  • Convention over Configuration: you don't need to specify the component of .fxml, simply place .fxml with the same name in the same location of your component (you must set up maven accord for that)

  • Optional tag `fxml:controller´ in your .fxml (only needed if you want IDE features)


Example project

If you want to see how to code with this framework please visit my ResumeFX project witch uses that.


Usage Steps

  1. .fxml file must have <fx:root> tag (fx:controller attribute it's optional)
  2. View class must extend the class of your top node in level hierarchy of your .fxml (type attribute of fx:root)
  3. View class must be annotated with @FXMLView (com.tangorabox.reactivedesk.FXMLView)
  4. After injection logic can be done in @FML void initialize() method as usually in JavaFX (or implementing Initializable interface)

Maven configuration for nested .fxml

.fxml files must be placed at the same level of it's .java component, If you want place .fxml in the same package, not in resources folder, you must set up maven accordingly:

<build>
    <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>${project.build.sourceDirectory}</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </resource>
        </resources>

        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>${project.build.testSourceDirectory}</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
</build>

Limitations

When custom component is included inside another .fxml, there should be no customization properties in the tag, or fxml loading will crash on runtime.

Non compliant example:

  <CustomComponent fx:id="myComponent" text="Hello World" maxWidth="800"/>

Compliant example

  <HBox maxWidth="800">
    <CustomComponent fx:id="myComponent"/>
  </HBox>

As you can see, restrict size values through a wrapping Parent, or set this in fxml or your CustomComponent, or in the view code.

If you want to set the text "hello world" please do it programmatically in your view code.

Inspiration Projects

  • Afterburner.fx: I think that it's FXMLView class generate multiple empty useless classes in projects, one for each view

  • JuiceFx: my fork of Afterburner.fx to add @Guice injection features

  • mvvmFX: interesting alternative but seems to have problems with java11+

  • fx-guice: very similar to my project, and I could have used it, but it seems the project is very old and is dead

Contributing

If you want to contribute to upgrade this project with new features or fixing bugs, you're welcome, please make a pull request.


Team

GaRzY
GaRzY
github.com/garzy

Support

Reach out to me at one of the following places!


License

License: LGPL v3