Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 11 | Rev 13 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
1
package org.tela_botanica.client;
1
package org.tela_botanica.client;
2
 
2
 
3
 
3
 
4
// TODO : sortie User vers une classe ...
4
// TODO : sortie User vers une classe ...
5
// TODO : sortie les boutons supprimer et exporter et inclure ici
5
// TODO : sortie les boutons supprimer et exporter et inclure ici
6
 
6
 
7
import com.google.gwt.i18n.client.Dictionary;
7
import com.google.gwt.i18n.client.Dictionary;
8
import com.google.gwt.json.client.JSONParser;
8
import com.google.gwt.json.client.JSONParser;
9
import com.google.gwt.json.client.JSONString;
9
import com.google.gwt.json.client.JSONString;
10
import com.google.gwt.json.client.JSONValue;
10
import com.google.gwt.json.client.JSONValue;
11
import com.google.gwt.user.client.HTTPRequest;
11
import com.google.gwt.user.client.HTTPRequest;
12
import com.google.gwt.user.client.ResponseTextHandler;
12
import com.google.gwt.user.client.ResponseTextHandler;
-
 
13
import com.google.gwt.user.client.ui.TextBox;
13
 
14
 
14
public class Mediator {
15
public class Mediator {
15
		
16
		
16
		
17
		
17
		private String serviceBaseUrl = getServiceBaseUrlFromDictionnary();
18
		private String serviceBaseUrl = getServiceBaseUrlFromDictionnary();
18
		private String user = null;
19
		private String user = null;
19
		private InventoryItemList inventoryItemList = null;
20
		private InventoryItemList inventoryItemList = null;
20
		private LocationList locationList = null;
21
		private LocationList locationList = null;
-
 
22
		private DateList dateList = null;
21
		private NameAssistant nameAssistant=null;
23
		private NameAssistant nameAssistant=null;
22
		private LocationAssistant locationAssistant=null;
24
		private LocationAssistant locationAssistant=null;
-
 
25
		private InventoryItem inventoryItem=null;
-
 
26
		private EntryPanel entryPanel=null;
-
 
27
		
-
 
28
		private TextBox date = null; 
-
 
29
		private TextBox complementLocation = null; 
-
 
30
		private TextBox comment = null;
-
 
31
 
-
 
32
		
-
 
33
 
23
		
34
 
24
		private Cel cel = null;
35
		private Cel cel = null;
25
 
36
 
26
		
37
		
27
		Mediator() {
38
		Mediator() {
28
			
39
			
29
			
40
			
30
		}
41
		}
31
	
42
	
32
		/**
43
		/**
33
		 * Recuperation information utilisateur
44
		 * Recuperation information utilisateur
34
		 *
45
		 *
35
		 */
46
		 */
36
		
47
		
37
		public void initUser() {
48
		public void initUser() {
38
			getUserFromService();
49
			getUserFromService();
39
			
50
			
40
		}
51
		}
-
 
52
		
-
 
53
		
-
 
54
		/**
-
 
55
		 * Action initialisation
-
 
56
		 */
-
 
57
		
-
 
58
	
-
 
59
		public void onInit() {
-
 
60
 
-
 
61
			this.onLocationSelected("all");
-
 
62
			
-
 
63
		}
-
 
64
		
-
 
65
 
-
 
66
		public void onEntryClick() {
-
 
67
			
-
 
68
			this.entryPanel.show();
-
 
69
		}
41
	
70
		
42
		/**
71
		/**
43
		 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
-
 
44
		 *
72
		 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
45
		 */
73
		 */
46
		
74
		
47
		public void onLocationSelected(String loc) {
75
		public void onLocationSelected(String loc) {
48
		
76
		
49
			inventoryItemList.setLocation(loc);
77
			inventoryItemList.setLocation(loc);
-
 
78
			inventoryItemList.setDate("all");
50
			inventoryItemList.updateCount();
79
			inventoryItemList.updateCount();
-
 
80
			
-
 
81
			if (entryPanel!=null) {
51
			
82
			
52
			if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
83
				if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
53
				locationAssistant.setText("");
84
					locationAssistant.setText("");
54
			}
85
				}
55
			else {
86
				else {
-
 
87
					locationAssistant.setText(loc);
-
 
88
				}
56
				locationAssistant.setText(loc);
89
					
-
 
90
			}
-
 
91
		
-
 
92
		}
-
 
93
 
-
 
94
		
-
 
95
		/**
-
 
96
		 * Action sur selection d'une date : affichage de la liste des taxons correspondants
-
 
97
		 */
-
 
98
		
-
 
99
		public void onDateSelected(String date) {
-
 
100
 
-
 
101
			inventoryItemList.setDate(date);
-
 
102
			inventoryItemList.updateCount();
-
 
103
 
-
 
104
			/*
-
 
105
			if (entryPanel!=null) {
-
 
106
			
-
 
107
				if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
-
 
108
					locationAssistant.setText("");
-
 
109
				}
-
 
110
				else {
-
 
111
					locationAssistant.setText(loc);
-
 
112
				}
-
 
113
					
-
 
114
			}
57
			}
115
			*/
-
 
116
		
58
			
117
		}
59
		}
118
 
60
	
119
		
61
		/**
120
		/**
62
		 * Action sur ajout d'un taxon : affichage du lieu corresondant
121
		 * Action posterieure à l'affichage des observations : mise a jour affichage des localites
63
		 */
122
		 */
64
		
123
		
65
	
124
	
66
		public void onInventoryItemUpdate(String loc) {
125
		public void onInventoryItemUpdate(String loc) {
67
 
126
 
68
			locationList.setLocation(loc);
127
			locationList.setLocation(loc);
69
			locationList.updateCount();
128
			locationList.updateCount();
70
		
129
		
71
		}
130
		}
-
 
131
	
-
 
132
		
-
 
133
		/**
-
 
134
		 * Action posterieure à l'affichage des localites : mise a jour affichage des dates
-
 
135
		 */
-
 
136
 
-
 
137
		public void onLocationUpdate(String loc) {
-
 
138
 
-
 
139
		
-
 
140
			dateList.setLocation(loc);
-
 
141
			dateList.updateCount();
-
 
142
	
-
 
143
		}
-
 
144
		
-
 
145
		
-
 
146
		/**
-
 
147
		 * Action prealable à l'ajout d'une observation : controle presence champs requis et lancement mise a jour 
-
 
148
		 * 
-
 
149
		 */
-
 
150
		
-
 
151
		public void onAddInventoryItem() {
-
 
152
		
-
 
153
			// TODO : singleton ?
-
 
154
			registerInventoryItem(new InventoryItem(nameAssistant.getText(),nameAssistant.getValue(),locationAssistant.getText(),locationAssistant.getValue(),date.getText(),complementLocation.getText(),comment.getText()));
-
 
155
			inventoryItemList.addelement();
-
 
156
			
-
 
157
		}
-
 
158
 
-
 
159
 
-
 
160
		
-
 
161
		public boolean inventoryItemIsValid() {
-
 
162
			// TODO : controle date
-
 
163
			
-
 
164
		    if (inventoryItem.getName().compareTo("")==0) {
-
 
165
		    	return false;
-
 
166
		    }
-
 
167
		    else {
-
 
168
		    	return true;
-
 
169
		    }
-
 
170
			
-
 
171
		}
-
 
172
 
-
 
173
		/**
-
 
174
		 * Declaration InventoryItem
-
 
175
		 * @param cel
-
 
176
		 */
-
 
177
 
-
 
178
		public void registerInventoryItem(InventoryItem inventoryItem) {
-
 
179
			
-
 
180
			this.inventoryItem=inventoryItem;
-
 
181
		}
-
 
182
 
-
 
183
 
-
 
184
		
72
		
185
		
73
		/**
186
		/**
74
		 * Declaration InventoryItemList 
187
		 * Declaration InventoryItemList 
75
		 * @param inventoryItemList
188
		 * @param inventoryItemList
76
		 */
189
		 */
77
		
190
		
78
		public void registerInventoryItemList(InventoryItemList inventoryItemList) {
191
		public void registerInventoryItemList(InventoryItemList inventoryItemList) {
79
			
192
			
80
			this.inventoryItemList=inventoryItemList;
193
			this.inventoryItemList=inventoryItemList;
81
		
194
		
82
		}
195
		}
83
	
196
	
84
		/**
197
		/**
85
		 * Declaration LocationList
198
		 * Declaration LocationList
86
		 * @param locationList
199
		 * @param locationList
87
		 */
200
		 */
88
		
201
		
89
		public void registerLocationList(LocationList locationList) {
202
		public void registerLocationList(LocationList locationList) {
90
			
203
			
91
			this.locationList=locationList;
204
			this.locationList=locationList;
92
		}
205
		}
-
 
206
	
-
 
207
		
-
 
208
		
-
 
209
		/**
-
 
210
		 * Declaration DateList
-
 
211
		 * @param locationList
-
 
212
		 */
-
 
213
		
-
 
214
		public void registerDateList(DateList dateList) {
-
 
215
			
-
 
216
			this.dateList=dateList;
-
 
217
		}
-
 
218
 
-
 
219
		
93
		
220
		
94
		/**
221
		/**
95
		 * Declaration Cel
222
		 * Declaration Cel
96
		 * @param cel
223
		 * @param cel
97
		 */
224
		 */
98
 
225
 
99
		public void registerCel(Cel cel) {
226
		public void registerCel(Cel cel) {
100
			
227
			
101
			this.cel=cel;
228
			this.cel=cel;
102
		}
229
		}
103
 
230
 
104
		
231
		
105
		/**
232
		/**
106
		 * Declaration NameAssistant 
233
		 * Declaration NameAssistant 
107
		 * @param nameassistant
234
		 * @param nameassistant
108
		 */
235
		 */
109
		
236
		
110
		public void registerNameAssistant(NameAssistant nameAssistant) {
237
		public void registerNameAssistant(NameAssistant nameAssistant) {
111
			this.nameAssistant=nameAssistant;
238
			this.nameAssistant=nameAssistant;
112
			
239
			
113
		}
240
		}
114
		
241
		
115
		/**
242
		/**
116
		 * Declaration LocationAssistant 
243
		 * Declaration LocationAssistant 
117
		 * @param locationassistant
244
		 * @param locationassistant
118
		 */
245
		 */
119
		
246
		
120
		public void registerLocationAssistant(LocationAssistant locationAssistant) {
247
		public void registerLocationAssistant(LocationAssistant locationAssistant) {
121
			this.locationAssistant=locationAssistant;
248
			this.locationAssistant=locationAssistant;
122
			
249
			
123
		}
250
		}
-
 
251
 
-
 
252
		
-
 
253
		
-
 
254
		/**
-
 
255
		 * Declaration date
-
 
256
		 * @param date
-
 
257
		 */
-
 
258
		
-
 
259
		public void registerDate(TextBox date) {
-
 
260
			this.date=date;
-
 
261
			
-
 
262
		}
-
 
263
	
-
 
264
		
-
 
265
		
-
 
266
		/**
-
 
267
		 * Declaration complementLocation
-
 
268
		 * @param complementLocation
-
 
269
		 */
-
 
270
		
-
 
271
		public void registerComplementLocation(TextBox complementLocation) {
-
 
272
			this.complementLocation=complementLocation;
-
 
273
			
-
 
274
		}
-
 
275
		
-
 
276
		
-
 
277
	    public void  registerEntryPanel(EntryPanel entryPanel) {
-
 
278
	    	this.entryPanel=entryPanel;
-
 
279
		}
-
 
280
 
-
 
281
		
-
 
282
		/**
-
 
283
		 * Declaration commentaire 
-
 
284
		 * @param commentaire
-
 
285
		 */
-
 
286
		
-
 
287
		public void registerComment(TextBox comment) {
-
 
288
			this.comment=comment;
-
 
289
			
-
 
290
		}
-
 
291
		
-
 
292
 
124
		
293
		
125
 
294
 
126
		/**
295
		/**
127
		 * Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation
296
		 * Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation
128
		 * de l'appellant Cel. (initAsync)
297
		 * de l'appellant Cel. (initAsync)
129
		 * 
298
		 * 
130
		 */
299
		 */
131
		
300
		
132
		private void getUserFromService() {
301
		private void getUserFromService() {
133
 
302
 
134
 
303
 
135
			HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
304
			HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
136
					new ResponseTextHandler() {
305
					new ResponseTextHandler() {
137
 
306
 
138
						public void onCompletion(String str) {
307
						public void onCompletion(String str) {
139
							JSONValue jsonValue = JSONParser.parse(str);
308
							JSONValue jsonValue = JSONParser.parse(str);
140
							JSONString jsonString;
309
							JSONString jsonString;
141
							if ((jsonString = jsonValue.isString()) != null) {
310
							if ((jsonString = jsonValue.isString()) != null) {
142
								user = jsonString.stringValue();
311
								user = jsonString.stringValue();
143
							}
312
							}
144
							cel.initAsync();
313
							cel.initAsync();
145
						}
314
						}
146
					});
315
					});
147
 
316
 
148
		}
317
		}
149
	
318
	
150
		/**
319
		/**
151
		 * Accesseur Url de base
320
		 * Accesseur Url de base
152
		 * @return Url de base
321
		 * @return Url de base
153
		 */
322
		 */
154
		
323
		
155
		public String getServiceBaseUrl() {
324
		public String getServiceBaseUrl() {
156
			
325
			
157
			return serviceBaseUrl;
326
			return serviceBaseUrl;
158
 
327
 
159
		}
328
		}
160
 
329
 
161
		
330
		
162
		/**
331
		/**
163
		 * Recuperation du prefixe d'appel des services
332
		 * Recuperation du prefixe d'appel des services
164
		 * @return prefix appel des service
333
		 * @return prefix appel des service
165
		 */
334
		 */
166
 
335
 
167
		private String getServiceBaseUrlFromDictionnary() {
336
		private String getServiceBaseUrlFromDictionnary() {
168
 
337
 
169
			Dictionary theme = Dictionary.getDictionary("Parameters");
338
			Dictionary theme = Dictionary.getDictionary("Parameters");
170
			return theme.get("serviceBaseUrl");
339
			return theme.get("serviceBaseUrl");
171
 
340
 
172
		}
341
		}
173
 
342
 
174
 
343
 
175
		/**
344
		/**
176
		 *  Accesseur Utilisateur
345
		 *  Accesseur Utilisateur
177
		 * @return utilisateur connecté ou identifiant de session
346
		 * @return utilisateur connecté ou identifiant de session
178
		 */
347
		 */
179
		
348
		
180
		public String getUser() {
349
		public String getUser() {
181
			return user;
350
			return user;
182
		}
351
		}
183
		
352
		
184
 
353
 
185
		
354
		
186
		public InventoryItemList getInventoryItemList() {
355
		public InventoryItemList getInventoryItemList() {
187
			return inventoryItemList;
356
			return inventoryItemList;
188
		}
357
		}
189
 
358
 
190
		public LocationList getLocationList() {
359
		public LocationList getLocationList() {
191
			return locationList;
360
			return locationList;
192
		}
361
		}
-
 
362
 
-
 
363
		public DateList getDateList() {
-
 
364
			return dateList;
-
 
365
		}
-
 
366
 
193
 
367
		
194
		public NameAssistant getNameAssistant() {
368
		public NameAssistant getNameAssistant() {
195
			return nameAssistant;
369
			return nameAssistant;
196
		}
370
		}
197
 
371
 
198
		public LocationAssistant getLocationAssistant() {
372
		public LocationAssistant getLocationAssistant() {
199
			return locationAssistant;
373
			return locationAssistant;
200
		}
374
		}
-
 
375
 
-
 
376
		public InventoryItem getInventoryItem() {
-
 
377
			return inventoryItem;
-
 
378
		}
-
 
379
 
-
 
380
		public EntryPanel getEntryPanel() {
-
 
381
			return entryPanel;
-
 
382
		}
201
 
383
 
202
 
384
 
203
 
385
 
204
	}
386
	}