New file |
0,0 → 1,157 |
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 TaxonList taxonlist = null; |
private LocationList locationList = null; |
private Cel cel = null; |
|
|
Mediator() { |
|
|
} |
|
/** |
* Recuperation information utilisateur |
* |
*/ |
|
public void initUser() { |
getUserFromService(); |
|
} |
|
/** |
* Action sur selection d'un lieu |
* |
*/ |
|
public void onLocationSelected(String loc) { |
|
taxonlist.setLocation(loc); |
taxonlist.updateCount(); |
|
|
} |
|
/** |
* Action sur ajout d'un taxon |
*/ |
|
|
public void onTaxonListUpdate(String loc) { |
|
locationList.setLocation(loc); |
locationList.update(); |
|
} |
|
/** |
* Enregistrement TaxonList |
* @param taxonlist |
*/ |
|
public void registerTaxonList(TaxonList taxonlist) { |
|
this.taxonlist=taxonlist; |
|
} |
|
/** |
* Enregistremnt LocationList |
* @param locationList |
*/ |
|
public void registerLocationList(LocationList locationList) { |
|
this.locationList=locationList; |
} |
|
/** |
* Enregistrement Cel |
* @param cel |
*/ |
|
public void registerCel(Cel cel) { |
|
this.cel=cel; |
} |
|
|
|
/** |
* Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation |
* de l'appellant Cel. (initAsunc) |
* |
*/ |
|
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; |
} |
|
|
|
} |