1919import java .io .IOException ;
2020import java .io .PrintWriter ;
2121import java .io .StringWriter ;
22- import java .util .List ;
2322
23+ import de .doubleslash .keeptask .common .FxmlLayout ;
2424import de .doubleslash .keeptask .common .Resources ;
2525import de .doubleslash .keeptask .common .Resources .RESOURCE ;
26- import de .doubleslash .keeptask .common . WorkItem ;
26+ import de .doubleslash .keeptask .view . MainWindowController ;
2727import javafx .fxml .FXMLLoader ;
2828import javafx .scene .Scene ;
2929import javafx .scene .image .Image ;
3939import de .doubleslash .keeptask .common .FontProvider ;
4040import de .doubleslash .keeptask .controller .Controller ;
4141import de .doubleslash .keeptask .model .Model ;
42- import de .doubleslash .keeptask .view .ViewController ;
43- import de .doubleslash .keeptask .viewpopup .GlobalScreenListener ;
4442import javafx .application .Application ;
4543import javafx .scene .control .Alert ;
4644import javafx .scene .control .Alert .AlertType ;
@@ -63,9 +61,7 @@ public class App extends Application {
6361
6462 private Controller controller ;
6563
66- private ViewController viewController ;
67-
68- private GlobalScreenListener globalScreenListener ;
64+ private MainWindowController viewController ;
6965
7066 @ Override
7167 public void init () throws Exception {
@@ -77,9 +73,9 @@ public void init() throws Exception {
7773 ApplicationProperties applicationProperties = springContext .getBean (ApplicationProperties .class );
7874 LOG .info ("KeepTask Version: '{}'." , applicationProperties .getBuildVersion ());
7975 LOG .info ("KeepTask Build Timestamp: '{}'." , applicationProperties .getBuildTimestamp ());
80- LOG .info ("KeepTask Git Infos: id '{}', branch '{}', time '{}', dirty '{}'." ,
81- applicationProperties . getGitCommitId (), applicationProperties . getGitBranch (),
82- applicationProperties . getGitCommitTime (), applicationProperties . getGitDirty () );
76+ LOG .info ("KeepTask Git Infos: id '{}', branch '{}', time '{}', dirty '{}'." , applicationProperties . getGitCommitId (), applicationProperties . getGitBranch (), applicationProperties . getGitCommitTime (), applicationProperties . getGitDirty ());
77+
78+ FxmlLayout . setContext ( springContext );
8379
8480 model = springContext .getBean (Model .class );
8581 controller = springContext .getBean (Controller .class );
@@ -93,73 +89,76 @@ public void start(final Stage primaryStage) {
9389 LOG .info ("UI successfully initialised." );
9490 } catch (final Exception e ) {
9591 LOG .error ("There was an error while initialising the UI" , e );
96-
97- final Alert alert = new Alert (AlertType .ERROR );
98- alert .setTitle ("Error" );
99- alert .setHeaderText ("Could not start application" );
100- alert .setContentText ("Please send the error with your logs folder to a developer" );
101-
102- final StringWriter sw = new StringWriter ();
103- final PrintWriter pw = new PrintWriter (sw );
104- e .printStackTrace (pw );
105- final String exceptionText = sw .toString ();
106-
107- final Label label = new Label ("The exception stacktrace was:" );
108-
109- final TextArea textArea = new TextArea (exceptionText );
110- textArea .setEditable (false );
111- textArea .setWrapText (true );
112-
113- textArea .setMaxWidth (Double .MAX_VALUE );
114- textArea .setMaxHeight (Double .MAX_VALUE );
115- GridPane .setVgrow (textArea , Priority .ALWAYS );
116- GridPane .setHgrow (textArea , Priority .ALWAYS );
117-
118- final GridPane expContent = new GridPane ();
119- expContent .setMaxWidth (Double .MAX_VALUE );
120- expContent .add (label , 0 , 0 );
121- expContent .add (textArea , 0 , 1 );
122-
123- alert .getDialogPane ().setExpandableContent (expContent );
124- alert .showAndWait ();
125- System .exit (1 );
92+ showExceptionAndExit (e );
12693 }
12794 }
12895
96+
12997 private void initialiseApplication (final Stage primaryStage ) throws Exception {
13098 FontProvider .loadFonts ();
13199
132- List <WorkItem > workItems = model .getWorkItemRepository ().findAll ();
133- model .setWorkItems (workItems );
100+ controller .init ();
134101
135- initialiseUI (primaryStage );
102+ initialiseAndShowUI (primaryStage );
136103 }
137104
138- private void initialiseUI (final Stage primaryStage ) throws IOException {
105+ private void initialiseAndShowUI (final Stage primaryStage ) throws IOException {
139106 LOG .debug ("Initialising main UI." );
140-
141- // Load root layout from fxml file.
142- final FXMLLoader loader = new FXMLLoader ();
143- loader .setLocation (Resources .getResource (RESOURCE .FXML_VIEW_LAYOUT ));
144- loader .setControllerFactory (springContext ::getBean );
145- final Pane mainPane = loader .load ();
107+ primaryStage .setTitle ("KeepTask" );
146108 primaryStage .initStyle (StageStyle .TRANSPARENT );
147109 primaryStage .getIcons ().add (new Image (Resources .getResource (RESOURCE .ICON_MAIN ).toString ()));
148- // Show the scene containing the root layout.
149- final Scene mainScene = new Scene (mainPane , Color .TRANSPARENT );
150-
151-
152- primaryStage .setTitle ("KeepTask" );
153- primaryStage .setScene (mainScene );
154110 primaryStage .setAlwaysOnTop (true );
155111 primaryStage .setResizable (false );
156-
157112 primaryStage .setOnCloseRequest (windowEvent -> LOG .info ("On close request" ));
158113
159- primaryStage .show ();
114+ final FXMLLoader loader = FxmlLayout .createLoaderFor (RESOURCE .FXML_VIEW_LAYOUT );
115+
116+ final Pane mainPane = loader .load ();
160117 viewController = loader .getController ();
161118 viewController .setMainStage (primaryStage );
162119
120+ final Scene mainScene = new Scene (mainPane , Color .TRANSPARENT );
121+ primaryStage .setScene (mainScene );
122+
123+ primaryStage .show ();
124+ }
125+
126+ private static void showExceptionAndExit (Exception e ) {
127+ final Alert alert = new Alert (AlertType .ERROR );
128+ alert .setTitle ("Error" );
129+ alert .setHeaderText ("Could not start application" );
130+ alert .setContentText ("Please send the error with your logs folder to a developer" );
131+
132+ final String exceptionText = getExceptionAsString (e );
133+
134+ final Label label = new Label ("The exception stacktrace was:" );
135+
136+ final TextArea textArea = new TextArea (exceptionText );
137+ textArea .setEditable (false );
138+ textArea .setWrapText (true );
139+
140+ textArea .setMaxWidth (Double .MAX_VALUE );
141+ textArea .setMaxHeight (Double .MAX_VALUE );
142+ GridPane .setVgrow (textArea , Priority .ALWAYS );
143+ GridPane .setHgrow (textArea , Priority .ALWAYS );
144+
145+ final GridPane expContent = new GridPane ();
146+ expContent .setMaxWidth (Double .MAX_VALUE );
147+ expContent .add (label , 0 , 0 );
148+ expContent .add (textArea , 0 , 1 );
149+
150+ alert .getDialogPane ().setExpandableContent (expContent );
151+
152+ alert .showAndWait ();
153+ System .exit (1 );
154+ }
155+
156+ private static String getExceptionAsString (Exception e ) {
157+ final StringWriter sw = new StringWriter ();
158+ final PrintWriter pw = new PrintWriter (sw );
159+ e .printStackTrace (pw );
160+ final String exceptionText = sw .toString ();
161+ return exceptionText ;
163162 }
164163
165164 @ Override
0 commit comments