1919import de .doubleslash .keeptime .model .Project ;
2020import de .doubleslash .keeptime .model .Settings ;
2121import de .doubleslash .keeptime .model .Work ;
22- import de .doubleslash .keeptime .model .repos .ProjectRepository ;
23- import de .doubleslash .keeptime .model .repos .SettingsRepository ;
24- import de .doubleslash .keeptime .model .repos .WorkRepository ;
2522import de .doubleslash .keeptime .view .ViewController ;
2623import de .doubleslash .keeptime .viewPopup .GlobalScreenListener ;
2724import de .doubleslash .keeptime .viewPopup .ViewControllerPopup ;
@@ -44,35 +41,27 @@ public class Main extends Application {
4441 public static Stage stage ;
4542 Stage popupViewStage ;
4643
47- private final Logger Log = LoggerFactory .getLogger (this .getClass ());
44+ private final Logger LOG = LoggerFactory .getLogger (this .getClass ());
4845
49- public static Model model ;
46+ private Model model ;
5047 private Controller controller ;
5148
52- public static ProjectRepository projectRepository ;
53-
54- public static WorkRepository workRepository ;
55- public static SettingsRepository settingsRepository ;
56-
5749 @ Override
5850 public void init () throws Exception {
5951 springContext = SpringApplication .run (Main .class );
52+ // TODO test if everywhere is used the same model
53+ model = springContext .getBean (Model .class );
54+ controller = springContext .getBean (Controller .class );
6055 }
6156
6257 @ Override
6358 public void start (final Stage primaryStage ) throws Exception {
6459 stage = primaryStage ;
6560
66- Log .debug ("Reading configuration" );
67- model = springContext .getBean (Model .class );
68-
69- projectRepository = springContext .getBean (ProjectRepository .class );
70- workRepository = springContext .getBean (WorkRepository .class );
71- settingsRepository = springContext .getBean (SettingsRepository .class );
72- // TODO how to do data migration for updates??
61+ LOG .debug ("Reading configuration" );
7362
7463 // TODO there should just be one instance of settings in the repo
75- final List <Settings > settingsList = settingsRepository .findAll ();
64+ final List <Settings > settingsList = model . settingsRepository .findAll ();
7665 final Settings settings ;
7766 if (settingsList .isEmpty ()) {
7867 settings = new Settings ();
@@ -85,7 +74,7 @@ public void start(final Stage primaryStage) throws Exception {
8574 settings .setHoverFontColor (model .hoverFontColor .get ());
8675 settings .setUseHotkey (false );
8776 settings .setDisplayProjectsRight (false );
88- settingsRepository .save (settings );
77+ model . settingsRepository .save (settings );
8978 } else {
9079 settings = settingsList .get (0 );
9180 }
@@ -98,19 +87,19 @@ public void start(final Stage primaryStage) throws Exception {
9887 model .useHotkey .set (settings .isUseHotkey ());
9988 model .displayProjectsRight .set (settings .isDisplayProjectsRight ());
10089
101- final List <Work > todaysWorkItems = workRepository .findByCreationDate (LocalDate .now ());
102- Log .info ("Found {} past work items" , todaysWorkItems .size ());
90+ final List <Work > todaysWorkItems = model . workRepository .findByCreationDate (LocalDate .now ());
91+ LOG .info ("Found {} past work items" , todaysWorkItems .size ());
10392 model .pastWorkItems .addAll (todaysWorkItems );
10493
10594 // createProjects();
10695
107- final List <Project > projects = projectRepository .findAll ();
96+ final List <Project > projects = model . projectRepository .findAll ();
10897
109- Log .debug ("Found '{}' projects" , projects .size ());
98+ LOG .debug ("Found '{}' projects" , projects .size ());
11099 if (projects .isEmpty ()) {
111- Log .info ("Adding default project" );
100+ LOG .info ("Adding default project" );
112101 projects .add (model .DEFAULT_PROJECT );
113- projectRepository .save (model .DEFAULT_PROJECT );
102+ model . projectRepository .save (model .DEFAULT_PROJECT );
114103 }
115104
116105 model .allProjects .addAll (projects );
@@ -121,7 +110,7 @@ public void start(final Stage primaryStage) throws Exception {
121110 final Optional <Project > findAny = projects .stream ().filter (p -> p .isDefault ()).findAny ();
122111 if (findAny .isPresent ()) {
123112 model .idleProject = findAny .get ();
124- Log .debug ("Using project '{}' as default project." , model .idleProject );
113+ LOG .debug ("Using project '{}' as default project." , model .idleProject );
125114 }
126115
127116 primaryStage .setOnHiding ((we ) -> {
@@ -185,7 +174,7 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
185174 }
186175
187176 private void shutdown () {
188- Log .info ("Shutting down" );
177+ LOG .info ("Shutting down" );
189178 // viewController.changeProject(model.idleProject, 0); // TODO not so nice (view has the comments for the current
190179 // // job)
191180 controller .shutdown ();
@@ -216,7 +205,7 @@ private void initialiseUI(final Stage primaryStage) {
216205 primaryStage .setOnCloseRequest (new EventHandler <WindowEvent >() {
217206 @ Override
218207 public void handle (final WindowEvent event ) {
219- Log .info ("On close request" );
208+ LOG .info ("On close request" );
220209 // shutdown();
221210 // Platform.exit();
222211 }
@@ -226,14 +215,14 @@ public void handle(final WindowEvent event) {
226215 // Give the controller access to the main app.
227216 viewController .setStage (primaryStage );
228217
229- controller = springContext .getBean (Controller .class , model );
218+ // controller = springContext.getBean(Controller.class, model, new RealDateProvider() );
230219
231220 viewController .setController (controller , model );
232221
233222 primaryStage .show ();
234223
235224 } catch (final Exception e ) {
236- Log .error ("Error: " + e .toString (), e );
225+ LOG .error ("Error: " + e .toString (), e );
237226 e .printStackTrace ();
238227 }
239228 }
0 commit comments