Subversion Repositories eFlore/Archives.cel-v1

Rev

Rev 4 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 5
1
/*
1
/*
2
 * Copyright 2006 Google Inc.
2
 * Copyright 2006 Google Inc.
3
 * 
3
 * 
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
4
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
 * use this file except in compliance with the License. You may obtain a copy of
5
 * use this file except in compliance with the License. You may obtain a copy of
6
 * the License at
6
 * the License at
7
 * 
7
 * 
8
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * http://www.apache.org/licenses/LICENSE-2.0
9
 * 
9
 * 
10
 * Unless required by applicable law or agreed to in writing, software
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
 * License for the specific language governing permissions and limitations under
13
 * License for the specific language governing permissions and limitations under
14
 * the License.
14
 * the License.
15
 */
15
 */
16
package org.tela_botanica.client;
16
package org.tela_botanica.client;
17
 
17
 
18
 
18
 
19
import com.google.gwt.i18n.client.Dictionary;
19
import com.google.gwt.i18n.client.Dictionary;
20
import com.google.gwt.json.client.JSONArray;
20
import com.google.gwt.json.client.JSONArray;
21
import com.google.gwt.json.client.JSONNumber;
21
import com.google.gwt.json.client.JSONNumber;
22
import com.google.gwt.json.client.JSONParser;
22
import com.google.gwt.json.client.JSONParser;
23
import com.google.gwt.json.client.JSONString;
23
import com.google.gwt.json.client.JSONString;
24
import com.google.gwt.json.client.JSONValue;
24
import com.google.gwt.json.client.JSONValue;
25
import com.google.gwt.user.client.HTTPRequest;
25
import com.google.gwt.user.client.HTTPRequest;
26
import com.google.gwt.user.client.ResponseTextHandler;
26
import com.google.gwt.user.client.ResponseTextHandler;
27
import com.google.gwt.user.client.ui.Composite;
27
import com.google.gwt.user.client.ui.Composite;
28
import com.google.gwt.user.client.ui.FlexTable;
28
import com.google.gwt.user.client.ui.FlexTable;
29
import com.google.gwt.user.client.ui.Grid;
29
import com.google.gwt.user.client.ui.Grid;
30
import com.google.gwt.user.client.ui.HTML;
30
import com.google.gwt.user.client.ui.HTML;
31
import com.google.gwt.user.client.ui.HorizontalPanel;
31
import com.google.gwt.user.client.ui.HorizontalPanel;
32
import com.google.gwt.user.client.ui.VerticalPanel;
32
import com.google.gwt.user.client.ui.VerticalPanel;
33
import com.google.gwt.user.client.ui.DockPanel;
33
import com.google.gwt.user.client.ui.DockPanel;
34
import com.google.gwt.user.client.ui.Button;
34
import com.google.gwt.user.client.ui.Button;
35
import com.google.gwt.user.client.ui.CheckBox;
35
import com.google.gwt.user.client.ui.CheckBox;
36
import com.google.gwt.user.client.ui.Widget;
36
import com.google.gwt.user.client.ui.Widget;
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.HasHorizontalAlignment;
39
import com.google.gwt.user.client.ui.HasVerticalAlignment;
39
import com.google.gwt.user.client.ui.HasVerticalAlignment;
40
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter;
-
 
41
 
40
 
42
import java.util.Vector;
41
import java.util.Vector;
43
 
42
 
44
 
43
 
45
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte
44
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte
46
 
-
 
47
/**
-
 
48
 * A composite that displays a list of emails that can be selected.
45
 
-
 
46
 */
49
 */
47
 
50
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
48
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener  {
51
 
49
 
-
 
50
 
-
 
51
	
-
 
52
// Barre de navigation 
52
 
53
	
53
	  private class NavBar extends Composite implements ClickListener {
54
	  private class NavBar extends Composite implements ClickListener {
54
		  
55
		  
55
	    public final DockPanel bar = new DockPanel();
56
	    public final DockPanel bar = new DockPanel();
56
	    public final Button gotoFirst = new Button("<<", this);
57
	    public final Button gotoFirst = new Button("<<", this);
57
	    public final Button gotoNext = new Button(">", this);
58
	    public final Button gotoNext = new Button(">", this);
58
	    public final Button gotoPrev = new Button("<", this);
59
	    public final Button gotoPrev = new Button("<", this);
59
	    public final Button gotoEnd = new Button(">>", this);
60
	    public final Button gotoEnd = new Button(">>", this);
60
	    public final HTML status = new HTML();
61
	    public final HTML status = new HTML();
61
  
62
  
62
 
63
 
63
	    public NavBar() {
64
	    public NavBar() {
64
	      initWidget(bar);
65
	      initWidget(bar);
65
	      bar.setStyleName("navbar");
66
	      bar.setStyleName("navbar");
66
	      status.setStyleName("status");
67
	      status.setStyleName("status");
67
 
68
 
68
	      HorizontalPanel buttons = new HorizontalPanel();
69
	      HorizontalPanel buttons = new HorizontalPanel();
69
	      buttons.add(gotoFirst);
70
	      buttons.add(gotoFirst);
70
	      buttons.add(gotoPrev);
71
	      buttons.add(gotoPrev);
71
	      buttons.add(gotoNext);
72
	      buttons.add(gotoNext);
72
	      buttons.add(gotoEnd);
73
	      buttons.add(gotoEnd);
73
	      bar.add(buttons, DockPanel.EAST);
74
	      bar.add(buttons, DockPanel.EAST);
74
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
75
	      bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
75
	      bar.add(status, DockPanel.CENTER);
76
	      bar.add(status, DockPanel.CENTER);
76
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
77
	      bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
77
	      bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
78
	      bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
78
	      bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
79
	      bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
79
	      bar.setCellWidth(status, "100%");
80
	      bar.setCellWidth(status, "100%");
80
 
-
 
81
	      // Initialize prev & first button to disabled.
-
 
82
	      //
81
 
83
	    }
82
	    }
84
 
83
 
85
	    
84
	    
86
	    public void onClick(Widget sender) {
85
	    public void onClick(Widget sender) {
87
	  	    if (sender == gotoNext) {
86
	  	    if (sender == gotoNext) {
88
	  	      // Move forward a page.
87
	  	      // Move forward a page.
89
	  	      startIndex += VISIBLE_TAXON_COUNT;
88
	  	      startIndex += VISIBLE_TAXON_COUNT;
90
	  	      if (startIndex >= count)
89
	  	      if (startIndex >= count)
91
	  	          startIndex -= VISIBLE_TAXON_COUNT;
90
	  	          startIndex -= VISIBLE_TAXON_COUNT;
92
	  	    } 
91
	  	    } 
93
	  	    else {
92
	  	    else {
94
	  	     if (sender == gotoPrev) {
93
	  	     if (sender == gotoPrev) {
95
	  	      // Move back a page.
94
	  	      // Move back a page.
96
	  	      startIndex -= VISIBLE_TAXON_COUNT;
95
	  	      startIndex -= VISIBLE_TAXON_COUNT;
97
	  	      if (startIndex < 0)
96
	  	      if (startIndex < 0)
98
	  	        startIndex = 0;
97
	  	        startIndex = 0;
99
	  	      }
98
	  	      }
100
	  	     else {
99
	  	     else {
101
	  	    	 if (sender==gotoEnd) {
100
	  	    	 if (sender==gotoEnd) {
102
	  	    	  	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
103
    		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
104
    		    	}
-
 
105
    		    	else {
101
	  	    		gotoEnd();
106
    		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
107
    		    	}
-
 
108
	  	    	 }
102
	  	    	 }
109
	  	    	 else {
103
	  	    	 else {
110
	  	    		 if (sender== gotoFirst) {
104
	  	    		 if (sender== gotoFirst) {
111
	  	    			 startIndex = 0;
105
	  	    			 startIndex = 0;
112
	  	    		 }
106
	  	    		 }
113
	  	    	 }
107
	  	    	 }
114
	  	     }
108
	  	     }
115
	  	   }
109
	  	   }
116
	  	   update();
110
	  	   update();
117
	    }
111
	    }
118
 
112
 
119
	  }
113
	  }
120
 
114
 
121
  public void setStatusText(String text) {
115
  private void setStatusText(String text) {
122
	    navBar.status.setText(text);
116
	    navBar.status.setText(text);
123
  }
117
  }
124
 
-
 
125
  public void clearStatusText() {
-
 
126
	    navBar.status.setHTML("&nbsp;");
-
 
127
  }
-
 
128
 
-
 
129
	
118
 
130
 
119
 
131
  private static final int VISIBLE_TAXON_COUNT = 15;
120
  private static final int VISIBLE_TAXON_COUNT = 15;
132
	
121
	
133
  private Grid header = new Grid(1,6);
122
  private Grid header = new Grid(1,6);
134
  private FlexTable table = new FlexTable();
123
  private FlexTable table = new FlexTable();
135
  private VerticalPanel panel = new VerticalPanel();
124
  private VerticalPanel panel = new VerticalPanel();
136
 
125
 
137
  private int startIndex=0;
126
  private int startIndex=0;
138
  private String serviceBaseUrl=getServiceBaseUrl();
127
  private String serviceBaseUrl=getServiceBaseUrl();
139
  private int count=65000;
128
  private int count=65000;
140
  
129
  
141
  private Vector complements=null;
130
  private Vector complements=null;
142
  private String element=null;
131
  private String element=null;
143
  private String complement=null;
132
  private String complement=null;
144
  
133
  
145
  private String user;
134
  private String user;
146
  
135
  
147
  private NavBar navBar = new NavBar();
136
  private NavBar navBar = new NavBar();
148
  
137
  
149
  public TaxonList(Vector comps) {
138
  public TaxonList(Vector comps) {
150
 
139
 
151
	 
140
	 
152
	getUser();
-
 
153
 
141
     initAsync();
154
	
142
	
155
	// Information complementaire
143
	// Information complementaire : un tableau associe au retour de l'assistant de saisie
156
	
144
	
157
	complements=comps;
145
	complements=comps;
158
	
146
	
159
    // Setup the header
147
    // Mise en forme du header 
160
	  
148
	  
161
    header.setCellSpacing(0);
149
    header.setCellSpacing(0);
162
    header.setCellPadding(2);
150
    header.setCellPadding(2);
163
    header.setWidth("100%");
151
    header.setWidth("100%");
164
 
152
 
165
    header.setStyleName("taxon-ListHeader");
153
    header.setStyleName("taxon-ListHeader");
166
    
154
    
167
    header.setText(0, 0, "");
155
    header.setText(0, 0, "");
168
    header.setText(0, 1, "Nom saisi");
156
    header.setText(0, 1, "Nom saisi");
169
    header.setText(0, 2, "Nom retenu");
157
    header.setText(0, 2, "Nom retenu");
170
    header.setHTML(0, 3, "Code<br>Nomenclatural");
158
    header.setHTML(0, 3, "Code<br>Nomenclatural");
171
    header.setHTML(0, 4, "Code<br>Taxonomique");
159
    header.setHTML(0, 4, "Code<br>Taxonomique");
172
    header.setText(0, 5, "");
160
    header.setText(0, 5, "Famille");
173
  
161
  
174
	header.getCellFormatter().setWidth(0,0,"2%");
162
	header.getCellFormatter().setWidth(0,0,"2%");
175
	header.getCellFormatter().setWidth(0,1,"31%");
163
	header.getCellFormatter().setWidth(0,1,"31%");
176
	header.getCellFormatter().setWidth(0,2,"31%");
164
	header.getCellFormatter().setWidth(0,2,"31%");
177
	header.getCellFormatter().setWidth(0,3,"9%");
165
	header.getCellFormatter().setWidth(0,3,"9%");
178
	header.getCellFormatter().setWidth(0,4,"9%");
166
	header.getCellFormatter().setWidth(0,4,"9%");
179
	header.getCellFormatter().setWidth(0,5,"18%");
167
	header.getCellFormatter().setWidth(0,5,"18%");
180
 
-
 
181
	
-
 
182
 
-
 
183
    header.setCellSpacing(0);
-
 
184
    header.setCellPadding(2);
-
 
185
 
168
 
186
    // Setup the table.
169
    // Mise en forme de la table.
187
	  
170
	  
188
    table.setCellSpacing(0);
171
    table.setCellSpacing(0);
189
    table.setBorderWidth(0);
172
    table.setBorderWidth(0);
190
    table.setCellPadding(2);
173
    table.setCellPadding(2);
191
    table.setWidth("100%");
174
    table.setWidth("100%");
-
 
175
 
192
 
176
    // Mise en forme barre navigation
193
 
177
    
194
    navBar.setWidth("100%");
-
 
195
 
178
    navBar.setWidth("100%");
196
    
179
 
197
   
180
   
198
    table.setStyleName("taxon-List");
181
    table.setStyleName("taxon-List");
199
 
182
 
200
    panel.add(navBar);
183
    panel.add(navBar);
201
    panel.add(header);
184
    panel.add(header);
202
    panel.add(table);
185
    panel.add(table);
203
    
186
    
204
    initWidget(panel);
187
    initWidget(panel);
205
    
188
    
206
 
189
 
207
  }
190
  }
208
 
191
 
-
 
192
  /**
-
 
193
   * Action lancee par la selection d'un nom dans l'assistant de saisie. Lance la recherche d'informations
-
 
194
   * complémentaires (famille, numero nomenclaturaux etc) et met a jour l'inventaire (addelement())
-
 
195
   * @return void
-
 
196
   */
209
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
197
  public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
210
		
198
	
-
 
199
	  	setStatusDisabled();
-
 
200
	  	
-
 
201
	    // Il y a surement une meilleure facon de faire que de passer par une variable de classe 
-
 
202
	    // pour atteindre une inner classe
-
 
203
	  
-
 
204
	    element=str;
-
 
205
	
-
 
206
	    // Saisie assistée
211
	  
-
 
212
// Recherche informations complementaires :
-
 
213
// et Ajout ligne 
-
 
214
	 
207
	  
-
 
208
	    if (pos>=0) {
-
 
209
	 
-
 
210
	    // Le vecteur complements contient les informations complémentaires associées à un nom.
215
	    if (pos>=0) {
211
	    	
216
	    complement=(String) complements.get(pos);
-
 
217
	    element=str;
212
	    complement=(String) complements.get(pos);
218
	 
213
	 
219
		 HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, 
214
		 HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, 
220
				    new ResponseTextHandler(){
215
				    new ResponseTextHandler(){
221
 
216
 
222
				    	public void onCompletion(String str) {
217
				    	public void onCompletion(String str) {
223
		    
218
		    
224
							JSONValue jsonValue= JSONParser.parse(str);
219
							JSONValue jsonValue= JSONParser.parse(str);
225
				  			JSONArray jsonArray;
220
				  			JSONArray jsonArray;
226
				
221
				
227
				  			complements.clear();
222
				  			complements.clear();
228
				  			
223
				  			
229
				  			if ((jsonArray = jsonValue.isArray()) != null) {
224
				  			if ((jsonArray = jsonValue.isArray()) != null) {
230
				  					  // Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
225
				  					  // Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
231
								      addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
226
								      addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
232
								    		  ((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
227
								    		  ((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
233
								    		  ((JSONString) jsonArray.get(3)).stringValue());
228
								    		  ((JSONString) jsonArray.get(3)).stringValue());
234
				  			}
229
				  			}
235
				    	} 
230
				    	} 
236
 
231
 
237
				   	});
232
				   	});
238
	    }
233
	    }
-
 
234
	    // Saisie libre
239
	    else {
235
	    else {
240
 			complements.clear();
236
 			complements.clear();
241
 
237
 
242
			addElement(str," "," "," "," "," ");
238
			addElement(element," "," "," "," "," ");
243
	    }
239
	    }
244
  }
240
  }
-
 
241
 
-
 
242
  /**
-
 
243
   * Ajoute un element à l'inventaire 
-
 
244
   * @param nom_sel : nom selectionne
-
 
245
   * @param num_nom_sel : numero nomenclatural nom selectionne
-
 
246
   * @param nom_ret : nom retenu
-
 
247
   * @param num_nom_ret : numero nomenclaturel nom retenu
-
 
248
   * @param num_taxon : numero taxonomique
-
 
249
   * @param famille : famille
245
  
250
   */
246
 
251
 
247
  public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
252
  public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) {
-
 
253
	 
-
 
254
	  // Calcul du nouveau numéro d'ordre 
248
	 
255
	  
249
	  int lastOrdre=1;
256
	 /* int order=1;
250
	  if (table.getRowCount()>0) {
257
	  if (table.getRowCount()>0) {
251
		  lastOrdre=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
258
		  order=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1;
252
	  }
259
	  }*/
253
		  
260
		  
254
	  count++;
261
	  count++;
255
	  HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
262
	  HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/", "identifiant="+user+"&nom_sel="+nom_sel+"&num_nom_sel="+num_nom_sel
256
			  +"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille+"&ordre="+lastOrdre,
263
			  +"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille,
-
 
264
			  
257
	  new ResponseTextHandler(){
265
	  new ResponseTextHandler(){
258
	
266
	
259
	  	public void onCompletion(String str) {
267
	  	public void onCompletion(String str) {
260
		    	if ((count%VISIBLE_TAXON_COUNT)>0) {
-
 
261
		    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
262
		    	}
-
 
263
		    	else {
-
 
264
		    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
265
		    	}
-
 
266
		    	if (startIndex < 0) {
-
 
267
			  	    startIndex = 0;
268
	  			gotoEnd();
268
			  	}
-
 
269
		    	update();
269
		    	update();
270
	  	}
270
	  	}
271
	  });
271
	  });
272
  }
272
  }
-
 
273
 
-
 
274
  /**
-
 
275
   * Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
-
 
276
   *
-
 
277
   */
273
 
278
 
274
  
279
  
275
  public void deleteElement() {
280
  public void deleteElement() {
-
 
281
 
-
 
282
	  
-
 
283
	  setStatusDisabled();
-
 
284
	  boolean checked=false;
276
 
285
 
277
	    // Lifo ...
286
	    // Lifo ...
278
      for (int i=table.getRowCount()-1; i>=0;i--){
287
      for (int i=table.getRowCount()-1; i>=0;i--){
279
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
288
		 if (((CheckBox) table.getWidget(i,0)).isChecked())  {
-
 
289
			checked=true;
280
			String str=table.getText(i,6);
290
			String str=table.getText(i,6);
281
			count--;
291
			count--;
282
			 HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", 
292
			 HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", 
283
			   new ResponseTextHandler(){
293
			   new ResponseTextHandler(){
284
 
294
 
285
			   	public void onCompletion(String str) {
295
			   	public void onCompletion(String str) {
286
			    	if ((count%VISIBLE_TAXON_COUNT)==0) {
-
 
287
			    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
288
			    	}
-
 
289
			    	if (startIndex < 0) {
-
 
290
				  	    startIndex = 0;
296
			   		gotoEnd();
291
				  	}
-
 
292
			    	update();
297
			    	update();
293
			   	}
298
			   	}
294
			  });
299
			  });
295
 
300
 
296
	  	 }
301
	  	 }
297
	  }
302
	  }
-
 
303
      if (!checked) {
-
 
304
    	  setStatusEnabled(); 
-
 
305
      }
298
  }
306
  }
-
 
307
 
-
 
308
  /** 
-
 
309
   * 
-
 
310
   * Lancement des initialisations dependantes de réponses asynchrones : le retour d'une demande d'initialisation declanche 
-
 
311
   * la demande d'initialisation suivantes
-
 
312
   * user : resultat recherche nom d'utilisateur
-
 
313
   * count : resultat nombre d'enregistrements d'inventaires
-
 
314
   * affichage enregistrements trouvés 
-
 
315
   *
-
 
316
   */
-
 
317
  private void initAsync() {
-
 
318
	 
-
 
319
	  getUser();
-
 
320
	  // getCount()
-
 
321
	  // update()
-
 
322
	  
-
 
323
  }
-
 
324
  
-
 
325
  /**
-
 
326
   * Recherche utilisateur en cours 
-
 
327
   *
299
 
328
   */
-
 
329
  private void getUser() {
-
 
330
	  
-
 
331
	  
-
 
332
    	 setStatusDisabled();
300
  private void getUser() {
333
 
301
		 HTTPRequest.asyncGet(serviceBaseUrl+"/User/", 
334
		 HTTPRequest.asyncGet(serviceBaseUrl+"/User/", 
302
				    new ResponseTextHandler(){
335
				    new ResponseTextHandler(){
303
 
336
 
304
				    	public void onCompletion(String str) {
337
				    	public void onCompletion(String str) {
305
				    		JSONValue jsonValue= JSONParser.parse(str);
338
				    		JSONValue jsonValue= JSONParser.parse(str);
306
				    		JSONString jsonString;
339
				    		JSONString jsonString;
307
				    		    if ((jsonString = jsonValue.isString()) != null) {
340
				    		    if ((jsonString = jsonValue.isString()) != null) {
308
				    		    	user = jsonString.stringValue();
341
				    		    	user = jsonString.stringValue();
309
				    		    }
342
				    		    }
310
				    		    getCount();
343
				    		    getCount();
311
				    	}
344
				    	}
312
			 	});
345
			 	});
313
		    
346
		    
314
		  
347
		  
315
 
348
 
316
		}  
349
		}  
-
 
350
 
-
 
351
 /**
317
 
352
  * Recherche nombre d'enregistrement pour l'utilisateur en cours
-
 
353
  *
318
  
354
  */ 
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
 
355
  private void getCount() {
322
  
356
 
323
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", 
357
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", 
324
		    new ResponseTextHandler(){
358
		    new ResponseTextHandler(){
325
 
359
 
326
		    	public void onCompletion(String str) {
360
		    	public void onCompletion(String str) {
327
 
-
 
328
//On se positionne sur la dernière page ...
-
 
329
		    		
361
 
330
		    		JSONValue jsonValue= JSONParser.parse(str);
362
		    		JSONValue jsonValue= JSONParser.parse(str);
331
		    		JSONNumber jsonNumber;
363
		    		JSONNumber jsonNumber;
332
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
364
		    		    if ((jsonNumber = jsonValue.isNumber()) != null) {
333
		    		    	count=(int) jsonNumber.getValue();
365
		    		    	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; 
-
 
339
		    		    	}
-
 
340
		    		    	if (startIndex < 0) {
366
		    		    	gotoEnd(); // Derniere page
341
		    			  	    startIndex = 0;
-
 
342
		    			  	}
-
 
343
	 				
-
 
344
		    		    	update();
367
		    		    	update();
345
		    		    }
368
		    		    }
346
		    	}
369
		    	}
347
	 	});
370
	 	});
348
 
371
 
349
  }
372
  }
-
 
373
 
-
 
374
  /**
-
 
375
   * Mise a jour de l'affichage, à partir des données d'inventaire deja saisies.
-
 
376
   * La valeur de this.startIndex permet de determiner quelles données seront affichées 
-
 
377
   *
350
 
378
   */
351
  
379
  
352
  private void update() {
380
  private void update() {
353
	  
-
 
354
	  
-
 
355
	 // TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes .
381
	  
356
 
-
 
357
	 navBar.gotoFirst.setEnabled(false);
-
 
358
	 navBar.gotoPrev.setEnabled(false);
-
 
359
     navBar.gotoNext.setEnabled(false);
382
 
360
     navBar.gotoEnd.setEnabled(false);
383
	 setStatusDisabled();
361
 
384
	 
-
 
385
	 // TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes .
362
     setStatusText("Patientez ...");
386
 
363
 
387
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT, 
364
	 HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT, 
388
			 
365
		    new ResponseTextHandler(){
389
		    new ResponseTextHandler(){
366
 
390
 
367
		    	public void onCompletion(String str) {
391
		    	public void onCompletion(String str) {
368
 
392
 
369
		    		    JSONValue jsonValue= JSONParser.parse(str);
393
		    		    JSONValue jsonValue= JSONParser.parse(str);
370
		    		    JSONArray jsonArray;
394
		    		    JSONArray jsonArray;
371
		    		    JSONArray jsonArrayNested;
395
		    		    JSONArray jsonArrayNested;
372
		    		 
396
		    		 
373
		    		    // Lifo ...
397
		    		    // Lifo ...
374
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
398
		    	        for (int i=table.getRowCount()-1; i>=0;i--){
375
		                        table.removeRow(i);
399
		                        table.removeRow(i);
376
		                }
400
		                }
377
 
401
 
378
 
402
 
379
		    		    int j=0;
403
		    		    int j=0;
380
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
404
		    		    if ((jsonArray = jsonValue.isArray()) != null) {
381
		    		      int i; 	
-
 
382
		    		      for (i = 0; i < jsonArray.size(); ++i) {
405
		    		      for (int i = 0; i < jsonArray.size(); ++i) {
383
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
406
		    		    	  if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
384
		    		    		  int row=table.insertRow(table.getRowCount());
407
		    		    		  int row=table.insertRow(table.getRowCount());
385
		    		    		  // Case a cocher
408
		    		    		  // Case a cocher
386
		    		    		  table.setWidget(row,0,new CheckBox());
409
		    		    		  table.setWidget(row,0,new CheckBox());
387
		    		    		  // Nom saisi
410
		    		    		  // Nom saisi
388
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
411
		    		    		  table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
389
		    		    		  // Nom retenu
412
		    		    		  // Nom retenu
390
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
413
		    		    		  table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
391
		    		    		  // Num nomenclatural
414
		    		    		  // Num nomenclatural
392
		    		    		  table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
415
		    		    		  table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
393
		    		    		  // Num Taxonomique
416
		    		    		  // Num Taxonomique
394
		    		    		  table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
417
		    		    		  table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
395
		    		    		  // Famille
418
		    		    		  // Famille
396
		    		    		  table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
419
		    		    		  table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
397
		    		    		  // Numero d'ordre
420
		    		    		  // Numero d'ordre
398
		    		    		  table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
421
		    		    		  table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
399
		    		    		  
422
		    		    		  
400
		    		    		  table.getCellFormatter().setVisible(row,6,true);
423
		    		    		  table.getCellFormatter().setVisible(row,6,false);
401
		    		    		  
424
		    		     		  
402
		    		    		  table.getFlexCellFormatter().setWidth(row,0,"2%");
425
		    		    		  table.getFlexCellFormatter().setWidth(row,0,"2%");
403
		    		    		  table.getFlexCellFormatter().setWidth(row,1,"31%");
426
		    		    		  table.getFlexCellFormatter().setWidth(row,1,"31%");
404
		    		    		  table.getFlexCellFormatter().setWidth(row,2,"31%");
427
		    		    		  table.getFlexCellFormatter().setWidth(row,2,"31%");
405
		    		    		  table.getFlexCellFormatter().setWidth(row,3,"9%");
428
		    		    		  table.getFlexCellFormatter().setWidth(row,3,"9%");
406
		    		    		  table.getFlexCellFormatter().setWidth(row,4,"9%");
429
		    		    		  table.getFlexCellFormatter().setWidth(row,4,"9%");
407
		    		    		  table.getFlexCellFormatter().setWidth(row,5,"18%");
430
		    		    		  table.getFlexCellFormatter().setWidth(row,5,"18%");
408
		    		    		  j++;
431
		    		    		  j++;
409
		    		    	  }
432
		    		    	  }
410
		    		    	  
433
		    		    	  
411
		    		      }
434
		    		      }
412
		    		      // Calcul nombre d'enregistrement total (c'est un doublon, c'est normal ...)
-
 
413
		    		      if (i<VISIBLE_TAXON_COUNT) {
-
 
414
		    		    	  count = startIndex+i;
-
 
415
		    		      }
435
		    		    } 
416
		    		      
-
 
417
		    		      // Navigation 
-
 
418
		    		      
-
 
419
 
-
 
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);
436
		    		    setStatusEnabled();
426
		    		    		if (count < VISIBLE_TAXON_COUNT) {
-
 
427
		    		    			setStatusText((startIndex + 1) + " - " + count );
-
 
428
		    		    		}
-
 
429
		    		    		else {
-
 
430
				    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
431
		    		    		}
-
 
432
		    		    		
437
		    		    
433
		    		      }
-
 
434
		    		      // Derniere page
-
 
435
		    		      else {
-
 
436
		    		    	  if (startIndex>=(count-VISIBLE_TAXON_COUNT)) {
-
 
437
		    		    		navBar.gotoPrev.setEnabled(true);
-
 
438
		    		    		navBar.gotoFirst.setEnabled(true);
-
 
439
		    		    		navBar.gotoNext.setEnabled(false);
-
 
440
		    		    		navBar.gotoEnd.setEnabled(false);
-
 
441
		    		    		setStatusText((startIndex + 1) + " - " + count);
-
 
442
		    		    	  }
-
 
443
		    		    	  // Page normale 
-
 
444
		    		    	  else {
-
 
445
				    		      navBar.gotoPrev.setEnabled(true);
-
 
446
				    		      navBar.gotoFirst.setEnabled(true);
-
 
447
				    		      navBar.gotoNext.setEnabled(true);
-
 
448
				    		      navBar.gotoEnd.setEnabled(true);
-
 
449
				    		      setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
450
		    		    	  }
-
 
451
		    		      }
-
 
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
		    		    }
-
 
461
		    	}
438
		    	}
462
		    });
439
		    });
463
 
440
 
464
  }
441
  }
465
 
-
 
466
private String getServiceBaseUrl() {
-
 
467
	  
-
 
468
	  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
469
	  return theme.get("serviceBaseUrl");
-
 
470
	  
-
 
471
 
-
 
472
	}  
-
 
473
 
-
 
-
 
442
 
-
 
443
  /**
-
 
444
   * Recuperation du prefixe d'appel des services  
-
 
445
   */
-
 
446
  
-
 
447
	private String getServiceBaseUrl() {
-
 
448
		  
-
 
449
		  Dictionary theme = Dictionary.getDictionary("Parameters");
-
 
450
		  return theme.get("serviceBaseUrl");
-
 
451
		  
-
 
452
	
-
 
453
		}  
-
 
454
	
-
 
455
	
-
 
456
	/**
-
 
457
	 * Affichage message d'attente et désactivation navigation
-
 
458
	 * @param 
-
 
459
	 * @return void  
-
 
460
	 */
-
 
461
	
-
 
462
	private void setStatusDisabled() {
-
 
463
		
-
 
464
		navBar.gotoFirst.setEnabled(false);
-
 
465
		navBar.gotoPrev.setEnabled(false);
-
 
466
		navBar.gotoNext.setEnabled(false);
-
 
467
		navBar.gotoEnd.setEnabled(false);
-
 
468
	
-
 
469
		setStatusText("Patientez ...");
-
 
470
	}
-
 
471
	
-
 
472
 
-
 
473
	/**
-
 
474
	 * Affichage numero de page et gestion de la navigation
-
 
475
	 *
-
 
476
	 */
-
 
477
	
-
 
478
	private void setStatusEnabled() {
-
 
479
	
-
 
480
		// Il y a forcemment un disabled avant d'arriver ici
-
 
481
		
-
 
482
		if (count > 0 ) {	
-
 
483
				
-
 
484
			if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la premiere page
-
 
485
				navBar.gotoPrev.setEnabled(true);
-
 
486
				navBar.gotoFirst.setEnabled(true);
-
 
487
				if (startIndex<(count-VISIBLE_TAXON_COUNT)) {  // Pas la derniere page
-
 
488
					navBar.gotoNext.setEnabled(true);
-
 
489
					navBar.gotoEnd.setEnabled(true);
-
 
490
					setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
491
				}
-
 
492
				else { // Derniere page
-
 
493
					setStatusText((startIndex + 1) + " - " + count);
-
 
494
				}
-
 
495
			}
-
 
496
			else {  // Premiere page
-
 
497
				if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
-
 
498
					navBar.gotoNext.setEnabled(true);
-
 
499
					navBar.gotoEnd.setEnabled(true);
-
 
500
					setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
-
 
501
				}
-
 
502
				else {
-
 
503
					setStatusText((startIndex + 1) + " - " + count);
-
 
504
				}
-
 
505
			}
-
 
506
		}
-
 
507
		
-
 
508
		
-
 
509
		else { // Pas d'inventaire, pas de navigation
-
 
510
			 setStatusText(0 + " - " + 0);
-
 
511
		}
-
 
512
	}
-
 
513
	
-
 
514
	
-
 
515
	/**
-
 
516
	 * Positionnement index de parcours (this.startIndex) pour affichage de la dernière page
-
 
517
	 * @param 
-
 
518
	 * @return void  
-
 
519
	 */
-
 
520
	
-
 
521
	private void gotoEnd() {
-
 
522
		
-
 
523
		  	if ( (count==0) || (count%VISIBLE_TAXON_COUNT)>0) {
-
 
524
	    		startIndex=count-(count%VISIBLE_TAXON_COUNT); 
-
 
525
	    	}
-
 
526
	    	else {
-
 
527
	    		startIndex=count-VISIBLE_TAXON_COUNT; 
-
 
528
	    	}
-
 
529
		  	
474
 
530
	}
475
 
531
	
476
}
532
}