Skip to content

Package: JavaFXSpringAnnotationApplication

JavaFXSpringAnnotationApplication

nameinstructionbranchcomplexitylinemethod
JavaFXSpringAnnotationApplication()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
createApplicationContext()
M: 0 C: 38
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 7
100%
M: 0 C: 1
100%
lambda$createApplicationContext$0(int)
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * SteelBlue: DCI User Interfaces
5: * http://tidalwave.it/projects/steelblue
6: *
7: * Copyright (C) 2015 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * 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
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/steelblue-src
22: * git clone https://github.com/tidalwave-it/steelblue-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.ui.javafx;
27:
28: import jakarta.annotation.Nonnull;
29: import jakarta.inject.Named;
30: import java.util.ArrayList;
31: import java.util.List;
32: import org.springframework.beans.factory.BeanFactory;
33: import org.springframework.context.ConfigurableApplicationContext;
34: import org.springframework.context.annotation.AnnotationConfigApplicationContext;
35: import org.springframework.context.annotation.Bean;
36: import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
37: import it.tidalwave.ui.core.annotation.EnableMessageBus;
38: import it.tidalwave.ui.javafx.impl.DefaultJavaFXPanelGroupControl;
39: import it.tidalwave.ui.javafx.spi.AbstractJavaFXSpringApplication;
40: import org.slf4j.Logger;
41: import org.slf4j.LoggerFactory;
42: import it.tidalwave.util.PreferencesHandler;
43: import it.tidalwave.messagebus.MessageBus;
44: import it.tidalwave.messagebus.spi.SimpleMessageBus;
45:
46: /***************************************************************************************************************************************************************
47: *
48: * A base class for JavaFX applications with use Spring annotation scanning.
49: *
50: * @author Fabrizio Giudici
51: * @since 1.1-ALPHA-4
52: *
53: **************************************************************************************************************************************************************/
54: public class JavaFXSpringAnnotationApplication extends AbstractJavaFXSpringApplication
55: {
56: /***********************************************************************************************************************************************************
57: * Base bean factory.
58: **********************************************************************************************************************************************************/
59: private class Beans
60: {
61: @Bean
62: public ThreadPoolTaskExecutor javafxBinderExecutor()
63: {
64: return executor;
65: }
66:
67: @Bean
68: public PreferencesHandler preferencesHandler()
69: {
70: return PreferencesHandler.getInstance();
71: }
72:
73: @Bean
74: public JavaFXToolBarControl toolBarControl()
75: {
76: return toolBarControl;
77: }
78:
79: @Bean
80: public JavaFXMenuBarControl menuBarControl()
81: {
82: return menuBarControl;
83: }
84:
85: @Bean
86: public JavaFXPanelGroupControl panelGroupControl (@Nonnull final BeanFactory beanFactory)
87: {
88: return new DefaultJavaFXPanelGroupControl(beanFactory);
89: }
90: }
91:
92: /***********************************************************************************************************************************************************
93: * Auxiliary bean factory for message bus.
94: **********************************************************************************************************************************************************/
95: private static class MessageBusBeans
96: {
97: @Bean(name = MESSAGE_BUS_EXECUTOR_BEAN_NAME)
98: public ThreadPoolTaskExecutor applicationMessageBusExecutor()
99: {
100: final var executor = new ThreadPoolTaskExecutor();
101: executor.setWaitForTasksToCompleteOnShutdown(false);
102: executor.setThreadNamePrefix("messageBus-");
103: executor.setCorePoolSize(10);
104: executor.setMaxPoolSize(10);
105: executor.setQueueCapacity(10);
106: return executor;
107: }
108:
109: @Bean(name = APPLICATION_MESSAGE_BUS_BEAN_NAME)
110: public MessageBus applicationMessageBus (@Named(MESSAGE_BUS_EXECUTOR_BEAN_NAME) final ThreadPoolTaskExecutor executor)
111: {
112: return new SimpleMessageBus(executor);
113: }
114: }
115:
116: public static final String MESSAGE_BUS_EXECUTOR_BEAN_NAME = "applicationMessageBusExecutor";
117:
118: // Don't use Slf4j and its static logger - give Main a chance to initialize things
119: private final Logger log = LoggerFactory.getLogger(JavaFXSpringAnnotationApplication.class);
120:
121: /***********************************************************************************************************************************************************
122: * {@inheritDoc}
123: **********************************************************************************************************************************************************/
124: @Override @Nonnull
125: protected ConfigurableApplicationContext createApplicationContext()
126: {
127: final var mainClass = getClass();
128: final var componentClasses = new ArrayList<>(List.of(mainClass, Beans.class));
129:
130:• if (getClass().isAnnotationPresent(EnableMessageBus.class))
131: {
132: log.info("Detected @{}, enabling message bus", EnableMessageBus.class.getSimpleName());
133: componentClasses.add(MessageBusBeans.class);
134: }
135:
136: log.info("Scanning beans from {}", mainClass);
137: return new AnnotationConfigApplicationContext(componentClasses.toArray(Class<?>[]::new));
138: }
139: }