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,28 @@ 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 {
64- stage = primaryStage ;
6559
66- Log .debug ("Reading configuration" );
67- model = springContext .getBean (Model .class );
60+ stage = primaryStage ;
6861
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??
62+ LOG .debug ("Reading configuration" );
7363
7464 // TODO there should just be one instance of settings in the repo
75- final List <Settings > settingsList = settingsRepository .findAll ();
65+ final List <Settings > settingsList = model . settingsRepository .findAll ();
7666 final Settings settings ;
7767 if (settingsList .isEmpty ()) {
7868 settings = new Settings ();
@@ -85,7 +75,7 @@ public void start(final Stage primaryStage) throws Exception {
8575 settings .setHoverFontColor (model .hoverFontColor .get ());
8676 settings .setUseHotkey (false );
8777 settings .setDisplayProjectsRight (false );
88- settingsRepository .save (settings );
78+ model . settingsRepository .save (settings );
8979 } else {
9080 settings = settingsList .get (0 );
9181 }
@@ -98,19 +88,19 @@ public void start(final Stage primaryStage) throws Exception {
9888 model .useHotkey .set (settings .isUseHotkey ());
9989 model .displayProjectsRight .set (settings .isDisplayProjectsRight ());
10090
101- final List <Work > todaysWorkItems = workRepository .findByCreationDate (LocalDate .now ());
102- Log .info ("Found {} past work items" , todaysWorkItems .size ());
91+ final List <Work > todaysWorkItems = model . workRepository .findByCreationDate (LocalDate .now ());
92+ LOG .info ("Found {} past work items" , todaysWorkItems .size ());
10393 model .pastWorkItems .addAll (todaysWorkItems );
10494
10595 // createProjects();
10696
107- final List <Project > projects = projectRepository .findAll ();
97+ final List <Project > projects = model . projectRepository .findAll ();
10898
109- Log .debug ("Found '{}' projects" , projects .size ());
99+ LOG .debug ("Found '{}' projects" , projects .size ());
110100 if (projects .isEmpty ()) {
111- Log .info ("Adding default project" );
101+ LOG .info ("Adding default project" );
112102 projects .add (model .DEFAULT_PROJECT );
113- projectRepository .save (model .DEFAULT_PROJECT );
103+ model . projectRepository .save (model .DEFAULT_PROJECT );
114104 }
115105
116106 model .allProjects .addAll (projects );
@@ -121,7 +111,7 @@ public void start(final Stage primaryStage) throws Exception {
121111 final Optional <Project > findAny = projects .stream ().filter (p -> p .isDefault ()).findAny ();
122112 if (findAny .isPresent ()) {
123113 model .idleProject = findAny .get ();
124- Log .debug ("Using project '{}' as default project." , model .idleProject );
114+ LOG .debug ("Using project '{}' as default project." , model .idleProject );
125115 }
126116
127117 primaryStage .setOnHiding ((we ) -> {
@@ -185,7 +175,7 @@ private void initialisePopupUI(final Stage primaryStage) throws IOException {
185175 }
186176
187177 private void shutdown () {
188- Log .info ("Shutting down" );
178+ LOG .info ("Shutting down" );
189179 // viewController.changeProject(model.idleProject, 0); // TODO not so nice (view has the comments for the current
190180 // // job)
191181 controller .shutdown ();
@@ -216,7 +206,7 @@ private void initialiseUI(final Stage primaryStage) {
216206 primaryStage .setOnCloseRequest (new EventHandler <WindowEvent >() {
217207 @ Override
218208 public void handle (final WindowEvent event ) {
219- Log .info ("On close request" );
209+ LOG .info ("On close request" );
220210 // shutdown();
221211 // Platform.exit();
222212 }
@@ -226,14 +216,14 @@ public void handle(final WindowEvent event) {
226216 // Give the controller access to the main app.
227217 viewController .setStage (primaryStage );
228218
229- controller = springContext .getBean (Controller .class , model );
219+ // controller = springContext.getBean(Controller.class, model, new RealDateProvider() );
230220
231221 viewController .setController (controller , model );
232222
233223 primaryStage .show ();
234224
235225 } catch (final Exception e ) {
236- Log .error ("Error: " + e .toString (), e );
226+ LOG .error ("Error: " + e .toString (), e );
237227 e .printStackTrace ();
238228 }
239229 }
0 commit comments