Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 10 | Rev 12 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client;


// TODO : sortie User vers une classe ...
// TODO : sortie les boutons supprimer et exporter et inclure ici

import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.HTTPRequest;
import com.google.gwt.user.client.ResponseTextHandler;

public class Mediator {
                
                
                private String serviceBaseUrl = getServiceBaseUrlFromDictionnary();
                private String user = null;
                private InventoryItemList inventoryItemList = null;
                private LocationList locationList = null;
                private NameAssistant nameAssistant=null;
                private LocationAssistant locationAssistant=null;
                
                private Cel cel = null;

                
                Mediator() {
                        
                        
                }
        
                /**
                 * Recuperation information utilisateur
                 *
                 */
                
                public void initUser() {
                        getUserFromService();
                        
                }
        
                /**
                 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
                 *
                 */
                
                public void onLocationSelected(String loc) {
                
                        inventoryItemList.setLocation(loc);
                        inventoryItemList.updateCount();
                        
                        if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
                                locationAssistant.setText("");
                        }
                        else {
                                locationAssistant.setText(loc);
                        }
                        
                }
        
                /**
                 * Action sur ajout d'un taxon : affichage du lieu corresondant
                 */
                
        
                public void onInventoryItemUpdate(String loc) {

                        locationList.setLocation(loc);
                        locationList.updateCount();
                
                }
                
                /**
                 * Declaration InventoryItemList 
                 * @param inventoryItemList
                 */
                
                public void registerInventoryItemList(InventoryItemList inventoryItemList) {
                        
                        this.inventoryItemList=inventoryItemList;
                
                }
        
                /**
                 * Declaration LocationList
                 * @param locationList
                 */
                
                public void registerLocationList(LocationList locationList) {
                        
                        this.locationList=locationList;
                }
                
                /**
                 * Declaration Cel
                 * @param cel
                 */

                public void registerCel(Cel cel) {
                        
                        this.cel=cel;
                }

                
                /**
                 * Declaration NameAssistant 
                 * @param nameassistant
                 */
                
                public void registerNameAssistant(NameAssistant nameAssistant) {
                        this.nameAssistant=nameAssistant;
                        
                }
                
                /**
                 * Declaration LocationAssistant 
                 * @param locationassistant
                 */
                
                public void registerLocationAssistant(LocationAssistant locationAssistant) {
                        this.locationAssistant=locationAssistant;
                        
                }
                

                /**
                 * Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation
                 * de l'appellant Cel. (initAsync)
                 * 
                 */
                
                private void getUserFromService() {


                        HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
                                        new ResponseTextHandler() {

                                                public void onCompletion(String str) {
                                                        JSONValue jsonValue = JSONParser.parse(str);
                                                        JSONString jsonString;
                                                        if ((jsonString = jsonValue.isString()) != null) {
                                                                user = jsonString.stringValue();
                                                        }
                                                        cel.initAsync();
                                                }
                                        });

                }
        
                /**
                 * Accesseur Url de base
                 * @return Url de base
                 */
                
                public String getServiceBaseUrl() {
                        
                        return serviceBaseUrl;

                }

                
                /**
                 * Recuperation du prefixe d'appel des services
                 * @return prefix appel des service
                 */

                private String getServiceBaseUrlFromDictionnary() {

                        Dictionary theme = Dictionary.getDictionary("Parameters");
                        return theme.get("serviceBaseUrl");

                }


                /**
                 *  Accesseur Utilisateur
                 * @return utilisateur connecté ou identifiant de session
                 */
                
                public String getUser() {
                        return user;
                }
                

                
                public InventoryItemList getInventoryItemList() {
                        return inventoryItemList;
                }

                public LocationList getLocationList() {
                        return locationList;
                }

                public NameAssistant getNameAssistant() {
                        return nameAssistant;
                }

                public LocationAssistant getLocationAssistant() {
                        return locationAssistant;
                }



        }