Content of file JavaFXSpringApplication.java.html
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../../jacoco-resources/report.gif" type="image/gif"/><title>JavaFXSpringApplication.java</title><link rel="stylesheet" href="../../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../../index.html" class="el_report">SteelBlue - Examples - Large</a> > <a href="../index.html" class="el_bundle">it-tidalwave-role-ui-javafx</a> > <a href="index.source.html" class="el_package">it.tidalwave.ui.javafx</a> > <span class="el_source">JavaFXSpringApplication.java</span></div><h1>JavaFXSpringApplication.java</h1><pre class="source lang-java linenums">/*
* *********************************************************************************************************************
*
* SteelBlue: DCI User Interfaces
* http://tidalwave.it/projects/steelblue
*
* Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
*
* *********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* *********************************************************************************************************************
*
* git clone https://bitbucket.org/tidalwave/steelblue-src
* git clone https://github.com/tidalwave-it/steelblue-src
*
* *********************************************************************************************************************
*/
package it.tidalwave.ui.javafx;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.Executors;
import java.io.IOException;
import javafx.stage.Stage;
import javafx.application.Platform;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import it.tidalwave.role.ui.javafx.ApplicationPresentationAssembler;
import it.tidalwave.ui.javafx.JavaFXSafeProxyCreator.NodeAndDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
*
**********************************************************************************************************************/
<span class="nc bnc" id="L52" title="All 2 branches missed.">public class JavaFXSpringApplication extends JavaFXApplicationWithSplash</span>
{
// Don't use Slf4j and its static logger - give Main a chance to initialize things
<span class="nc" id="L55"> private final Logger log = LoggerFactory.getLogger(JavaFXSpringApplication.class);</span>
private ClassPathXmlApplicationContext applicationContext;
<span class="nc" id="L59"> private final List<String> springConfigLocations = new ArrayList<>();</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Override @Nonnull
protected NodeAndDelegate createParent()
throws IOException
{
<span class="nc" id="L70"> return NodeAndDelegate.load(getClass(), applicationFxml);</span>
}
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Override
protected void initializeInBackground()
{
<span class="nc" id="L81"> log.info("initializeInBackground()");</span>
try
{
<span class="nc" id="L85"> logProperties();</span>
// TODO: workaround for NWRCA-41
<span class="nc" id="L87"> System.setProperty("it.tidalwave.util.spring.ClassScanner.basePackages", "it");</span>
<span class="nc" id="L89"> springConfigLocations.add("classpath*:/META-INF/*AutoBeans.xml");</span>
<span class="nc" id="L90"> final String osName = System.getProperty("os.name", "").toLowerCase();</span>
<span class="nc bnc" id="L92" title="All 2 branches missed."> if (osName.contains("os x"))</span>
{
<span class="nc" id="L94"> springConfigLocations.add("classpath*:/META-INF/*AutoMacOSXBeans.xml");</span>
}
<span class="nc bnc" id="L97" title="All 2 branches missed."> if (osName.contains("linux"))</span>
{
<span class="nc" id="L99"> springConfigLocations.add("classpath*:/META-INF/*AutoLinuxBeans.xml");</span>
}
<span class="nc bnc" id="L102" title="All 2 branches missed."> if (osName.contains("windows"))</span>
{
<span class="nc" id="L104"> springConfigLocations.add("classpath*:/META-INF/*AutoWindowsBeans.xml");</span>
}
<span class="nc" id="L107"> log.info("Loading Spring configuration from {} ...", springConfigLocations);</span>
<span class="nc" id="L108"> applicationContext = new ClassPathXmlApplicationContext(springConfigLocations.toArray(new String[0]));</span>
<span class="nc" id="L109"> applicationContext.registerShutdownHook(); // this actually seems not working, onClosing() does</span>
}
<span class="nc" id="L111"> catch (Throwable t)</span>
{
<span class="nc" id="L113"> log.error("", t);</span>
<span class="nc" id="L114"> }</span>
<span class="nc" id="L115"> }</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Override
protected void onStageCreated (@Nonnull final Stage stage,
@Nonnull final NodeAndDelegate applicationNad)
{
<span class="nc bnc" id="L126" title="All 4 branches missed."> assert Platform.isFxApplicationThread();</span>
<span class="nc" id="L127"> JavaFXSafeProxyCreator.getJavaFxBinder().setMainWindow(stage);</span>
<span class="nc" id="L128"> runApplicationAssemblers(applicationNad);</span>
<span class="nc" id="L129"> Executors.newSingleThreadExecutor().execute(() -> onStageCreated(applicationContext));</span>
<span class="nc" id="L130"> }</span>
/*******************************************************************************************************************
*
* Invoked when the {@link Stage} is created and the {@link ApplicationContext} has been initialized. Typically
* the main class overrides this, retrieves a reference to the main controller and boots it.
* This method is executed in a background thread.
*
* @param applicationContext the application context
*
******************************************************************************************************************/
protected void onStageCreated (@Nonnull final ApplicationContext applicationContext)
{
<span class="nc" id="L143"> }</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
@Override
protected void onClosing()
{
<span class="nc" id="L153"> applicationContext.close();</span>
<span class="nc" id="L154"> }</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
private void runApplicationAssemblers (@Nonnull final NodeAndDelegate applicationNad)
{
<span class="nc" id="L163"> Objects.requireNonNull(applicationContext, "applicationContext is null");</span>
<span class="nc" id="L164"> applicationContext.getBeansOfType(ApplicationPresentationAssembler.class).values()</span>
<span class="nc" id="L165"> .forEach(a -> a.assemble(applicationNad.getDelegate()));</span>
<span class="nc" id="L166"> }</span>
/*******************************************************************************************************************
*
*
*
******************************************************************************************************************/
private void logProperties()
{
<span class="nc" id="L175"> final SortedMap<Object, Object> map = new TreeMap<>(System.getProperties());</span>
<span class="nc bnc" id="L177" title="All 2 branches missed."> for (final Entry<Object, Object> e : map.entrySet())</span>
{
<span class="nc" id="L179"> log.debug("{}: {}", e.getKey(), e.getValue());</span>
<span class="nc" id="L180"> }</span>
<span class="nc" id="L181"> }</span>
}
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.7.202105040129</span></div></body></html>