Subversion Repositories eFlore/Archives.cel-v1

Rev

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

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