Subversion Repositories eFlore/Archives.cel-v1

Rev

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

Rev 3 Rev 4
Line 14... Line 14...
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
Line -... Line 17...
-
 
17
 
17
 
18
 
18
 
19
import com.google.gwt.i18n.client.Dictionary;
19
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONNumber;
21
import com.google.gwt.json.client.JSONNumber;
21
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONParser;
Line 31... Line 32...
31
import com.google.gwt.user.client.ui.VerticalPanel;
32
import com.google.gwt.user.client.ui.VerticalPanel;
32
import com.google.gwt.user.client.ui.DockPanel;
33
import com.google.gwt.user.client.ui.DockPanel;
33
import com.google.gwt.user.client.ui.Button;
34
import com.google.gwt.user.client.ui.Button;
34
import com.google.gwt.user.client.ui.CheckBox;
35
import com.google.gwt.user.client.ui.CheckBox;
35
import com.google.gwt.user.client.ui.Widget;
36
import com.google.gwt.user.client.ui.Widget;
36
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
-
 
37
import com.google.gwt.user.client.ui.ClickListener;
37
import com.google.gwt.user.client.ui.ClickListener;
-
 
38
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
38
import com.google.gwt.user.client.ui.HasAlignment;
39
import com.google.gwt.user.client.ui.HasVerticalAlignment;
-
 
40
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
Line -... Line 41...
-
 
41
 
-
 
42
import java.util.Vector;
-
 
43
 
-
 
44
 
Line 39... Line 45...
39
 
45
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte
40
 
46
 
41
/**
47
/**
42
 * A composite that displays a list of emails that can be selected.
48
 * A composite that displays a list of emails that can be selected.
Line 66... Line 72...
66
	      buttons.add(gotoEnd);
72
	      buttons.add(gotoEnd);
67
	      bar.add(buttons, DockPanel.EAST);
73
	      bar.add(buttons, DockPanel.EAST);
68
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
74
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
69
	      bar.add(status, DockPanel.CENTER);
75
	      bar.add(status, DockPanel.CENTER);
70
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
76
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
71
	      bar.setCellHorizontalAlignment(status, HasAlignment.ALIGN_RIGHT);
77
	      bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
72
	      bar.setCellVerticalAlignment(status, HasAlignment.ALIGN_MIDDLE);
78
	      bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
73
	      bar.setCellWidth(status, "100%");
79
	      bar.setCellWidth(status, "100%");
Line 74... Line 80...
74
 
80
 
75
	      // Initialize prev & first button to disabled.
81
	      // Initialize prev & first button to disabled.
76
	      //
82
	      //
Line 122... Line 128...
122
 
128
 
Line 123... Line 129...
123
	
129
	
124
 
130
 
125
  private static final int VISIBLE_TAXON_COUNT = 15;
-
 
126
	
131
  private static final int VISIBLE_TAXON_COUNT = 15;
127
  private Grid header = new Grid(1,3);
132
	
128
  private FlexTable table = new FlexTable();
133
  private Grid header = new Grid(1,6);
-
 
134
  private FlexTable table = new FlexTable();
129
  private CellFormatter cellFormater = table.getCellFormatter();
135
  private VerticalPanel panel = new VerticalPanel();
Line -... Line 136...
-
 
136
 
-
 
137
  private int startIndex=0;
-
 
138
  private String serviceBaseUrl=getServiceBaseUrl();
-
 
139
  private int count=65000;
-
 
140
  
-
 
141
  private Vector complements=null;
130
  private VerticalPanel panel = new VerticalPanel();
142
  private String element=null;
Line 131... Line 143...
131
  
143
  private String complement=null;
Line 132... Line 144...
132
  private int startIndex=0;
144
  
-
 
145
  private String user;
-
 
146
  
-
 
147
  private NavBar navBar = new NavBar();
-
 
148
  
-
 
149
  public TaxonList(Vector comps) {
-
 
150
 
133
  private int count=65000;
151
	 
134
  
152
	getUser();
Line 135... Line 153...
135
  private NavBar navBar = new NavBar();
153
 
136
  
154
	
137
  public TaxonList() {
155
	// Information complementaire
Line 138... Line 156...
138
 
156
	
Line 139... Line 157...
139
	  
157
	complements=comps;
140
	  
158
	
141
    // Setup the header
159
    // Setup the header
-
 
160
	  
-
 
161
    header.setCellSpacing(0);
-
 
162
    header.setCellPadding(2);
-
 
163
    header.setWidth("100%");
-
 
164
 
-
 
165
    header.setStyleName("taxon-ListHeader");
-
 
166
    
-
 
167
    header.setText(0, 0, "");
-
 
168
    header.setText(0, 1, "Nom saisi");
-
 
169
    header.setText(0, 2, "Nom retenu");
-
 
170
    header.setHTML(0, 3, "Code<br>Nomenclatural");
142
	  
171
    header.setHTML(0, 4, "Code<br>Taxonomique");
143
    header.setCellSpacing(0);
172
    header.setText(0, 5, "");
-
 
173
  
-
 
174
	header.getCellFormatter().setWidth(0,0,"2%");
144
    header.setCellPadding(2);
175
	header.getCellFormatter().setWidth(0,1,"31%");
145
    header.setWidth("100%");
176
	header.getCellFormatter().setWidth(0,2,"31%");
Line 146... Line 177...
146
 
177
	header.getCellFormatter().setWidth(0,3,"9%");
-
 
178
	header.getCellFormatter().setWidth(0,4,"9%");
147
    header.setStyleName("taxon-ListHeader");
179
	header.getCellFormatter().setWidth(0,5,"18%");
148
    
180
 
Line 149... Line 181...
149
    header.setText(0, 0, "Action");
181
	
Line 169... Line 201...
169
    panel.add(header);
201
    panel.add(header);
170
    panel.add(table);
202
    panel.add(table);
Line 171... Line 203...
171
    
203
    
Line 172... Line -...
172
    initWidget(panel);
-
 
173
    
204
    initWidget(panel);
174
    // Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
-
 
175
 
-
 
176
    
-
 
177
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/", 
-
 
178
		    new ResponseTextHandler(){
-
 
179
 
-
 
180
		    	public void onCompletion(String str) {
-
 
181
 
-
 
182
// On se positionne sur la dernière page ...
-
 
183
		    		
-
 
184
		    		JSONValue jsonValue= JSONParser.parse(str);
-
 
185
		    		JSONNumber jsonNumber;
-
 
186
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
187
		    		    	count=(int) jsonNumber.getValue();
-
 
188
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
189
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
190
		    		    	}
-
 
191
		    		    	else {
-
 
192
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
193
		    		    	}
-
 
194
	 				
-
 
195
		    		    	update();
-
 
196
		    		    }
-
 
197
		    	}
-
 
198
	 	});
-
 
199
    
205
    
Line 200... Line 206...
200
 
206
 
Line -... Line 207...
-
 
207
  }
-
 
208
 
201
  }
209
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
Line -... Line 210...
-
 
210
		
-
 
211
	  
-
 
212
// Recherche informations complementaires :
-
 
213
// et Ajout ligne 
-
 
214
	 
-
 
215
	    if (pos>=0) {
Line -... Line 216...
-
 
216
	    complement=(String) complements.get(pos);
-
 
217
	    element=str;
-
 
218
	 
-
 
219
		 HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, 
-
 
220
				    new ResponseTextHandler(){
202
 
221
 
203
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
222
				    	public void onCompletion(String str) {
-
 
223
		    
-
 
224
							JSONValue jsonValue= JSONParser.parse(str);
204
		
225
				  			JSONArray jsonArray;
-
 
226
				
-
 
227
				  			complements.clear();
-
 
228
				  			
-
 
229
				  			if ((jsonArray = jsonValue.isArray()) != null) {
-
 
230
				  					  // Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
-
 
231
								      addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
-
 
232
								    		  ((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
-
 
233
								    		  ((JSONString) jsonArray.get(3)).stringValue());
205
// Ajout ligne 
234
				  			}
Line -... Line 235...
-
 
235
				    	} 
-
 
236
 
-
 
237
				   	});
-
 
238
	    }
-
 
239
	    else {
-
 
240
 			complements.clear();
-
 
241
 
-
 
242
			addElement(str," "," "," "," "," ");
-
 
243
	    }
-
 
244
  }
-
 
245
  
-
 
246
 
-
 
247
  public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
-
 
248
	 
-
 
249
	  int lastOrdre=1;
-
 
250
	  if (table.getRowCount()>0) {
-
 
251
		  lastOrdre=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
206
	 
252
	  }
207
 
253
		  
208
	    count++;
254
	  count++;
209
	  
255
	  HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
210
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str, 
256
			  +"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille+"&ordre="+lastOrdre,
211
	    new ResponseTextHandler(){
257
	  new ResponseTextHandler(){
212
 
258
	
-
 
259
	  	public void onCompletion(String str) {
-
 
260
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
261
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
213
	    	public void onCompletion(String str) {
262
		    	}
214
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
263
		    	else {
215
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
264
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
216
		    	}
-
 
217
		    	else {
-
 
218
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
265
		    	}
219
		    	}
-
 
Line -... Line 266...
-
 
266
		    	if (startIndex < 0) {
220
		    	update();
267
			  	    startIndex = 0;
Line 221... Line 268...
221
	    	}
268
			  	}
222
	    });
269
		    	update();
223
	    
270
	  	}
224
 
271
	  });
225
  }
272
  }
226
  
273
 
227
 
274
  
Line 228... Line 275...
228
  public void deleteElement() {
275
  public void deleteElement() {
229
 
276
 
230
	    // Lifo ...
-
 
231
      for (int i=table.getRowCount()-1; i>=0;i--){
-
 
232
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
-
 
233
			String str=table.getText(i,2);
277
	    // Lifo ...
234
			count--;
278
      for (int i=table.getRowCount()-1; i>=0;i--){
-
 
279
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
-
 
280
			String str=table.getText(i,6);
-
 
281
			count--;
235
			 HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE", 
282
			 HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", 
236
			   new ResponseTextHandler(){
283
			   new ResponseTextHandler(){
237
 
284
 
Line 238... Line 285...
238
			   	public void onCompletion(String str) {
285
			   	public void onCompletion(String str) {
239
			   		if ((count%VISIBLE_TAXON_COUNT)>0) {
286
			    	if ((count%VISIBLE_TAXON_COUNT)==0) {
240
			    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
287
			    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
288
			    	}
-
 
289
			    	if (startIndex < 0) {
-
 
290
				  	    startIndex = 0;
-
 
291
				  	}
-
 
292
			    	update();
-
 
293
			   	}
-
 
294
			  });
-
 
295
 
-
 
296
	  	 }
-
 
297
	  }
-
 
298
  }
-
 
299
 
-
 
300
  private void getUser() {
-
 
301
		 HTTPRequest.asyncGet(serviceBaseUrl+"/User/", 
-
 
302
				    new ResponseTextHandler(){
-
 
303
 
-
 
304
				    	public void onCompletion(String str) {
-
 
305
				    		JSONValue jsonValue= JSONParser.parse(str);
-
 
306
				    		JSONString jsonString;
Line -... Line 307...
-
 
307
				    		    if ((jsonString = jsonValue.isString()) != null) {
-
 
308
				    		    	user = jsonString.stringValue();
-
 
309
				    		    }
-
 
310
				    		    getCount();
-
 
311
				    	}
-
 
312
			 	});
-
 
313
		    
-
 
314
		  
-
 
315
 
-
 
316
		}  
-
 
317
 
-
 
318
  
-
 
319
  private void getCount() {
-
 
320
  // Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
-
 
321
 
-
 
322
  
-
 
323
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", 
-
 
324
		    new ResponseTextHandler(){
-
 
325
 
-
 
326
		    	public void onCompletion(String str) {
-
 
327
 
-
 
328
//On se positionne sur la dernière page ...
-
 
329
		    		
-
 
330
		    		JSONValue jsonValue= JSONParser.parse(str);
-
 
331
		    		JSONNumber jsonNumber;
-
 
332
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
333
		    		    	count=(int) jsonNumber.getValue();
-
 
334
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
335
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
336
		    		    	}
-
 
337
		    		    	else {
-
 
338
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
Line 241... Line 339...
241
			    	}
339
		    		    	}
-
 
340
		    		    	if (startIndex < 0) {
-
 
341
		    			  	    startIndex = 0;
-
 
342
		    			  	}
Line 242... Line 343...
242
			    	else {
343
	 				
243
			    		startIndex=count-VISIBLE_TAXON_COUNT; 
344
		    		    	update();
244
			    	}
345
		    		    }
245
			    	update();
346
		    	}
Line 246... Line 347...
246
			   	}
347
	 	});
Line 247... Line 348...
247
			  });
348
 
248
 
349
  }
Line 249... Line 350...
249
	  	 }
350
 
Line 250... Line 351...
250
	  }
351
  
Line 273... Line 374...
273
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
374
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
274
		                        table.removeRow(i);
375
		                        table.removeRow(i);
275
		                }
376
		                }
Line -... Line 377...
-
 
377
 
276
 
378
 
277
 
379
		    		    int j=0;
278
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
380
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
279
		    		      int i; 	
381
		    		      int i; 	
280
		    		      for (i = 0; i < jsonArray.size(); ++i) {
382
		    		      for (i = 0; i < jsonArray.size(); ++i) {
-
 
383
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
281
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
384
		    		    		  int row=table.insertRow(table.getRowCount());
-
 
385
		    		    		  // Case a cocher
282
		    		    		  int row=table.insertRow(table.getRowCount());
386
		    		    		  table.setWidget(row,0,new CheckBox());
-
 
387
		    		    		  // Nom saisi
283
		    		    		  table.setWidget(row,0,new CheckBox());
388
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
-
 
389
		    		    		  // Nom retenu
-
 
390
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
-
 
391
		    		    		  // Num nomenclatural
-
 
392
		    		    		  table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
-
 
393
		    		    		  // Num Taxonomique
-
 
394
		    		    		  table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
-
 
395
		    		    		  // Famille
-
 
396
		    		    		  table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
-
 
397
		    		    		  // Numero d'ordre
284
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
398
		    		    		  table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
-
 
399
		    		    		  
-
 
400
		    		    		  table.getCellFormatter().setVisible(row,6,true);
-
 
401
		    		    		  
-
 
402
		    		    		  table.getFlexCellFormatter().setWidth(row,0,"2%");
-
 
403
		    		    		  table.getFlexCellFormatter().setWidth(row,1,"31%");
-
 
404
		    		    		  table.getFlexCellFormatter().setWidth(row,2,"31%");
-
 
405
		    		    		  table.getFlexCellFormatter().setWidth(row,3,"9%");
-
 
406
		    		    		  table.getFlexCellFormatter().setWidth(row,4,"9%");
285
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
407
		    		    		  table.getFlexCellFormatter().setWidth(row,5,"18%");
-
 
408
		    		    		  j++;
286
		    		    		  cellFormater.setVisible(row,2,false);
409
		    		    	  }
287
		    		    	  }
410
		    		    	  
288
		    		      }
411
		    		      }
289
		    		      // Calcul nombre d'enregistrement total
412
		    		      // Calcul nombre d'enregistrement total (c'est un doublon, c'est normal ...)
290
		    		      if (i<VISIBLE_TAXON_COUNT) {
413
		    		      if (i<VISIBLE_TAXON_COUNT) {
Line 291... Line 414...
291
		    		    	  count = startIndex+i;
414
		    		    	  count = startIndex+i;
Line 292... Line -...
292
		    		      }
-
 
Line 293... Line 415...
293
		    		      
415
		    		      }
294
		    		      // Navigation 
416
		    		      
295
		    		      
417
		    		      // Navigation 
296
		    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
418
		    		      
297
 
419
 
298
		    		      // Premiere page 
420
		    		      // Premiere page 
-
 
421
		    		      if (startIndex<VISIBLE_TAXON_COUNT ) {
-
 
422
		    		    		navBar.gotoPrev.setEnabled(false);
-
 
423
		    		    		navBar.gotoFirst.setEnabled(false);
-
 
424
		    		    		navBar.gotoNext.setEnabled(true);
-
 
425
		    		    		navBar.gotoEnd.setEnabled(true);
-
 
426
		    		    		if (count < VISIBLE_TAXON_COUNT) {
Line 299... Line 427...
299
		    		      if (startIndex<VISIBLE_TAXON_COUNT) {
427
		    		    			setStatusText((startIndex + 1) + " - " + count );
300
		    		    		navBar.gotoPrev.setEnabled(false);
428
		    		    		}
301
		    		    		navBar.gotoFirst.setEnabled(false);
429
		    		    		else {
302
		    		    		navBar.gotoNext.setEnabled(true);
430
				    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
Line 310... Line 438...
310
		    		    		navBar.gotoFirst.setEnabled(true);
438
		    		    		navBar.gotoFirst.setEnabled(true);
311
		    		    		navBar.gotoNext.setEnabled(false);
439
		    		    		navBar.gotoNext.setEnabled(false);
312
		    		    		navBar.gotoEnd.setEnabled(false);
440
		    		    		navBar.gotoEnd.setEnabled(false);
313
		    		    		setStatusText((startIndex + 1) + " - " + count);
441
		    		    		setStatusText((startIndex + 1) + " - " + count);
314
		    		    	  }
442
		    		    	  }
-
 
443
		    		    	  // Page normale 
315
		    		    	  else {
444
		    		    	  else {
316
				    		      navBar.gotoPrev.setEnabled(true);
445
				    		      navBar.gotoPrev.setEnabled(true);
317
				    		      navBar.gotoFirst.setEnabled(true);
446
				    		      navBar.gotoFirst.setEnabled(true);
318
				    		      navBar.gotoNext.setEnabled(true);
447
				    		      navBar.gotoNext.setEnabled(true);
319
				    		      navBar.gotoEnd.setEnabled(true);
448
				    		      navBar.gotoEnd.setEnabled(true);
-
 
449
				    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
320
		    		    	  }
450
		    		    	  }
321
		    		      }
451
		    		      }
322
		    		    }
452
		    		    }
-
 
453
		    		    // Tableau vide (TODO : despaguettiser)
-
 
454
		    		    if (j==0) {
-
 
455
		    		    	   navBar.gotoPrev.setEnabled(false);
-
 
456
				    		   navBar.gotoFirst.setEnabled(false);
-
 
457
				    		   navBar.gotoNext.setEnabled(false);
-
 
458
				    		   navBar.gotoEnd.setEnabled(false);
-
 
459
				    		   setStatusText(0 + " - " + 0);
-
 
460
		    		    }
323
		    	}
461
		    	}
324
		    });
462
		    });
Line 325... Line 463...
325
 
463
 
Line -... Line 464...
-
 
464
  }
326
  }
465
 
-
 
466
private String getServiceBaseUrl() {
-
 
467
	  
-
 
468
	  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
469
	  return theme.get("serviceBaseUrl");
-
 
470
	  
327
 
471
 
328
  
472
	}  
Line 329... Line 473...
329
  
473