Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 12 | Rev 14 | 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;
import com.google.gwt.user.client.ui.TextBox;

public class Mediator {
                
                
                private String serviceBaseUrl = getServiceBaseUrlFromDictionnary();
                private String user = null;
                private InventoryItemList inventoryItemList = null;
                private LocationList locationList = null;
                private DateList dateList = null;
                private NameAssistant nameAssistant=null;
                private LocationAssistant locationAssistant=null;
                private InventoryItem inventoryItem=null;
                private EntryPanel entryPanel=null;
                private ActionPanel actionPanel=null;
                private SearchPanel searchPanel=null;
                
                private TextBox date = null; 
                private TextBox complementLocation = null; 
                private TextBox comment = null;

                


                private Cel cel = null;

                
                Mediator() {
                        
                        
                }
        
                /**
                 * Recuperation information utilisateur
                 *
                 */
                
                public void initUser() {
                        getUserFromService();
                        
                }
                
                
                /**
                 * Action initialisation
                 */
                
        
                public void onInit() {

                        this.onLocationSelected("all");
                        
                }
                
                
                
                /**
                 * Action sur selection d'une observation : affichage du detail
                 */
                
                public void onInventoryItemSelected(String ordre) {
                
                        entryPanel.setOrdre(ordre);
                        entryPanel.update();
                        
                        
                }

                
                /**
                 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
                 */
                
                public void onSearch(String search) {
        
                        if (search.trim().compareTo("")==0) {
                                search="all";
                        }
                        inventoryItemList.setSearch(search);
                        inventoryItemList.updateCount();
                        
                }

                
                
                /**
                 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
                 */
                
                public void onLocationSelected(String loc) {
                
                        inventoryItemList.setLocation(loc);
                        inventoryItemList.setDate("all");
                        inventoryItemList.updateCount();
                        
                        
                        if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
                                locationAssistant.setText("");
                        }
                        else {
                                locationAssistant.setText(loc);
                        }
                
                }

                
                /**
                 * Action sur selection d'une date : affichage de la liste des taxons correspondants
                 */
                
                public void onDateSelected(String date) {

                        inventoryItemList.setDate(date);
                        inventoryItemList.updateCount();

                        /*
                        
                                if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
                                        locationAssistant.setText("");
                                }
                                else {
                                        locationAssistant.setText(loc);
                                }
                                        
                        */
                
                }

                
                /**
                 * Action posterieure à l'affichage des observations : mise a jour affichage des localites
                 */
                
        
                public void onInventoryItemUpdate(String loc) {

                        locationList.setLocation(loc);
                        locationList.updateCount();
                
                }
        
                
                /**
                 * Action posterieure à l'affichage des localites : mise a jour affichage des dates
                 */

                public void onLocationUpdate(String loc) {

                
                        dateList.setLocation(loc);
                        dateList.updateCount();
        
                }
                
                
                /**
                 * Action prealable à l'ajout d'une observation : controle presence champs requis et lancement mise a jour 
                 * 
                 */
                
                public void onAddInventoryItem() {
                
                        // TODO : singleton ?
                        registerInventoryItem(new InventoryItem(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),complementLocation.getText(),comment.getText(),"null"));
                        inventoryItemList.addelement();
                        
                }

                
                /**
                 * Action prealable à la modification d'une observation : controle presence champs requis et lancement mise a jour 
                 * 
                 */

                public void onModifyInventoryItem(String ordre) {

                // TODO : singleton ?
                registerInventoryItem(new InventoryItem(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),complementLocation.getText(),comment.getText(),ordre));
                inventoryItemList.updateElement();

                }

                
                public boolean inventoryItemIsValid() {
                        // TODO : controle date
                        
                    if (inventoryItem.getName().compareTo("")==0) {
                        return false;
                    }
                    else {
                        return true;
                    }
                        
                }

                /**
                 * Declaration InventoryItem
                 * @param cel
                 */

                public void registerInventoryItem(InventoryItem inventoryItem) {
                        
                        this.inventoryItem=inventoryItem;
                }


                
                
                /**
                 * 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 DateList
                 * @param locationList
                 */
                
                public void registerDateList(DateList dateList) {
                        
                        this.dateList=dateList;
                }

                
                
                /**
                 * 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;
                        
                }

                
                
                /**
                 * Declaration date
                 * @param date
                 */
                
                public void registerDate(TextBox date) {
                        this.date=date;
                        
                }
        
                
                
                /**
                 * Declaration complementLocation
                 * @param complementLocation
                 */
                
                public void registerComplementLocation(TextBox complementLocation) {
                        this.complementLocation=complementLocation;
                        
                }
                
                
            public void  registerEntryPanel(EntryPanel entryPanel) {
                this.entryPanel=entryPanel;
                }

            
                
            public void  registerActionPanel(ActionPanel actionPanel) {
                this.actionPanel=actionPanel;
                }

        
                
            public void  registerSearchPanel(SearchPanel searchPanel) {
                this.searchPanel=searchPanel;
                }


                /**
                 * Declaration commentaire 
                 * @param commentaire
                 */
                
                public void registerComment(TextBox comment) {
                        this.comment=comment;
                        
                }
                

                

                /**
                 * 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 DateList getDateList() {
                        return dateList;
                }

                
                public NameAssistant getNameAssistant() {
                        return nameAssistant;
                }

                public LocationAssistant getLocationAssistant() {
                        return locationAssistant;
                }

                public InventoryItem getInventoryItem() {
                        return inventoryItem;
                }

                public EntryPanel getEntryPanel() {
                        return entryPanel;
                }



        }