Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 13 | Rev 23 | 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.JSONArray;
import com.google.gwt.json.client.JSONBoolean;
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.Label;
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 StationList stationList = 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 LoginDialog loginDialog=null;
                private TopPanel topPanel=null;
                
                private TextBox date = null; 
                private TextBox complementLocation = null; 
                private TextBox comment = null;

                boolean connected=false;


                private Cel cel = null;

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

                        
                        locationList.setLocation("all");
                        locationList.updateCount();

                        this.onLocationSelected("all");
                        
                }
                
                
                /**
                 * Action suite ajout, modification, suppression element inventaire
                 */
                
        
                public void onInventoryUpdated(String location) {

                        
                        locationList.setLocation(location);
                        locationList.updateCount();

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

                
                /**
                 * Action sur recherche  : 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
                 * TODO : gerer asynchronicite ?
                 */
                
                public void onLocationSelected(String loc) {
                
                        inventoryItemList.setLocation(loc);
                        inventoryItemList.setDate("all");
                        inventoryItemList.setStation("all");
                        inventoryItemList.updateCount();
                        
                        dateList.setLocation(loc);
                        dateList.setDate("all");
                        dateList.updateCount();
                        stationList.setLocation(loc);
                        stationList.setStation("all");
                        stationList.updateCount();
                        
                }
                
                /**
                 * Action sur login
                 * @param user
                 */
                
                
                public void onLogin(String user) {
                        
                        
                        this.user=user;
                        topPanel.getSignLabel().setText(user+ " (deconnexion)");
                        inventoryItemList.setUser(user);
                        dateList.setUser(user);
                        stationList.setUser(user);
                        entryPanel.setUser(user);
                        locationList.setUser(user);
                        this.onInit();
                        
                }
                
                
                /**
                 * Action sur logoff
                 * @param user
                 */
                
                
                public void onLogoff(String user) {
                        
                        this.user=user;
                        topPanel.getSignLabel().setText("Connexion");
                        inventoryItemList.setUser(user);
                        dateList.setUser(user);
                        stationList.setUser(user);
                        entryPanel.setUser(user);
                        locationList.setUser(user);
                        this.onInit();
                        
                }

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

                        inventoryItemList.setStation(station);
                        inventoryItemList.updateCount();

                }



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

                        inventoryItemList.setDate(date);
                        inventoryItemList.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 StationList
                 * @param locationList
                 */
                
                public void registerStationList(StationList stationList) {
                        
                        this.stationList=stationList;
                }

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

            public void  registerTopPanel(TopPanel topPanel) {
                this.topPanel=topPanel;
                }

            
            
            public void  registerLoginDialog(LoginDialog loginDialog) {
                this.loginDialog=loginDialog;
                }

            
            
                /**
                 * 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);
                                                        JSONArray jsonArray;
                                                        if ((jsonArray = jsonValue.isArray()) != null) {
                                                                        user = ((JSONString) jsonArray.get(0)).stringValue();
                                                                        connected = ((JSONBoolean) jsonArray.get(1)).booleanValue();
                                                        }
                                                        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 void setUser(String user) {
                        this.user=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;
                }


                public void setConnected(boolean connected) {
                
                        this.connected=connected;
                }
                
                public boolean getConnected() {
                        
                        return this.connected;
                }


        }