package de.vogel612.helper;

import de.vogel612.helper.data.FilesetModel;
import de.vogel612.helper.ui.*;
import de.vogel612.helper.ui.jfx.*;

import java.nio.file.Path;
import java.nio.file.Paths;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class TranslationHelper extends Application {

    static final String ARGUMENT_MISMATCH = "Arguments do not match up. Please provide no more than a Path to the intended fileset";


    public static void main(String[] args) {
        if (args.length > 1) {
            // don't even bother!
            System.err.println(ARGUMENT_MISMATCH);
            return;
        }
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        Stage rcStage = new Stage(StageStyle.UTILITY);
        rcStage.initOwner(primaryStage);
        LocaleChooser rc = new JFXLocaleChooserView(rcStage, getClass().getResource("/LocaleChooser.fxml"));
        Parameters params = getParameters();
        if (params.getUnnamed().size() != 0) { // should be 1..
            final Path resxFile = Paths.get(params.getUnnamed().get(0));
            // FIXME show project or resx overview depending on argument
//            rc.setFileset(resxFile);
        }

        Stage translationStage = new Stage(StageStyle.UTILITY);
        translationStage.initOwner(primaryStage);
        TranslationView tv = new JFXTranslationView(translationStage, getClass().getResource("/TranslationView.fxml"));

        FilesetModel m = new FilesetModel();
        OverviewView v = new JFXTranslationOverviewView(rc, m, tv, primaryStage, getClass().getResource("/TranslationOverviewView.fxml"));
        ProjectView pv = new JFXProjectView(primaryStage, getClass().getResource("/ProjectOverview.fxml"));
        OverviewPresenter p = new OverviewPresenter(v, pv);

        Platform.runLater(p::show);
        Platform.runLater(p::fileChoosing);
    }
}

@@ -136,16 +136,44 @@
 jfx.*;%0A%0A
+import java.io.IOException;%0A
 import j
@@ -839,24 +839,25 @@
 ption %7B%0A
+%0A
         
 Stage rc
@@ -852,212 +852,76 @@
     
-Stage rcStage = new Stage(StageStyle.UTILITY);%0A        rcStage.initOwner(primaryStage);%0A        LocaleChooser rc = new JFXLocaleChooserView(rcStage, getClass().getResource(%22/LocaleChooser.fxml%22));
+// FIXME show project or resx overview depending on argument
 %0A       
  Par
@@ -916,16 +916,19 @@
 %0A       
+ //
  Paramet
@@ -960,24 +960,27 @@
 s();%0A       
+ //
  if (params.
@@ -1014,14 +1014,12 @@
  // 
-should
+must
  be 
@@ -1025,24 +1025,27 @@
  1..%0A       
+ //
      final P
@@ -1110,82 +1110,10 @@
     
-    // FIXME show project or resx overview depending on argument%0A//       
+//
     
@@ -1145,16 +1145,19 @@
 %0A       
+ //
  %7D%0A%0A    
@@ -1166,27 +1166,24 @@
   Stage 
-translation
+overview
 Stage = 
@@ -1207,15 +1207,17 @@
 yle.
-UTILITY
+DECORATED
 );%0A 
@@ -1223,27 +1223,24 @@
         
-translation
+overview
 Stage.in
@@ -1258,24 +1258,25 @@
 maryStage);%0A
+%0A
         Tran
@@ -1288,31 +1288,31 @@
 onView tv = 
-new JFX
+prepare
 TranslationV
@@ -1319,85 +1319,32 @@
 iew(
-translationStage, getClass().getResource(%22/TranslationView.fxml%22)
+overviewStage
 );%0A
-%0A
         
 File
@@ -1343,45 +1343,65 @@
     
-FilesetModel m = new FilesetModel(
+LocaleChooser rc = prepareLocaleChooser(overviewStage
 );%0A
+%0A
     
@@ -1460,22 +1460,40 @@
 rc, 
-m, tv, primary
+new FilesetModel(), tv, overview
 Stag
@@ -1807,11 +1807,622 @@
 );%0A    %7D
+%0A%0A    private LocaleChooser prepareLocaleChooser(Stage overviewStage) throws IOException %7B%0A        Stage rcStage = new Stage(StageStyle.UTILITY);%0A        rcStage.initOwner(overviewStage);%0A        return new JFXLocaleChooserView(rcStage, getClass().getResource(%22/LocaleChooser.fxml%22));%0A    %7D%0A%0A    private TranslationView prepareTranslationView(Stage overviewStage) throws IOException %7B%0A        Stage translationStage = new Stage(StageStyle.UTILITY);%0A        translationStage.initOwner(overviewStage);%0A        return new JFXTranslationView(translationStage, getClass().getResource(%22/TranslationView.fxml%22));%0A    %7D
 %0A%7D%0A

Move around some initialization and give each view a separate stage