mvvmfx/src/main/java/de/saxsys/mvvmfx/internal/viewloader/JavaViewLoader.java
public <ViewType extends View<? extends ViewModelType>, ViewModelType extends ViewModel> ViewTuple<ViewType, ViewModelType> loadJavaViewTuple(
            Class<? extends ViewType> viewType, ResourceBundle resourceBundle, final ViewModelType existingViewModel,
            ViewType codeBehind, Context parentContext, Collection<Scope> providedScopes) {

        // FIXME Woanders hin?!
        ContextImpl context = ViewLoaderScopeUtils.prepareContext(parentContext, providedScopes);
        ////////////////////////////

        DependencyInjector injectionFacade = DependencyInjector.getInstance();

        final ViewType view = codeBehind == null ? injectionFacade.getInstanceOf(viewType) : codeBehind;

        if (!(view instanceof Parent)) {
            throw new IllegalArgumentException("Can not load java view! The view class has to extend from "
                    + Parent.class.getName() + " or one of it's subclasses");
        }

        ViewModelType viewModel = null;

        // when no viewmodel was provided by the user...
        if (existingViewModel == null) {
            // ... we create a new one (if possible)
            viewModel = ViewLoaderReflectionUtils.createViewModel(view);
        } else {
            viewModel = existingViewModel;
        }

        ResourceBundleInjector.injectResourceBundle(view, resourceBundle);

        // if no ViewModel is available...
        if (viewModel == null) {
            // we need to check if the user is trying to inject a viewModel.

            final List<Field> viewModelFields = ViewLoaderReflectionUtils.getViewModelFields(viewType);

            if (!viewModelFields.isEmpty()) {
                throw new RuntimeException("The given view of type <" + view.getClass()
                        + "> has no generic viewModel type declared but tries to inject a viewModel.");
            }

        } else {
            ResourceBundleInjector.injectResourceBundle(viewModel, resourceBundle);

            // if the user has provided an existing ViewModel, we will not
            // (re-)initialize this existing instance
            ViewLoaderReflectionUtils.createAndInjectScopes(viewModel, context);
            if (existingViewModel == null) {
                ViewLoaderReflectionUtils.initializeViewModel(viewModel);
            }

            ViewLoaderReflectionUtils.injectViewModel(view, viewModel);
        }

        if (view instanceof Initializable) {
            Initializable initializable = (Initializable) view;
            initializable.initialize(null, resourceBundle);
        } else {
            injectResourceBundle(view, resourceBundle);
            callInitialize(view);
        }

        return new ViewTuple<>(view, (Parent) view, viewModel);
    }
public <ViewType extends View<? extends ViewModelType>, ViewModelType extends ViewModel> ViewTuple<ViewType, ViewModelType> loadJavaViewTuple(
            Class<? extends ViewType> viewType, ResourceBundle resourceBundle, final ViewModelType existingViewModel,
            ViewType codeBehind, Context parentContext, Collection<Scope> providedScopes) {

        // FIXME Woanders hin?!
        ContextImpl context = ViewLoaderScopeUtils.prepareContext(parentContext, providedScopes);
        ////////////////////////////

        DependencyInjector injectionFacade = DependencyInjector.getInstance();

        final ViewType view = codeBehind == null ? injectionFacade.getInstanceOf(viewType) : codeBehind;

        if (!(view instanceof Parent)) {
            throw new IllegalArgumentException("Can not load java view! The view class has to extend from "
                    + Parent.class.getName() + " or one of it's subclasses");
        }

        ViewModelType viewModel = null;

        // when no viewmodel was provided by the user...
        if (existingViewModel == null) {
            // ... we create a new one (if possible)
            viewModel = ViewLoaderReflectionUtils.createViewModel(view);
        } else {
            viewModel = existingViewModel;
        }

        ResourceBundleInjector.injectResourceBundle(view, resourceBundle);

        // if no ViewModel is available...
        if (viewModel == null) {
            // we need to check if the user is trying to inject a viewModel.

            final List<Field> viewModelFields = ViewLoaderReflectionUtils.getViewModelFields(viewType);

            if (!viewModelFields.isEmpty()) {
                throw new RuntimeException("The given view of type <" + view.getClass()
                        + "> has no generic viewModel type declared but tries to inject a viewModel.");
            }

        } else {
            ResourceBundleInjector.injectResourceBundle(viewModel, resourceBundle);

            // if the user has provided an existing ViewModel, we will not
            // (re-)initialize this existing instance
            ViewLoaderReflectionUtils.createAndInjectScopes(viewModel, context);
            if (existingViewModel == null) {
                ViewLoaderReflectionUtils.initializeViewModel(viewModel);
            }

            ViewLoaderReflectionUtils.injectViewModel(view, viewModel);
        }

        if (view instanceof Initializable) {
            Initializable initializable = (Initializable) view;
            initializable.initialize(null, resourceBundle);
        } else {
            injectResourceBundle(view, resourceBundle);
            callInitialize(view);
        }

        return new ViewTuple<>(view, (Parent) view, viewModel);
    }
public < ViewType extends View < ? extends ViewModelType > , ViewModelType extends ViewModel > ViewTuple < ViewType , ViewModelType > loadJavaViewTuple ( Class < ? extends ViewType > viewType , ResourceBundle resourceBundle , final ViewModelType existingViewModel , ViewType codeBehind , Context parentContext , Collection < Scope > providedScopes ) { // FIXME Woanders hin?! ContextImpl context = ViewLoaderScopeUtils . prepareContext ( parentContext , providedScopes ) ; //////////////////////////// DependencyInjector injectionFacade = DependencyInjector . getInstance ( ) ; final ViewType view = codeBehind == null ? injectionFacade . getInstanceOf ( viewType ) : codeBehind ; if ( ! ( view instanceof Parent ) ) { throw new IllegalArgumentException ( "Can not load java view! The view class has to extend from " + Parent . class . getName ( ) + " or one of it's subclasses" ) ; } ViewModelType viewModel = null ; // when no viewmodel was provided by the user... if ( existingViewModel == null ) { // ... we create a new one (if possible) viewModel = ViewLoaderReflectionUtils . createViewModel ( view ) ; } else { viewModel = existingViewModel ; } ResourceBundleInjector . injectResourceBundle ( view , resourceBundle ) ; // if no ViewModel is available... if ( viewModel == null ) { // we need to check if the user is trying to inject a viewModel. final List < Field > viewModelFields = ViewLoaderReflectionUtils . getViewModelFields ( viewType ) ; if ( ! viewModelFields . isEmpty ( ) ) { throw new RuntimeException ( "The given view of type <" + view . getClass ( ) + "> has no generic viewModel type declared but tries to inject a viewModel." ) ; } } else { ResourceBundleInjector . injectResourceBundle ( viewModel , resourceBundle ) ; // if the user has provided an existing ViewModel, we will not // (re-)initialize this existing instance ViewLoaderReflectionUtils . createAndInjectScopes ( viewModel , context ) ; if ( existingViewModel == null ) { ViewLoaderReflectionUtils . initializeViewModel ( viewModel ) ; } ViewLoaderReflectionUtils . injectViewModel ( view , viewModel ) ; } if ( view instanceof Initializable ) { Initializable initializable = ( Initializable ) view ; initializable . initialize ( null , resourceBundle ) ; } else { injectResourceBundle ( view , resourceBundle ) ; callInitialize ( view ) ; } return new ViewTuple <> ( view , ( Parent ) view , viewModel ) ; }
Loads the java written view of the given type and injects the ViewModel
for this view. <br>
If the given view type implements the {@link javafx.fxml.Initializable}
interface the "initialize" method of this interface will be invoked. When
this is not the case an implicit initialization will be done that is
working similar to the way the {@link javafx.fxml.FXMLLoader} is working.
<br>
When there is a <strong>public</strong> no-args method named "initialize"
is available this method will be called. When there is a
<strong>public</strong> field of type {@link java.util.ResourceBundle}
named "resources" is available this field will get the provided
ResourceBundle injected. <br>
The "initialize" method (whether from the
{@link javafx.fxml.Initializable} interface or implicit) will be invoked
<strong>after</strong> the viewModel was injected. This way the user can
create bindings to the viewModel in the initialize method.

@param viewType
class of the view.
@param resourceBundle
optional ResourceBundle that will be injected into the view.
@param existingViewModel
the viewModel instance that is used to load the view.
@param <ViewType>
the generic type of the view.
@param <ViewModelType>
the generic type of the viewModel.

@return a fully loaded and initialized instance of the view.
Loads the java written view of the given type and injects the ViewModel for this view . <br > If the given view type implements the { @link javafx . fxml . Initializable } interface the initialize method of this interface will be invoked . When this is not the case an implicit initialization will be done that is working similar to the way the { @link javafx . fxml . FXMLLoader } is working . <br > When there is a <strong > public< / strong > no - args method named initialize is available this method will be called . When there is a <strong > public< / strong > field of type { @link java . util . ResourceBundle } named resources is available this field will get the provided ResourceBundle injected . <br > The initialize method ( whether from the { @link javafx . fxml . Initializable } interface or implicit ) will be invoked <strong > after< / strong > the viewModel was injected . This way the user can create bindings to the viewModel in the initialize method .