Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 10 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 10 Rev 11
Line 15... Line 15...
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line 17... Line 17...
17
 
17
 
-
 
18
 
18
 
19
import com.google.gwt.json.client.JSONArray;
19
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONNumber;
20
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONParser;
21
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONString;
22
import com.google.gwt.json.client.JSONValue;
23
import com.google.gwt.json.client.JSONValue;
-
 
24
import com.google.gwt.user.client.HTTPRequest;
-
 
25
import com.google.gwt.user.client.ResponseTextHandler;
23
import com.google.gwt.user.client.HTTPRequest;
26
import com.google.gwt.user.client.ui.Button;
-
 
27
import com.google.gwt.user.client.ui.ClickListener;
24
import com.google.gwt.user.client.ResponseTextHandler;
28
import com.google.gwt.user.client.ui.Composite;
25
import com.google.gwt.user.client.ui.Composite;
29
import com.google.gwt.user.client.ui.DockPanel;
-
 
30
import com.google.gwt.user.client.ui.FlexTable;
-
 
31
import com.google.gwt.user.client.ui.Grid;
-
 
32
import com.google.gwt.user.client.ui.HTML;
-
 
33
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
26
import com.google.gwt.user.client.ui.FlexTable;
34
import com.google.gwt.user.client.ui.HasVerticalAlignment;
27
import com.google.gwt.user.client.ui.Grid;
35
import com.google.gwt.user.client.ui.HorizontalPanel;
28
import com.google.gwt.user.client.ui.SourcesTableEvents;
36
import com.google.gwt.user.client.ui.SourcesTableEvents;
-
 
37
import com.google.gwt.user.client.ui.TableListener;
Line 29... Line 38...
29
import com.google.gwt.user.client.ui.TableListener;
38
import com.google.gwt.user.client.ui.VerticalPanel;
30
import com.google.gwt.user.client.ui.VerticalPanel;
39
import com.google.gwt.user.client.ui.Widget;
31
 
40
 
32
/**
41
/**
-
 
42
 * A tree displaying a set of email folders.
-
 
43
 */
-
 
44
public class LocationList extends Composite {
-
 
45
	
-
 
46
	
-
 
47
	
-
 
48
	// Barre de navigation
-
 
49
 
-
 
50
	private class NavBar extends Composite implements ClickListener {
-
 
51
 
-
 
52
		public final DockPanel bar = new DockPanel();
-
 
53
 
-
 
54
		public final Button gotoFirst = new Button("<<", this);
-
 
55
 
-
 
56
		public final Button gotoNext = new Button(">", this);
-
 
57
 
-
 
58
		public final Button gotoPrev = new Button("<", this);
-
 
59
 
-
 
60
		public final Button gotoEnd = new Button(">>", this);
-
 
61
 
-
 
62
		public final HTML status = new HTML();
-
 
63
		
-
 
64
 
-
 
65
		public NavBar() {
-
 
66
			initWidget(bar);
-
 
67
			bar.setStyleName("navbar");
-
 
68
			status.setStyleName("status");
-
 
69
			status.setWordWrap(false);
-
 
70
			
-
 
71
			HorizontalPanel buttons = new HorizontalPanel();
-
 
72
			
-
 
73
			buttons.add(status);
-
 
74
			buttons.setCellHorizontalAlignment(status,
-
 
75
					HasHorizontalAlignment.ALIGN_RIGHT);
-
 
76
			buttons.setCellVerticalAlignment(status,
-
 
77
					HasVerticalAlignment.ALIGN_MIDDLE);
-
 
78
			buttons.setCellWidth(status, "100%");
-
 
79
 
-
 
80
 
-
 
81
			buttons.add(gotoFirst);
-
 
82
			buttons.add(gotoPrev);
-
 
83
			buttons.add(gotoNext);
-
 
84
			buttons.add(gotoEnd);
-
 
85
			bar.add(buttons, DockPanel.EAST);
-
 
86
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
-
 
87
			
-
 
88
			
-
 
89
			bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
-
 
90
 
-
 
91
			bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
-
 
92
			
-
 
93
					
-
 
94
			
-
 
95
	
-
 
96
			
-
 
97
		}
-
 
98
 
-
 
99
		public void onClick(Widget sender) {
-
 
100
			if (sender == gotoNext) {
-
 
101
				// Move forward a page.
-
 
102
				startIndex += VISIBLE_LOCATION_COUNT;
-
 
103
				if (startIndex >= count)
-
 
104
					startIndex -= VISIBLE_LOCATION_COUNT;
-
 
105
			} else {
-
 
106
				if (sender == gotoPrev) {
-
 
107
					// Move back a page.
-
 
108
					startIndex -= VISIBLE_LOCATION_COUNT;
-
 
109
					if (startIndex < 0)
-
 
110
						startIndex = 0;
-
 
111
				} else {
-
 
112
					if (sender == gotoEnd) {
-
 
113
						gotoEnd();
-
 
114
					} else {
-
 
115
						if (sender == gotoFirst) {
-
 
116
							startIndex = 0;
-
 
117
						}
-
 
118
					}
-
 
119
				}
-
 
120
			}
-
 
121
			update();
-
 
122
		}
Line 33... Line 123...
33
 * A tree displaying a set of email folders.
123
 
34
 */
124
	}
Line 53... Line 143...
53
 
143
 
Line 54... Line 144...
54
		private String serviceBaseUrl = null;
144
		private String serviceBaseUrl = null;
Line -... Line 145...
-
 
145
 
-
 
146
		private String location = "all";
-
 
147
		
-
 
148
 
-
 
149
		private NavBar navBar=null;
-
 
150
 
55
 
151
		
56
		private String location = "all";
152
		private int count = 65000;
Line 57... Line 153...
57
		
153
		
Line 68... Line 164...
68
			mediator.registerLocationList(this);
164
			mediator.registerLocationList(this);
Line 69... Line 165...
69
 
165
 
70
			user=mediator.getUser();
166
			user=mediator.getUser();
Line -... Line 167...
-
 
167
			serviceBaseUrl = mediator.getServiceBaseUrl();
71
			serviceBaseUrl = mediator.getServiceBaseUrl();
168
			
72
			
169
			navBar = new NavBar();
Line 73... Line 170...
73
		
170
			
74
			// Mise en forme du header
171
			// Mise en forme du header
75
 
172
 
Line 83... Line 180...
83
			header.setHTML(0, 0, "Localit&eacute;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");  // yeah !
180
			header.setHTML(0, 0, "Localit&eacute;s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");  // yeah !
Line 84... Line 181...
84
 
181
 
Line 85... Line 182...
85
			header.getCellFormatter().setWidth(0, 0, "100%");
182
			header.getCellFormatter().setWidth(0, 0, "100%");
Line 86... Line 183...
86
 
183
 
87
 
184
 
88
			// Mise en forme du selecteur
185
			// Mise en forme de l'entree "Toutes localités"
Line 108... Line 205...
108
		    });
205
		    });
Line 109... Line 206...
109
			
206
			
Line 110... Line 207...
110
			selector.setStyleName("location-ListElement");
207
			selector.setStyleName("location-ListElement");
Line 111... Line 208...
111
 
208
 
112
			
209
			
113
			// Mise en forme de la table.
210
			// Mise en forme du contenu 
114
 
211
 
Line 115... Line 212...
115
			table.setCellSpacing(0);
212
			table.setCellSpacing(0);
Line 116... Line 213...
116
			table.setBorderWidth(0);
213
			table.setBorderWidth(0);
117
			table.setCellPadding(2);
214
			table.setCellPadding(2);
-
 
215
			table.setWidth("100%");
-
 
216
 
-
 
217
			table.setStyleName("location-ListElement");
-
 
218
 
118
			table.setWidth("100%");
219
			// Mise en forme barre navigation
119
 
220
			
120
			table.setStyleName("location-ListElement");
221
			outer.add(navBar);
121
 
222
			
122
			// Mise en forme barre navigation
223
			navBar.setWidth("100%");
123
 
224
			
124
			outer.add(header);
225
			outer.add(header);
Line 149... Line 250...
149
		    
250
		    
150
		  	styleRow(selectedRow, false);
251
		  	styleRow(selectedRow, false);
151
	        selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
252
	        selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
Line -... Line 253...
-
 
253
		    mediator.onLocationSelected("all");
-
 
254
		    		
152
		    mediator.onLocationSelected("all");
255
		    
Line 153... Line 256...
153
		    		
256
			updateCount();
Line 154... Line 257...
154
			update();
257
			// update()
-
 
258
			
-
 
259
			initWidget(outer);
-
 
260
 
-
 
261
 
-
 
262
  }
-
 
263
 
Line -... Line 264...
-
 
264
		/**
155
			
265
		 * Recherche nombre d'enregistrement pour l'utilisateur en cours
-
 
266
		 * 
-
 
267
		 * 
-
 
268
		 */
-
 
269
		
-
 
270
		public void updateCount() {
-
 
271
			
-
 
272
			setStatusDisabled();
-
 
273
 
-
 
274
			HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user ,
-
 
275
					new ResponseTextHandler() {
-
 
276
 
-
 
277
						public void onCompletion(String str) {
-
 
278
							JSONValue jsonValue = JSONParser.parse(str);
-
 
279
							JSONNumber jsonNumber;
-
 
280
							if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
281
								count = (int) jsonNumber.getValue();
-
 
282
								update();
Line 156... Line 283...
156
			initWidget(outer);
283
							}
Line 157... Line 284...
157
 
284
						}
158
 
285
					});
Line 191... Line 318...
191
	 * 
318
	 * 
192
	 */	
319
	 */	
Line 193... Line 320...
193
 
320
 
Line 194... Line -...
194
		public void update() {
-
 
195
 
-
 
196
 
-
 
197
			// TODO : ne pas recreer la table a chaque fois ... : parcouris le retour, le comparer au present
-
 
198
			// et inserer ou supprimer s'il le faut.
-
 
199
 
-
 
200
			// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
-
 
201
			// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
-
 
Line -... Line 321...
-
 
321
		public void update() {
-
 
322
 
202
			
323
			
203
			// TODO : despaghettiser
324
			setStatusDisabled();
Line 204... Line 325...
204
			
325
 
Line 205... Line 326...
205
			HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/"
326
			HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryLocationList/" + user + "/"
Line 206... Line 327...
206
					+ startIndex + "/" + VISIBLE_LOCATION_COUNT,
327
					+ startIndex + "/" + VISIBLE_LOCATION_COUNT,
207
 
328
 
208
			new ResponseTextHandler() {
329
			new ResponseTextHandler() {
209
 
330
 
210
				public void onCompletion(String str) {
-
 
211
 
331
				public void onCompletion(String str) {
212
					JSONValue jsonValue = JSONParser.parse(str);
332
 
Line 213... Line -...
213
					JSONArray jsonArray;
-
 
214
					JSONArray jsonArrayNested;
-
 
215
 
-
 
216
					for (int i = table.getRowCount() - 1; i >= 0; i--) {
-
 
217
							table.removeRow(i);
-
 
218
					}
-
 
219
					
333
					JSONValue jsonValue = JSONParser.parse(str);
220
					if (location.compareTo("all")==0) {
334
					JSONArray jsonArray;
221
						styleRow(selectedRow, false);
335
					JSONArray jsonArrayNested;
222
						selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
336
			
-
 
337
					int row=0;
223
					}
338
					int i=0;
-
 
339
					
-
 
340
					if ((jsonArray = jsonValue.isArray()) != null) {
-
 
341
						int arraySize = jsonArray.size();
-
 
342
						for (i = 0; i < arraySize; ++i) {
224
 
343
							if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
Line 225... Line 344...
225
						
344
								if (i>=table.getRowCount()) {
Line 226... Line 345...
226
					if ((jsonArray = jsonValue.isArray()) != null) {
345
									 row = table.insertRow(table.getRowCount());
Line 240... Line 359...
240
								}
359
								}
Line 241... Line 360...
241
								
360
								
242
								if (loc.compareTo(location)==0) {
361
								if (loc.compareTo(location)==0) {
243
								  styleRow(row, true);
362
								  styleRow(row, true);
-
 
363
								}
-
 
364
								else {
-
 
365
								  styleRow(row, false);
Line 244... Line 366...
244
								}
366
								}
245
 
367
 
Line 246... Line 368...
246
								table.getFlexCellFormatter().setWidth(row, 0, "100%");
368
								table.getFlexCellFormatter().setWidth(row, 0, "100%");
247
							}
369
							}
-
 
370
 
-
 
371
						}
-
 
372
					}
-
 
373
					
-
 
374
					if (location.compareTo("all")==0) {
-
 
375
							selector.getRowFormatter().addStyleName(0, "location-SelectedRow");
-
 
376
					}
-
 
377
 
-
 
378
					
-
 
379
					// Suppression fin ancien affichage
-
 
380
					if (i<table.getRowCount()-1) {
-
 
381
						 for (int j = table.getRowCount() - 1; j > i-1; j--) {
-
 
382
							 table.removeRow(j);
-
 
383
						 }
Line 248... Line 384...
248
 
384
					}
249
						}
385
					setStatusEnabled();
Line 250... Line 386...
250
					}
386
 
Line 257... Line 393...
257
		public void setLocation(String location) {
393
		public void setLocation(String location) {
258
			this.location = location;
394
			this.location = location;
259
		}
395
		}
Line -... Line 396...
-
 
396
		
-
 
397
		
-
 
398
			
-
 
399
		/*
-
 
400
		 * Positionnement index de parcours (this.startIndex) pour affichage de la
-
 
401
		 * dernière page
-
 
402
		 * 
-
 
403
		 * @param
-
 
404
		 * @return void
-
 
405
		 */
-
 
406
 
-
 
407
		private void gotoEnd() {
-
 
408
 
-
 
409
			if ((count == 0) || (count % VISIBLE_LOCATION_COUNT) > 0) {
-
 
410
				startIndex = count - (count % VISIBLE_LOCATION_COUNT);
-
 
411
			} else {
-
 
412
				startIndex = count - VISIBLE_LOCATION_COUNT;
-
 
413
			}
-
 
414
 
-
 
415
		}
-
 
416
		
-
 
417
		
-
 
418
		/**
-
 
419
		 * Affichage message d'attente et désactivation navigation
-
 
420
		 * 
-
 
421
		 * @param
-
 
422
		 * @return void
-
 
423
		 */
-
 
424
 
-
 
425
		private void setStatusDisabled() {
-
 
426
 
-
 
427
			navBar.gotoFirst.setEnabled(false);
-
 
428
			navBar.gotoPrev.setEnabled(false);
-
 
429
			navBar.gotoNext.setEnabled(false);
-
 
430
			navBar.gotoEnd.setEnabled(false);
-
 
431
 
-
 
432
			setStatusText("Patientez ...");
-
 
433
		}
-
 
434
 
-
 
435
		/**
-
 
436
		 * Affichage numero de page et gestion de la navigation
-
 
437
		 * 
-
 
438
		 */
-
 
439
 
-
 
440
		private void setStatusEnabled() {
-
 
441
 
-
 
442
			// Il y a forcemment un disabled avant d'arriver ici
-
 
443
 
-
 
444
			if (count > 0) {
-
 
445
 
-
 
446
				if (startIndex >= VISIBLE_LOCATION_COUNT) { // Au dela de la
-
 
447
															// premiere page
-
 
448
					navBar.gotoPrev.setEnabled(true);
-
 
449
					navBar.gotoFirst.setEnabled(true);
-
 
450
					if (startIndex < (count - VISIBLE_LOCATION_COUNT)) { // Pas la
-
 
451
																		// derniere
-
 
452
																		// page
-
 
453
						navBar.gotoNext.setEnabled(true);
-
 
454
						navBar.gotoEnd.setEnabled(true);
-
 
455
						setStatusText((startIndex + 1) + " - "
-
 
456
								+ (startIndex + VISIBLE_LOCATION_COUNT) + " sur " + count );
-
 
457
					} else { // Derniere page
-
 
458
						setStatusText((startIndex + 1) + " - " + count + " sur " + count );
-
 
459
					}
-
 
460
				} else { // Premiere page
-
 
461
					if (count > VISIBLE_LOCATION_COUNT) { // Des pages derrieres
-
 
462
						navBar.gotoNext.setEnabled(true);
-
 
463
						navBar.gotoEnd.setEnabled(true);
-
 
464
						setStatusText((startIndex + 1) + " - "
-
 
465
								+ (startIndex + VISIBLE_LOCATION_COUNT) + " sur " + count);
-
 
466
					} else {
-
 
467
						setStatusText((startIndex + 1) + " - " + count + " sur " + count);
-
 
468
					}
-
 
469
				}
-
 
470
			}
-
 
471
 
-
 
472
			else { // Pas d'inventaire, pas de navigation
-
 
473
				setStatusText("0 - 0 sur 0");
-
 
474
			}
-
 
475
		}
260
		
476
 
-
 
477
 
-
 
478
 
-
 
479
		private void setStatusText(String text) {
Line 261... Line 480...
261
		
480
			navBar.status.setText(text);