package moe.tristan.easyfxml.model.fxml;

import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import moe.tristan.easyfxml.EasyFxml;
import moe.tristan.easyfxml.model.FxmlNode;
import moe.tristan.easyfxml.model.exception.ExceptionPane;
import moe.tristan.easyfxml.model.exception.ExceptionPaneBehavior;
import moe.tristan.easyfxml.util.StageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

/**
 * The {@link ViewsLoader} is a convenience {@link Service} acting as
 * a safe decorator around {@link EasyFxml} for error-handling.
 *
 * It provides :
 * - Error handling ({@link #loadingError(Throwable)}
 * - Error styles {@link ExceptionPaneBehavior}
 *
 * It is recommended to use it but {@link EasyFxml} works fine without it.
 */
@Component
public class ViewsLoader {
    private static final Logger LOG = LoggerFactory.getLogger(ViewsLoader.class);

    private final ApplicationContext context;

    @Autowired
    public ViewsLoader(final ApplicationContext context) {
        this.context = context;
    }

    public Pane loadPaneForNode(final FxmlNode fxmlNode, final ExceptionPaneBehavior onExceptionBehavior) {
        LOG.debug("Loading view : {} [{}]", fxmlNode, fxmlNode.getFxmlFile().getPath());
        final EasyFxml easyFxml = this.context.getBean(EasyFxml.class);
        return easyFxml.loadNode(fxmlNode).getOrElseGet(exception -> {
            switch (onExceptionBehavior) {
                case INLINE:
                    return this.loadingError(exception);
                case DIALOG:
                    this.loadingErrorDialog(exception);
                    return new Pane(new Label("An exception occured. See dialog and/or logs."));
                default:
                    throw new RuntimeException("Error behavior was not recognized. Was \""+ onExceptionBehavior +"\".");
            }
        });
    }

    private Pane loadingError(final Throwable exception) {
        LOG.error("Got exception loading view ! See stacktrace : ", exception);
        return new ExceptionPane(exception).asPane("Could not load component :( Details :");
    }

    private void loadingErrorDialog(final Throwable exception) {
        final Pane errPane = this.loadingError(exception);
        final Stage errorStage = StageUtils.stageOf("An error has occured", errPane);
        StageUtils.scheduleDisplaying(errorStage);
    }
}

@@ -507,112 +507,8 @@
 ed;%0A
-import org.springframework.context.ApplicationContext;%0Aimport org.springframework.stereotype.Component;%0A
 impo
@@ -898,17 +898,15 @@
 */%0A@
-Component
+Service
 %0Apub
@@ -1034,34 +1034,25 @@
 nal 
-ApplicationContext context
+EasyFxml easyFxml
 ;%0A%0A 
@@ -1098,68 +1098,61 @@
 nal 
-ApplicationContext context) %7B%0A        this.context = context
+EasyFxml easyFxml) %7B%0A        this.easyFxml = easyFxml
 ;%0A  
@@ -1357,80 +1357,8 @@
 ));%0A
-        final EasyFxml easyFxml = this.context.getBean(EasyFxml.class);%0A
     
@@ -1368,16 +1368,21 @@
  return 
+this.
 easyFxml

Make ViewsLoader reuse EasyFxml as it is made ot be reusable and encapsulate FXMLLoader cycling