Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 3 | Go to most recent revision | Show entire file | Regard 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;
-
 
41
 
-
 
42
import java.util.Vector;
-
 
43
 
Line -... Line 44...
-
 
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;
Line 127... Line 132...
127
  private Grid header = new Grid(1,3);
132
	
-
 
133
  private Grid header = new Grid(1,6);
128
  private FlexTable table = new FlexTable();
134
  private FlexTable table = new FlexTable();
Line -... Line 135...
-
 
135
  private VerticalPanel panel = new VerticalPanel();
-
 
136
 
-
 
137
  private int startIndex=0;
-
 
138
  private String serviceBaseUrl=getServiceBaseUrl();
-
 
139
  private int count=65000;
-
 
140
  
129
  private CellFormatter cellFormater = table.getCellFormatter();
141
  private Vector complements=null;
Line 130... Line 142...
130
  private VerticalPanel panel = new VerticalPanel();
142
  private String element=null;
-
 
143
  private String complement=null;
Line -... Line 144...
-
 
144
  
Line -... Line 145...
-
 
145
  private String user;
-
 
146
  
-
 
147
  private NavBar navBar = new NavBar();
-
 
148
  
131
  
149
  public TaxonList(Vector comps) {
Line 132... Line 150...
132
  private int startIndex=0;
150
 
133
  private int count=65000;
151
	 
134
  
152
	getUser();
Line 135... Line 153...
135
  private NavBar navBar = new NavBar();
153
 
Line 136... Line 154...
136
  
154
	
137
  public TaxonList() {
155
	// Information complementaire
138
 
156
	
-
 
157
	complements=comps;
-
 
158
	
-
 
159
    // Setup the header
-
 
160
	  
-
 
161
    header.setCellSpacing(0);
-
 
162
    header.setCellPadding(2);
-
 
163
    header.setWidth("100%");
-
 
164
 
-
 
165
    header.setStyleName("taxon-ListHeader");
-
 
166
    
Line -... Line 167...
-
 
167
    header.setText(0, 0, "");
-
 
168
    header.setText(0, 1, "Nom saisi");
-
 
169
    header.setText(0, 2, "Nom retenu");
139
	  
170
    header.setHTML(0, 3, "Code<br>Nomenclatural");
Line 140... Line 171...
140
	  
171
    header.setHTML(0, 4, "Code<br>Taxonomique");
-
 
172
    header.setText(0, 5, "");
141
    // Setup the header
173
  
142
	  
174
	header.getCellFormatter().setWidth(0,0,"2%");
Line 143... Line 175...
143
    header.setCellSpacing(0);
175
	header.getCellFormatter().setWidth(0,1,"31%");
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);
-
 
Line -... Line 204...
-
 
204
    initWidget(panel);
Line -... Line 205...
-
 
205
    
-
 
206
 
-
 
207
  }
-
 
208
 
-
 
209
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
-
 
210
		
-
 
211
	  
-
 
212
// Recherche informations complementaires :
-
 
213
// et Ajout ligne 
-
 
214
	 
173
    
215
	    if (pos>=0) {
174
    // Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
216
	    complement=(String) complements.get(pos);
Line 175... Line 217...
175
 
217
	    element=str;
Line 176... Line -...
176
    
-
 
177
	 HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/", 
-
 
178
		    new ResponseTextHandler(){
218
	 
179
 
219
		 HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, 
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();
-
 
Line 188... Line 220...
188
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
220
				    new ResponseTextHandler(){
-
 
221
 
-
 
222
				    	public void onCompletion(String str) {
-
 
223
		    
-
 
224
							JSONValue jsonValue= JSONParser.parse(str);
-
 
225
				  			JSONArray jsonArray;
-
 
226
				
189
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
227
				  			complements.clear();
190
		    		    	}
228
				  			
191
		    		    	else {
-
 
Line -... Line 229...
-
 
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(),
Line -... Line 233...
-
 
233
								    		  ((JSONString) jsonArray.get(3)).stringValue());
-
 
234
				  			}
192
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
235
				    	} 
Line 193... Line -...
193
		    		    	}
-
 
Line 194... Line -...
194
	 				
-
 
-
 
236
 
Line -... Line 237...
-
 
237
				   	});
-
 
238
	    }
-
 
239
	    else {
-
 
240
 			complements.clear();
Line 195... Line 241...
195
		    		    	update();
241
 
196
		    		    }
-
 
197
		    	}
242
			addElement(str," "," "," "," "," ");
-
 
243
	    }
198
	 	});
244
  }
Line 199... Line 245...
199
    
245
  
200
 
246
 
201
  }
247
  public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
202
 
248
	 
203
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
249
	  int lastOrdre=1;
204
		
250
	  if (table.getRowCount()>0) {
205
// Ajout ligne 
251
		  lastOrdre=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
-
 
252
	  }
-
 
253
		  
-
 
254
	  count++;
206
	 
255
	  HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
207
 
256
			  +"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille+"&ordre="+lastOrdre,
208
	    count++;
257
	  new ResponseTextHandler(){
209
	  
-
 
210
	    HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str, 
-
 
211
	    new ResponseTextHandler(){
258
	
Line 212... Line 259...
212
 
259
	  	public void onCompletion(String str) {
Line 213... Line 260...
213
	    	public void onCompletion(String str) {
260
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
214
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
261
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
215
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
262
		    	}
216
		    	}
263
		    	else {
217
		    	else {
264
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
218
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
265
		    	}
-
 
266
		    	if (startIndex < 0) {
-
 
267
			  	    startIndex = 0;
-
 
268
			  	}
-
 
269
		    	update();
-
 
270
	  	}
-
 
271
	  });
-
 
272
  }
-
 
273
 
-
 
274
  
-
 
275
  public void deleteElement() {
-
 
276
 
-
 
277
	    // Lifo ...
-
 
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--;
-
 
282
			 HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", 
-
 
283
			   new ResponseTextHandler(){
-
 
284
 
219
		    	}
285
			   	public void onCompletion(String str) {
Line 220... Line 286...
220
		    	update();
286
			    	if ((count%VISIBLE_TAXON_COUNT)==0) {
-
 
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;
-
 
307
				    		    if ((jsonString = jsonValue.isString()) != null) {
-
 
308
				    		    	user = jsonString.stringValue();
-
 
309
				    		    }
-
 
310
				    		    getCount();
-
 
311
				    	}
-
 
312
			 	});
-
 
313
		    
-
 
314
		  
-
 
315
 
221
	    	}
316
		}  
222
	    });
317
 
223
	    
318
  
224
 
319
  private void getCount() {
225
  }
320
  // Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
226
  
321
 
-
 
322
  
227
 
323
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", 
228
  public void deleteElement() {
324
		    new ResponseTextHandler(){
229
 
-
 
Line -... Line 325...
-
 
325
 
230
	    // Lifo ...
326
		    	public void onCompletion(String str) {
231
      for (int i=table.getRowCount()-1; i>=0;i--){
327
 
-
 
328
//On se positionne sur la dernière page ...
-
 
329
		    		
232
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
330
		    		JSONValue jsonValue= JSONParser.parse(str);
Line 233... Line 331...
233
			String str=table.getText(i,2);
331
		    		JSONNumber jsonNumber;
Line -... Line 332...
-
 
332
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
-
 
333
		    		    	count=(int) jsonNumber.getValue();
-
 
334
		    		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
234
			count--;
335
		    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
235
			 HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE", 
336
		    		    	}
236
			   new ResponseTextHandler(){
337
		    		    	else {
237
 
338
		    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
Line 238... Line 339...
238
			   	public void onCompletion(String str) {
339
		    		    	}
Line 239... Line 340...
239
			   		if ((count%VISIBLE_TAXON_COUNT)>0) {
340
		    		    	if (startIndex < 0) {
240
			    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
341
		    			  	    startIndex = 0;
Line 241... Line 342...
241
			    	}
342
		    			  	}
Line 242... Line 343...
242
			    	else {
343
	 				
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
  }
Line -... Line 465...
-
 
465
 
-
 
466
private String getServiceBaseUrl() {
-
 
467
	  
-
 
468
	  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
469
	  return theme.get("serviceBaseUrl");
Line 326... Line 470...
326
  }
470