Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 11 | Rev 13 | 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;
11 ddelon 27
 
12 ddelon 28
		private TextBox date = null;
29
		private TextBox complementLocation = null;
30
		private TextBox comment = null;
31
 
32
 
33
 
34
 
10 ddelon 35
		private Cel cel = null;
36
 
37
 
38
		Mediator() {
39
 
40
 
41
		}
42
 
43
		/**
44
		 * Recuperation information utilisateur
45
		 *
46
		 */
47
 
48
		public void initUser() {
49
			getUserFromService();
50
 
51
		}
12 ddelon 52
 
53
 
54
		/**
55
		 * Action initialisation
56
		 */
57
 
10 ddelon 58
 
12 ddelon 59
		public void onInit() {
60
 
61
			this.onLocationSelected("all");
62
 
63
		}
64
 
65
 
66
		public void onEntryClick() {
67
 
68
			this.entryPanel.show();
69
		}
70
 
10 ddelon 71
		/**
11 ddelon 72
		 * Action sur selection d'un lieu : affichage de la liste des taxons correspondants
10 ddelon 73
		 */
74
 
75
		public void onLocationSelected(String loc) {
76
 
11 ddelon 77
			inventoryItemList.setLocation(loc);
12 ddelon 78
			inventoryItemList.setDate("all");
11 ddelon 79
			inventoryItemList.updateCount();
10 ddelon 80
 
12 ddelon 81
			if (entryPanel!=null) {
82
 
83
				if ((loc.compareTo("000null")==0) || (loc.compareTo("all")==0)) {
84
					locationAssistant.setText("");
85
				}
86
				else {
87
					locationAssistant.setText(loc);
88
				}
89
 
11 ddelon 90
			}
12 ddelon 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
 
11 ddelon 114
			}
12 ddelon 115
			*/
116
 
10 ddelon 117
		}
12 ddelon 118
 
119
 
10 ddelon 120
		/**
12 ddelon 121
		 * Action posterieure à l'affichage des observations : mise a jour affichage des localites
10 ddelon 122
		 */
123
 
124
 
11 ddelon 125
		public void onInventoryItemUpdate(String loc) {
10 ddelon 126
 
127
			locationList.setLocation(loc);
11 ddelon 128
			locationList.updateCount();
10 ddelon 129
 
130
		}
12 ddelon 131
 
10 ddelon 132
 
133
		/**
12 ddelon 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
 
185
 
186
		/**
11 ddelon 187
		 * Declaration InventoryItemList
188
		 * @param inventoryItemList
10 ddelon 189
		 */
190
 
11 ddelon 191
		public void registerInventoryItemList(InventoryItemList inventoryItemList) {
10 ddelon 192
 
11 ddelon 193
			this.inventoryItemList=inventoryItemList;
10 ddelon 194
 
195
		}
196
 
197
		/**
11 ddelon 198
		 * Declaration LocationList
10 ddelon 199
		 * @param locationList
200
		 */
201
 
202
		public void registerLocationList(LocationList locationList) {
203
 
204
			this.locationList=locationList;
205
		}
12 ddelon 206
 
10 ddelon 207
 
12 ddelon 208
 
10 ddelon 209
		/**
12 ddelon 210
		 * Declaration DateList
211
		 * @param locationList
212
		 */
213
 
214
		public void registerDateList(DateList dateList) {
215
 
216
			this.dateList=dateList;
217
		}
218
 
219
 
220
 
221
		/**
11 ddelon 222
		 * Declaration Cel
10 ddelon 223
		 * @param cel
224
		 */
225
 
226
		public void registerCel(Cel cel) {
227
 
228
			this.cel=cel;
229
		}
230
 
231
 
11 ddelon 232
		/**
233
		 * Declaration NameAssistant
234
		 * @param nameassistant
235
		 */
236
 
237
		public void registerNameAssistant(NameAssistant nameAssistant) {
238
			this.nameAssistant=nameAssistant;
239
 
240
		}
241
 
242
		/**
243
		 * Declaration LocationAssistant
244
		 * @param locationassistant
245
		 */
246
 
247
		public void registerLocationAssistant(LocationAssistant locationAssistant) {
248
			this.locationAssistant=locationAssistant;
249
 
250
		}
12 ddelon 251
 
11 ddelon 252
 
12 ddelon 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
		}
10 ddelon 280
 
12 ddelon 281
 
10 ddelon 282
		/**
12 ddelon 283
		 * Declaration commentaire
284
		 * @param commentaire
285
		 */
286
 
287
		public void registerComment(TextBox comment) {
288
			this.comment=comment;
289
 
290
		}
291
 
292
 
293
 
294
 
295
		/**
10 ddelon 296
		 * Recherche distante et asynchrone de l'utilisateur connecté, en retour lancement methode initialisation
11 ddelon 297
		 * de l'appellant Cel. (initAsync)
10 ddelon 298
		 *
299
		 */
300
 
301
		private void getUserFromService() {
302
 
303
 
304
			HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
305
					new ResponseTextHandler() {
306
 
307
						public void onCompletion(String str) {
308
							JSONValue jsonValue = JSONParser.parse(str);
309
							JSONString jsonString;
310
							if ((jsonString = jsonValue.isString()) != null) {
311
								user = jsonString.stringValue();
312
							}
313
							cel.initAsync();
314
						}
315
					});
316
 
317
		}
318
 
319
		/**
320
		 * Accesseur Url de base
321
		 * @return Url de base
322
		 */
323
 
324
		public String getServiceBaseUrl() {
325
 
326
			return serviceBaseUrl;
327
 
328
		}
329
 
330
 
331
		/**
332
		 * Recuperation du prefixe d'appel des services
333
		 * @return prefix appel des service
334
		 */
335
 
336
		private String getServiceBaseUrlFromDictionnary() {
337
 
338
			Dictionary theme = Dictionary.getDictionary("Parameters");
339
			return theme.get("serviceBaseUrl");
340
 
341
		}
342
 
343
 
344
		/**
345
		 *  Accesseur Utilisateur
346
		 * @return utilisateur connecté ou identifiant de session
347
		 */
348
 
349
		public String getUser() {
350
			return user;
351
		}
11 ddelon 352
 
10 ddelon 353
 
11 ddelon 354
 
355
		public InventoryItemList getInventoryItemList() {
356
			return inventoryItemList;
357
		}
10 ddelon 358
 
11 ddelon 359
		public LocationList getLocationList() {
360
			return locationList;
361
		}
10 ddelon 362
 
12 ddelon 363
		public DateList getDateList() {
364
			return dateList;
365
		}
366
 
367
 
11 ddelon 368
		public NameAssistant getNameAssistant() {
369
			return nameAssistant;
370
		}
371
 
372
		public LocationAssistant getLocationAssistant() {
373
			return locationAssistant;
374
		}
375
 
12 ddelon 376
		public InventoryItem getInventoryItem() {
377
			return inventoryItem;
378
		}
11 ddelon 379
 
12 ddelon 380
		public EntryPanel getEntryPanel() {
381
			return entryPanel;
382
		}
11 ddelon 383
 
12 ddelon 384
 
385
 
10 ddelon 386
	}