Rev 26 | Rev 28 | 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 iciimport 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.TextBox;public class Mediator implements AutoCompleteAsyncTextBoxListener {private String serviceBaseUrl = getServiceBaseUrlFromDictionnary(); // Recherche url de base des services distants// Utilisateurprivate TopPanel topPanel=null; // Information de connexionprivate String user = null; // Utilisateur connecte ou bien identifiant de sessionprivate boolean connected=false;// Filtresprivate LeftPanel leftPanel=null; // Containeur filtre date, lieu, lieu-dit ...private LocationList locationList = null; // Filtre sur lieu de releveprivate DateList dateList = null; // Filtre sur date d'observationprivate StationList stationList = null; // Filtre sur station d'observation// Saisie d'une observationprivate EntryPanel entryPanel=null; // Formulaire de saisie observationprivate NameAssistant nameAssistant=null; // Assistant de saisie nom scientifiqueprivate LocationAssistant locationAssistant=null; // Assistant de saisie nom de communeprivate TextBox date = null; // date observationprivate TextBox milieu = null; // milieu observationprivate TextBox lieudit = null; // lieu dit observationprivate TextBox comment = null; // commentaire observationprivate InventoryItem inventoryItem=null; // Une observation saisie// Liste des observationsprivate InventoryItemList inventoryItemList = null; // Liste de releves saisisprivate ActionPanel actionPanel=null; // Action sur les observations// Informationsprivate InfoPopup infoPopup=null; // Information complementaire sur un taxon (photo, repartition)// Point d'entree (pour fin d'initialisation)private Cel cel = null;Mediator() {}// Methodes Private/*** Recuperation du prefixe d'appel des services* @return prefix appel des service*/private String getServiceBaseUrlFromDictionnary() {Dictionary theme = Dictionary.getDictionary("Parameters");return theme.get("serviceBaseUrl");}// Appel aux services :/*** Recherche distante et asynchrone de l'utilisateur connecte, 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(); // Identifiant utilisateur ou identifiant de session si non connecteconnected = ((JSONBoolean) jsonArray.get(1)).booleanValue(); // Drapeau leve si utilisateur identifie}cel.initAsync();}});}// Methodes Public// Information sur Etat du systeme/*** Recuperation information utilisateur**/public void initUser() {getUserFromService(); // Appel distant recherche de l'utilisateur}// Actions declanchee par le systeme/*** Action initialisation premier affichage*/public void onInit() {locationList.setLocation("all");locationList.updateCount();this.onLocationSelected("all");}// Actions sur formulaire de saisie/*** Action lancee par la completion d'un nom dans un assistant de saisie* Recherche d'information complementaires ....** @return void*/public void onComplete(ResponseTextHandler sender, String str, String value) {if (sender instanceof NameAssistant) {onNameCompleted(value);}}/*** Action suivant la completion d'un nom**/public void onNameCompleted(String value) {if (infoPopup==null) {infoPopup = new InfoPopup(this);}infoPopup.setImageUrl(value);}/*** Action prealable a l'ajout d'une observation : controle presence champs requis et lancement mise a jour**/public void onAddInventoryItem() {// Lazy instantiationif (inventoryItem==null) {registerInventoryItem(new InventoryItem());}inventoryItem.setContent(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),milieu.getText(),comment.getText(),"null");inventoryItemList.addelement();}/*** Action prealable a la modification d'une observation : controle presence champs requis et lancement mise a jour**/public void onModifyInventoryItem(String ordre) {// Lazy instantiationif (inventoryItem==null) {registerInventoryItem(new InventoryItem());}inventoryItem.setContent(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),milieu.getText(),comment.getText(),ordre);inventoryItemList.updateElement();}public boolean inventoryItemIsValid() {// TODO : controle dateif (inventoryItem.getName().compareTo("")==0) {return false;}else {return true;}}/*** Action lancee par la selection d'un nom dans un assistant de saisie. Lance* la recherche d'informations complementaires (famille, numero* nomenclaturaux etc) et met a jour l'inventaire (addelement())** @return void*/public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,String str, String value) {if (getEntryPanel().getOrdre()==null) { // Nouvelle observationonAddInventoryItem();}else {onModifyInventoryItem(getEntryPanel().getOrdre()); // Modification d'une observationgetEntryPanel().setOrdre(null);}}// Action portant sur la liste des observations/*** Action suite ajout, modification, suppression d'un element inventaire*/public void onInventoryUpdated(String location) {locationList.setLocation(location); // Mise a jour filtre localitelocationList.updateCount();this.onLocationSelected(location); // Selection localite}/*** Action sur selection d'une observation : affichage du detail*/public void onInventoryItemSelected(String ordre) {entryPanel.setOrdre(ordre); // Mise a jour du formulaire de saisie avec l'element selectionneentryPanel.update();}/*** Action sur deselection d'une observation : remise a zero*/public void onInventoryItemUnselected(String ordre) {entryPanel.setOrdre(null); // Mise a jour du formulaire de saisie avec l'element selectionne}// Action sur Filtrage// Filtre identification/*** Action sur login : initialisation filtres pour cette utilisateur* @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();}// Filtre recherche contenu/*** 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();}// Filtre selection lieu/*** 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.updateCount();inventoryItemList.displayFilter();dateList.setLocation(loc);dateList.updateCount();stationList.setLocation(loc);stationList.updateCount();}// Filtre station/*** Action sur selection d'une station : affichage de la liste des taxons correspondants*/public void onStationSelected(String station) {inventoryItemList.setStation(station);inventoryItemList.updateCount();inventoryItemList.displayFilter();}// Filtre date d'observation/*** Action sur selection d'une date : affichage de la liste des taxons correspondants*/public void onDateSelected(String date) {inventoryItemList.setDate(date);inventoryItemList.updateCount();inventoryItemList.displayFilter();}// Declaration, enregistrement/*** Declaration InventoryItem : une observation* @param cel*/public void registerInventoryItem(InventoryItem inventoryItem) {this.inventoryItem=inventoryItem;}/*** Declaration InventoryItemList : liste d'observation* @param inventoryItemList*/public void registerInventoryItemList(InventoryItemList inventoryItemList) {this.inventoryItemList=inventoryItemList;}/*** Declaration LocationList : filtre lieu observation* @param locationList*/public void registerLocationList(LocationList locationList) {this.locationList=locationList;}/*** Declaration DateList : filtre date observation* @param locationList*/public void registerDateList(DateList dateList) {this.dateList=dateList;}/*** Declaration InfoPopup : information complementaire taxon en cours* @param infoPopup*/public void registerInfoPopup(InfoPopup infoPopup) {this.infoPopup=infoPopup;}/*** Declaration StationList : filtre par station* @param locationList*/public void registerStationList(StationList stationList) {this.stationList=stationList;}/*** Declaration Cel : point d'entree* @param cel*/public void registerCel(Cel cel) {this.cel=cel;}/*** Declaration NameAssistant : completion nom scientifique* @param nameassistant*/public void registerNameAssistant(NameAssistant nameAssistant) {this.nameAssistant=nameAssistant;}/*** Declaration LocationAssistant : completion commune* @param locationassistant*/public void registerLocationAssistant(LocationAssistant locationAssistant) {this.locationAssistant=locationAssistant;}/*** Declaration date : date observation* @param date*/public void registerDate(TextBox date) {this.date=date;}/*** Declaration lieu dit : lieu dit d'observation** @param milieu*/public void registerLieudit(TextBox lieudit) {this.lieudit=lieudit;}/*** Declaration milieu : milieu d'observation** @param milieu*/public void registerMilieu(TextBox milieu) {this.milieu=milieu;}/*** Declaration Entry Panel : formulaire de saisie observation*/public void registerEntryPanel(EntryPanel entryPanel) {this.entryPanel=entryPanel;}/*** Declaration Action Panel : actions sur liste des observations*/public void registerActionPanel(ActionPanel actionPanel) {this.actionPanel=actionPanel;}/*** Declaration TopPanel : panneau de connexion*/public void registerTopPanel(TopPanel topPanel) {this.topPanel=topPanel;}/*** Declaration commentaire* @param commentaire*/public void registerComment(TextBox comment) {this.comment=comment;}/** Declaration LeftPanel Panneau gauche filtre sur liste d'observation**/public void registerLeftPanel(LeftPanel leftPanel) {this.leftPanel=leftPanel;}// Accesseurs et setteurs/*** Accesseur Url de base* @return Url de base*/public String getServiceBaseUrl() {return serviceBaseUrl;}/*** Accesseur Utilisateur* @return utilisateur connecte 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 LeftPanel getLeftPanel() {return leftPanel;}public InfoPopup getInfoPopup() {if (infoPopup==null) {infoPopup = new InfoPopup(this);}return infoPopup;}public void setConnected(boolean connected) {this.connected=connected;}public boolean getConnected() {return this.connected;}public ActionPanel getActionPanel() {return this.actionPanel;}}