package org.opendolphin.demo.team;

import javafx.application.Application;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.opendolphin.core.client.ClientDolphin;
import org.opendolphin.core.client.ClientModelStore;
import org.opendolphin.core.client.comm.BlindCommandBatcher;
import org.opendolphin.core.client.comm.HttpClientConnector;
import org.opendolphin.core.client.comm.JavaFXUiThreadHandler;
import org.opendolphin.core.comm.JsonCodec;

import java.io.File;
import java.net.URI;

// todo: make url base configurable from command line

public class TeamStarter {
    public static void main(String[] args) throws Exception {

        final String servletUrl = "http://localhost:8080/dolphin-grails/dolphin/";
//        final String servletUrl = "https://klondike.canoo.com/dolphin-grails/dolphin/";

        ClientDolphin clientDolphin = new ClientDolphin();
        clientDolphin.setClientModelStore(new ClientModelStore(clientDolphin));
        BlindCommandBatcher batcher = new BlindCommandBatcher();
        batcher.setMergeValueChanges(true);
        batcher.setDeferMillis(100);
        HttpClientConnector connector = new HttpClientConnector(clientDolphin, batcher, servletUrl);
        final JsonCodec codec = new JsonCodec();
        connector.setCodec(codec);
        final JavaFXUiThreadHandler uiThreadHandler = new JavaFXUiThreadHandler();
        connector.setUiThreadHandler(uiThreadHandler);
        clientDolphin.setClientConnector(connector);

        TeamApplication.clientDolphin = clientDolphin;

        String result = connector.uploadFile(new File("/data.txt"), DefaultGroovyMethods.toURI("http://localhost:8080/dolphin-grails/fileUpload/save"));
        System.out.println("uploaded and returned: "+result);

        Application.launch(TeamApplication.class);
    }
}

@@ -495,15 +495,73 @@
 ava.
-net.URI
+lang.reflect.Field;%0Aimport java.net.URI;%0Aimport java.util.HashMap
 ;%0A%0A/
@@ -704,16 +704,18 @@
 tion %7B%0A%0A
+//
         
@@ -789,18 +789,16 @@
 phin/%22;%0A
-//
         
@@ -1596,16 +1596,18 @@
 lphin;%0A%0A
+//
         
@@ -1747,24 +1747,26 @@
 ad/save%22));%0A
+//
         Syst
@@ -1812,24 +1812,455 @@
 %22+result);%0A%0A
+        // Mac-specific hack for java 7 on el capitan%0A        try %7B%0A            Class%3C?%3E macFontFinderClass = Class.forName(%22com.sun.t2k.MacFontFinder%22);%0A            Field psNameToPathMap = macFontFinderClass.getDeclaredField(%22psNameToPathMap%22);%0A            psNameToPathMap.setAccessible(true);%0A            psNameToPathMap.set(null, new HashMap%3CString, String%3E());%0A        %7D catch (Exception e) %7B%0A            // ignore%0A        %7D%0A%0A%0A
         Appl
@@ -2298,16 +2298,17 @@
 class);%0A
+%0A
     %7D%0A%7D%0A

add todo for later inspection