Subversion Repositories eFlore/Archives.cel-v1

Rev

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