|
8 | 8 | import com.thecoderscorner.embedcontrol.customization.MenuItemStore; |
9 | 9 | import com.thecoderscorner.embedcontrol.jfx.controlmgr.JfxNavigationHeader; |
10 | 10 | import com.thecoderscorner.embedcontrol.jfx.controlmgr.JfxNavigationManager; |
| 11 | +import com.thecoderscorner.menu.auth.MenuAuthenticator; |
11 | 12 | import com.thecoderscorner.menu.auth.PropertiesAuthenticator; |
12 | 13 | import com.thecoderscorner.menu.mgr.MenuManagerServer; |
13 | 14 | import com.thecoderscorner.menu.persist.LocaleMappingHandler; |
14 | 15 | import com.thecoderscorner.menu.persist.PropertiesMenuStateSerialiser; |
15 | 16 | import com.thecoderscorner.menu.persist.VersionInfo; |
16 | | -import com.thecoderscorner.menu.remote.mgrclient.SocketServerConnectionManager; |
17 | 17 | import com.thecoderscorner.menu.remote.protocol.ConfigurableProtocolConverter; |
18 | 18 | import com.thecoderscorner.menuexample.tcmenu.plugins.TcJettyWebServer; |
19 | 19 |
|
|
25 | 25 |
|
26 | 26 | /** |
27 | 27 | * This class creates an application context out of all these components, and you can request any components that are |
28 | | - * put into the context using getBean(ClassName.class). |
| 28 | + * put into the context using getBean(ClassName.class). See the base class BaseMenuConfig for more details. Generally |
| 29 | + * don't change the constructor, as it is rebuild each time around. Prefer putting your own code in appCustomConfiguration |
29 | 30 | */ |
30 | 31 | public class MenuConfig extends BaseMenuConfig { |
31 | | - public MenuConfig(String env) { |
32 | | - super(null, env); |
33 | | - var executorService = asBean(Executors.newScheduledThreadPool(propAsIntWithDefault("threading.pool.size", 4))); |
34 | | - var menuDef = asBean(new EmbeddedJavaDemoMenu()); |
35 | | - |
36 | | - asBean(new PropertiesMenuStateSerialiser(menuDef.getMenuTree(), Path.of(resolvedProperties.getProperty("file.menu.storage")).resolve("menuStorage.properties"))); |
37 | | - |
38 | | - var settings = asBean(new GlobalSettings(new ApplicationThemeManager())); |
39 | | - // load or adjust the settings as needed here. You could use the JDBC components with SQLite to load and store |
40 | | - // these values just like embed control does. See TcPreferencesPersistence and TccDatabaseUtilities. |
41 | | - settings.setDefaultFontSize(14); |
42 | | - settings.setDefaultRecursiveRendering(false); |
43 | | - |
44 | | - asBean(new JfxNavigationHeader(executorService, settings)); |
45 | | - |
46 | | - asBean(new MenuItemStore(settings, menuDef.getMenuTree(), "", 7, 2, settings.isDefaultRecursiveRendering())); |
47 | | - |
48 | | - var protocol = asBean(new ConfigurableProtocolConverter(true)); |
| 32 | + @TcComponent |
| 33 | + public JfxNavigationHeader navMgr(ScheduledExecutorService executorService, GlobalSettings settings) { |
| 34 | + return new JfxNavigationHeader(executorService, settings); |
| 35 | + } |
49 | 36 |
|
50 | | - Clock clock = asBean(Clock.systemUTC()); |
51 | | - asBean(new TcJettyWebServer(protocol, clock, "./data/www", 8080, false)); |
| 37 | + @TcComponent |
| 38 | + public ConfigurableProtocolConverter protocol() { |
| 39 | + return new ConfigurableProtocolConverter(true); |
| 40 | + } |
52 | 41 |
|
53 | | - var authenticator = asBean(new PropertiesAuthenticator(mandatoryStringProp("file.auth.storage"))); |
| 42 | + @TcComponent |
| 43 | + public MenuManagerServer menuManagerServer(Clock clock, EmbeddedJavaDemoMenu menuDef, ScheduledExecutorService executorService, MenuAuthenticator authenticator) { |
| 44 | + return new MenuManagerServer(executorService, menuDef.getMenuTree(), mandatoryStringProp("server.name"), UUID.fromString(mandatoryStringProp("server.uuid")), authenticator, clock); |
| 45 | + } |
54 | 46 |
|
55 | | - asBean(new MenuManagerServer(executorService, menuDef.getMenuTree(), mandatoryStringProp("server.name"), UUID.fromString(mandatoryStringProp("server.uuid")), authenticator, clock)); |
| 47 | + @TcComponent |
| 48 | + public EmbeddedJavaDemoController menuController() { |
| 49 | + return new EmbeddedJavaDemoController( |
| 50 | + getBean(EmbeddedJavaDemoMenu.class), |
| 51 | + getBean(JfxNavigationManager.class), |
| 52 | + getBean(ScheduledExecutorService.class), |
| 53 | + getBean(GlobalSettings.class), |
| 54 | + getBean(MenuItemStore.class) |
| 55 | + ); |
| 56 | + } |
56 | 57 |
|
57 | | - asBean(new SocketServerConnectionManager(protocol, executorService, 3333, clock)); |
| 58 | + @TcComponent |
| 59 | + public MenuItemStore itemStore(GlobalSettings settings, EmbeddedJavaDemoMenu menuDef) { |
| 60 | + return new MenuItemStore(settings, menuDef.getMenuTree(), "", 7, 2, settings.isDefaultRecursiveRendering()); |
| 61 | + } |
58 | 62 |
|
59 | | - asBean(createVersionInfo()); |
| 63 | + @TcComponent |
| 64 | + public GlobalSettings globalSettings() { |
| 65 | + var settings = new GlobalSettings(new ApplicationThemeManager()); |
| 66 | + // load or adjust the settings as needed here. You could use the JDBC components with SQLite to load and store |
| 67 | + // these values just like embed control does. See TcPreferencesPersistence and TccDatabaseUtilities. |
| 68 | + settings.setDefaultFontSize(16); |
| 69 | + settings.setDefaultRecursiveRendering(false); |
| 70 | + return settings; |
| 71 | + } |
60 | 72 |
|
61 | | - scanForComponents(); |
| 73 | + @TcComponent |
| 74 | + public MenuAppVersion versionInfo() { |
| 75 | + var version = mandatoryStringProp("build.version"); |
| 76 | + var timestamp = mandatoryStringProp("build.timestamp"); |
| 77 | + var groupId = mandatoryStringProp("build.groupId"); |
| 78 | + var artifact = mandatoryStringProp("build.artifactId"); |
| 79 | + return new MenuAppVersion(new VersionInfo(version), timestamp, groupId, artifact); |
62 | 80 | } |
63 | 81 |
|
64 | 82 | @TcComponent |
65 | | - LocaleMappingHandler localeHandler() { |
| 83 | + public LocaleMappingHandler localeHandler() { |
66 | 84 | return LocaleMappingHandler.NOOP_IMPLEMENTATION; |
67 | 85 | } |
68 | 86 |
|
69 | | - void appCustomConfiguration() { |
70 | | - asBean(new EmbeddedJavaDemoController( |
71 | | - getBean(EmbeddedJavaDemoMenu.class), |
72 | | - getBean(JfxNavigationManager.class), |
73 | | - getBean(ScheduledExecutorService.class), |
74 | | - getBean(GlobalSettings.class), |
75 | | - getBean(MenuItemStore.class) |
76 | | - )); |
| 87 | + @TcComponent |
| 88 | + public MenuAuthenticator menuAuthenticator() { |
| 89 | + return new PropertiesAuthenticator(mandatoryStringProp("file.auth.storage")); |
| 90 | + } |
| 91 | + |
| 92 | + @TcComponent |
| 93 | + public ConfigurableProtocolConverter tagVal() { |
| 94 | + return new ConfigurableProtocolConverter(true); |
| 95 | + } |
77 | 96 |
|
78 | | - // you can put your configurations here, example: |
79 | | - // var myComponent = asBean(new MyOwnComponent("hello"); |
80 | | - // to later access it simple call getBean(MyOwnComponent.class) on the context. |
| 97 | + @TcComponent |
| 98 | + public TcJettyWebServer webServer(ConfigurableProtocolConverter protocol, Clock clock) { |
| 99 | + return new TcJettyWebServer(protocol, clock, "./data/www", 8080, false); |
81 | 100 | } |
82 | 101 |
|
83 | | - public MenuAppVersion createVersionInfo() { |
84 | | - return new MenuAppVersion(new VersionInfo(mandatoryStringProp("build.version")), |
85 | | - mandatoryStringProp("build.timestamp"), mandatoryStringProp("build.groupId"), |
86 | | - mandatoryStringProp("build.artifactId")); |
| 102 | + public MenuConfig() { |
| 103 | + // Do not change this constructor, it is replaced with each build, put your objects in appCustomConfiguration |
| 104 | + super(null, null); |
| 105 | + Clock clock = asBean(Clock.systemUTC()); |
| 106 | + var executorService = asBean(Executors.newScheduledThreadPool(propAsIntWithDefault("threading.pool.size", 4))); |
| 107 | + var menuDef = asBean(new EmbeddedJavaDemoMenu()); |
| 108 | + asBean(new PropertiesMenuStateSerialiser(menuDef.getMenuTree(), Path.of(resolvedProperties.getProperty("file.menu.storage")).resolve("menuStorage.properties"))); |
| 109 | + scanForComponents(); |
87 | 110 | } |
88 | 111 |
|
89 | 112 | // Auto generated menu callbacks end here. Please do not remove this line or change code after it. |
|
0 commit comments