Subversion Repositories eFlore/Archives.cel-v1

Rev

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