org.bidib.wizard.config.ApplicationRunnerConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bidibwizard-client Show documentation
Show all versions of bidibwizard-client Show documentation
jBiDiB BiDiB Wizard Client Application POM
package org.bidib.wizard.config;
import java.awt.EventQueue;
import javax.swing.RepaintManager;
import org.apache.commons.lang3.SystemUtils;
import org.bidib.wizard.api.context.ApplicationContext;
import org.bidib.wizard.client.common.boot.SwingApplicationInitializer;
import org.bidib.wizard.common.context.DefaultApplicationContext;
import org.bidib.wizard.main.BiDiBWizardStandaloneApplication;
import org.bidib.wizard.mvc.error.controller.ErrorController;
import org.bidib.wizard.mvc.main.controller.DefaultBidibPiController;
import org.bidib.wizard.mvc.main.controller.MainController;
import org.bidib.wizard.utils.ThreadCheckingRepaintManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ApplicationRunnerConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationRunnerConfig.class);
@Bean
SwingApplicationInitializer swingApplicationInitializer(
final org.springframework.context.ApplicationContext context) {
return new SwingApplicationInitializer(context);
}
@Bean
ApplicationRunner applicationRunner(final org.springframework.context.ApplicationContext ctx) {
return args -> {
EventQueue.invokeLater(() -> {
LOGGER.info("Create the application context from the EDT. Started the spring boot application.");
try {
RepaintManager.setCurrentManager(new ThreadCheckingRepaintManager());
final ApplicationArguments applicationArguments =
ctx.getBean("springApplicationArguments", ApplicationArguments.class);
SwingApplicationInitializer swingApplicationInitializer =
ctx.getBean(SwingApplicationInitializer.class);
swingApplicationInitializer.run(applicationArguments);
MainController mainController = ctx.getBean(MainController.class);
// TODO this is a hack
ApplicationContext applicationContext = DefaultApplicationContext.getInstance();
applicationContext.register(DefaultApplicationContext.KEY_SPRINGCONTEXT, ctx);
if (SystemUtils.IS_OS_LINUX) {
LoggerFactory
.getLogger(BiDiBWizardStandaloneApplication.class)
.info("Check if we are running on BiDiB-Pi infrastructure.");
try {
DefaultBidibPiController bidibPiController = new DefaultBidibPiController();
bidibPiController.start(applicationContext);
LoggerFactory
.getLogger(BiDiBWizardStandaloneApplication.class)
.info("The Pi connector was initialized.");
}
catch (IllegalArgumentException ex) {
LoggerFactory
.getLogger(BiDiBWizardStandaloneApplication.class)
.warn("The Pi connector was not initialized.");
}
}
new ErrorController().start(() -> mainController.hasStartupPassed());
mainController.start();
LOGGER.info("Start application passed.");
}
catch (Exception ex) {
LOGGER.warn("Start application failed.", ex);
SpringApplication.exit(ctx, () -> 1);
}
});
};
};
}