Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 11 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
10 ddelon 1
package org.tela_botanica.client;
2
 
3
 
4
// TODO : sortie User vers une classe ...
5
// TODO : sortie les boutons supprimer et exporter et inclure ici
6
 
7
import com.google.gwt.i18n.client.Dictionary;
8
import com.google.gwt.json.client.JSONParser;
9
import com.google.gwt.json.client.JSONString;
10
import com.google.gwt.json.client.JSONValue;
11
import com.google.gwt.user.client.HTTPRequest;
12
import com.google.gwt.user.client.ResponseTextHandler;
13
 
14
public class Mediator {
15
 
16
 
17
		private String serviceBaseUrl = getServiceBaseUrlFromDictionnary();
18
		private String user = null;
19
		private TaxonList taxonlist = null;
20
		private LocationList locationList = null;
21
		private Cel cel = null;
22
 
23
 
24
		Mediator() {
25
 
26
 
27
		}
28
 
29
		/**
30
		 * Recuperation information utilisateur
31
		 *
32
		 */
33
 
34
		public void initUser() {
35
			getUserFromService();
36
 
37
		}
38
 
39
		/**
40
		 * Action sur selection d'un lieu
41
		 *
42
		 */
43
 
44
		public void onLocationSelected(String loc) {
45
 
46
			taxonlist.setLocation(loc);
47
			taxonlist.updateCount();
48
 
49
 
50
		}
51
 
52
		/**
53
		 * Action sur ajout d'un taxon
54
		 */
55
 
56
 
57
		public void onTaxonListUpdate(String loc) {
58
 
59
			locationList.setLocation(loc);
60
			locationList.update();
61
 
62
		}
63
 
64
		/**
65
		 * Enregistrement TaxonList
66
		 * @param taxonlist
67
		 */
68
 
69
		public void registerTaxonList(TaxonList taxonlist) {
70
 
71
			this.taxonlist=taxonlist;
72
 
73
		}
74
 
75
		/**
76
		 * Enregistremnt LocationList
77
		 * @param locationList
78
		 */
79
 
80
		public void registerLocationList(LocationList locationList) {
81
 
82
			this.locationList=locationList;
83
		}
84
 
85
		/**
86
		 * Enregistrement Cel
87
		 * @param cel
88
		 */
89
 
90
		public void registerCel(Cel cel) {
91
 
92
			this.cel=cel;
93
		}
94
 
95
 
96
 
97
		/**
98
		 * Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation
99
		 * de l'appellant Cel. (initAsunc)
100
		 *
101
		 */
102
 
103
		private void getUserFromService() {
104
 
105
 
106
			HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
107
					new ResponseTextHandler() {
108
 
109
						public void onCompletion(String str) {
110
							JSONValue jsonValue = JSONParser.parse(str);
111
							JSONString jsonString;
112
							if ((jsonString = jsonValue.isString()) != null) {
113
								user = jsonString.stringValue();
114
							}
115
							cel.initAsync();
116
						}
117
					});
118
 
119
		}
120
 
121
		/**
122
		 * Accesseur Url de base
123
		 * @return Url de base
124
		 */
125
 
126
		public String getServiceBaseUrl() {
127
 
128
			return serviceBaseUrl;
129
 
130
		}
131
 
132
 
133
		/**
134
		 * Recuperation du prefixe d'appel des services
135
		 * @return prefix appel des service
136
		 */
137
 
138
		private String getServiceBaseUrlFromDictionnary() {
139
 
140
			Dictionary theme = Dictionary.getDictionary("Parameters");
141
			return theme.get("serviceBaseUrl");
142
 
143
		}
144
 
145
 
146
		/**
147
		 *  Accesseur Utilisateur
148
		 * @return utilisateur connecté ou identifiant de session
149
		 */
150
 
151
		public String getUser() {
152
			return user;
153
		}
154
 
155
 
156
 
157
	}