Subversion Repositories eFlore/Applications.cel

Rev

Rev 2615 | Blame | Last modification | View Log | RSS feed

package org.tela_botanica.client;

import org.tela_botanica.client.i18n.Msg;
import org.tela_botanica.client.modeles.objets.Configuration;

import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window.Location;
import com.gwtext.client.core.Ext;
import com.gwtext.client.widgets.Viewport;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class cel2 implements EntryPoint {

        /**
         * This is the entry point method.
         */
        @Override
        public void onModuleLoad() {    
                
                /*
                // A décommenter + compiler en detailed dans le cas d'une erreur
                // survernant uniquement sur le serveur
                GWT.setUncaughtExceptionHandler(null);
                GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {    
                        @Override
                        public void onUncaughtException(Throwable e) {
                                        Window.alert("uncaught: " + e.getMessage());
                                        String s = buildStackTrace(e, "RuntimeException:\n");
                                        Window.alert(s);
                                        e.printStackTrace();
                        }
                });
                */
                // TODO: config devrait être un singleton
                Configuration config = new Configuration();     
                // Si la langue est précisée dans l'url on la prend, sinon on prend celle par défaut
                // @TODO: avertissement si la langue indiquée dans l'url n'est pas la bonne
                String langueURL = Location.getParameter("lang");
                if (! Msg.init()) {
                        cel2.LogVersFirebug("La langue par défaut \"" + Msg.getLangueDefaut() + "\" n'a pas pu être chargée");
                }       
                if (langueURL != null && ! langueURL.equals("")) {
                        cel2.LogVersFirebug("Langue passée dans l'URL: " + langueURL);
                        if (! Msg.setLangue(langueURL)) {
                                cel2.LogVersFirebug("La langue demandée \"" + langueURL + "\" n'a pas pu être chargée");
                        }
                }

                // Chargement de l'api google maps v3 avant l'initialisation pour 
                // éviter des "complications"
                // TODO: fabriquer une classe qui cherche dans la config une liste d'api
                // à charger, les instancie et ensuite lance l'application
                AjaxLoaderOptions optAj = AjaxLoaderOptions.newInstance();
                optAj.setOtherParms("key="+Configuration.getCleGoogleMaps()+"&sensor=false");
                        
                Runnable callback = new Runnable() {
                        public void run() {
                                initialiserCel();
                        };
                };
                AjaxLoader.loadApi("maps", "3", callback, optAj);
        }
        
        private void initialiserCel() {
                CarnetEnLigneMediateur carnetEnLigneMediateur= CarnetEnLigneMediateur.Instance();
                new Viewport(carnetEnLigneMediateur.getPanneauPrincipalCarnetEnLigne()) ;
                carnetEnLigneMediateur.getEtatUtilisateur() ;

                Timer t = new Timer() {
                        @Override
                        public void run() {
                                 Ext.get("loading").hide();
                        }
                };
                
                t.schedule(3000);
        }
        
        /*private String buildStackTrace(Throwable t, String log) {
             if (t != null) {
                     log += t.getClass().toString();
                     log += t.getMessage();
                     //
                     StackTraceElement[] stackTrace = t.getStackTrace();
                     if (stackTrace != null) {
                         StringBuffer trace = new StringBuffer();
                    
                             for (int i = 0; i < stackTrace.length; i++) {
                                 trace.append(stackTrace[i].getClassName() + "." + stackTrace[i].getMethodName() + "("
                                                 + stackTrace[i].getFileName() + ":" + stackTrace[i].getLineNumber());
                             }
                    
                             log += trace.toString();
                     }
                     //
                     Throwable cause = t.getCause();
                     if (cause != null && cause != t) {
                         log += buildStackTrace(cause, "CausedBy:\n");
                     }
             }
             return log;
        }*/

        public static native void  LogVersFirebug(Object o) /*-{
                if (!!($wnd.console && $wnd.console.log)) {
                        console.log(o);
                }
        }-*/;
}