Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 9 → Rev 10

/trunk/src/org/tela_botanica/client/TaxonList.java
18,7 → 18,6
import java.util.Iterator;
import java.util.Vector;
 
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONParser;
42,7 → 41,7
import com.google.gwt.user.client.ui.Label;
 
/*
* Le retour de getUser appelle getCount qui appelle update pour veiller à une
* Le retour de getUser appelle updateCount qui appelle update pour veiller à une
* initialisation correcte
*
*/
193,7 → 192,7
}
}
}
update(true);
update();
}
 
}
212,7 → 211,7
 
private int startIndex = 0;
 
private String serviceBaseUrl = getServiceBaseUrl();
private String serviceBaseUrl = null;
 
private int count = 65000;
 
219,14 → 218,86
private String user;
 
private NavBar navBar=null;
 
private Mediator mediator = null;
// Optimization
int sizeChecked=0;
int itemDeleted=0;
public TaxonList() {
// Data provider
private NameAssistant nameProvider=null;
private LocationAssistant locationProvider=null;
// Data from provider
private String nameText=null;
private String nameValue=null;
private String locationText=null;
private String locationValue=null;
 
getUser(); // Appelle le reste des initialisations
private String location = "all";
public TaxonList(Mediator med) {
 
mediator=med;
mediator.registerTaxonList(this);
user=mediator.getUser();
serviceBaseUrl = mediator.getServiceBaseUrl();
navBar = new NavBar();
 
// Information complementaire : un tableau associe au retour de
// l'assistant de saisie
 
// Mise en forme du header
 
header.setCellSpacing(0);
header.setCellPadding(2);
header.setWidth("100%");
 
header.setStyleName("taxon-ListHeader");
 
header.setText(0, 0, "");
header.setText(0, 1, "Nom saisi");
header.setText(0, 2, "Nom retenu");
header.setHTML(0, 3, "Code<br>Nomenclatural");
header.setHTML(0, 4, "Code<br>Taxonomique");
header.setText(0, 5, "Famille");
 
header.getCellFormatter().setWidth(0, 0, "2%");
header.getCellFormatter().setWidth(0, 1, "31%");
header.getCellFormatter().setWidth(0, 2, "31%");
header.getCellFormatter().setWidth(0, 3, "9%");
header.getCellFormatter().setWidth(0, 4, "9%");
header.getCellFormatter().setWidth(0, 5, "18%");
 
// Mise en forme de la table.
 
table.setCellSpacing(0);
table.setBorderWidth(0);
table.setCellPadding(2);
table.setWidth("100%");
 
// Mise en forme barre navigation
 
navBar.setWidth("100%");
 
table.setStyleName("taxon-List");
 
panel.add(navBar);
panel.add(header);
panel.add(table);
 
updateCount();
// update()
 
initWidget(panel);
 
 
240,59 → 311,75
* @return void
*/
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
final String str,final String value) {
 
setStatusDisabled();
 
// On met a jour rapidement l'affichage puis on lance la requete ....
String str, String value) {
// Le nom de plante est requis
int row = table.insertRow(table.getRowCount());
// Case a cocher
table.setWidget(row, 0, new CheckBox());
// Nom saisi
table.setText(row, 1, str);
if (nameProvider.getText().compareTo("")==0) {
return;
}
nameText=nameProvider.getText();
nameValue=nameProvider.getValue();
locationValue=locationProvider.getValue();
locationText=locationProvider.getText();
// Suppresion indication departementale (on pourrait faire mieux !!)
int pos=locationText.indexOf("(" );
if (pos>=0) {
locationText=locationText.substring(0,pos);
}
setStatusDisabled();
table.getFlexCellFormatter().setWidth(row, 0, "2%");
table.getFlexCellFormatter()
.setWidth(row, 1, "31%");
// On met a jour rapidement l'affichage puis on lance la requete ....
int row = table.insertRow(table.getRowCount());
// Case a cocher
table.setWidget(row, 0, new CheckBox());
// Nom saisi
table.setText(row, 1, nameText);
table.getFlexCellFormatter().setWidth(row, 0, "2%");
table.getFlexCellFormatter()
.setWidth(row, 1, "31%");
// Recherche complement d'information
// Recherche complement d'information
 
if (value !=null) {
 
 
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + value,
new ResponseTextHandler() {
 
public void onCompletion(String strcomplete) {
 
JSONValue jsonValue = JSONParser.parse(strcomplete);
JSONArray jsonArray;
 
if ((jsonArray = jsonValue.isArray()) != null) {
// Nom retenu, Num Nomen nom retenu, Num Taxon,
// Famille
addElement(str, value,
((JSONString) jsonArray.get(0))
.stringValue(),
((JSONString) jsonArray.get(1))
.stringValue(),
((JSONString) jsonArray.get(2))
.stringValue(),
((JSONString) jsonArray.get(3))
.stringValue());
}
}
 
});
}
// Saisie libre
else {
addElement(str, " ", " ", " ", " ", " ");
}
if (nameValue !=null) {
 
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + nameValue,
new ResponseTextHandler() {
public void onCompletion(String strcomplete) {
JSONValue jsonValue = JSONParser.parse(strcomplete);
JSONArray jsonArray;
if ((jsonArray = jsonValue.isArray()) != null) {
// Nom retenu, Num Nomen nom retenu, Num Taxon,
// Famille
addElement(nameText, nameValue,
((JSONString) jsonArray.get(0))
.stringValue(),
((JSONString) jsonArray.get(1))
.stringValue(),
((JSONString) jsonArray.get(2))
.stringValue(),
((JSONString) jsonArray.get(3))
.stringValue(),
locationText,locationValue);
}
}
});
}
// Saisie libre
else {
addElement(nameText, " ", " ", " ", " ", " ",locationText,locationValue);
}
}
 
/**
313,7 → 400,7
*/
 
public void addElement(String nom_sel, String num_nom_sel, String nom_ret,
String num_nom_ret, String num_taxon, String famille) {
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location) {
 
// Calcul du nouveau numéro d'ordre
 
326,19 → 413,13
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/", "identifiant="
+ user + "&nom_sel=" + nom_sel + "&num_nom_sel=" + num_nom_sel
+ "&nom_ret=" + nom_ret + "&num_nom_ret=" + num_nom_ret
+ "&num_taxon=" + num_taxon + "&famille=" + famille,
+ "&num_taxon=" + num_taxon + "&famille=" + famille + "&location=" + loc + "&id_location=" + id_location,
 
new ResponseTextHandler() {
 
public void onCompletion(String str) {
// (Optimisation) Si on reste sur la meme page : ajout à la fin
if (((count-2)/VISIBLE_TAXON_COUNT)==(count-1/VISIBLE_TAXON_COUNT)) {
update(false);
}
else {
gotoEnd();
update(true);
}
location=loc;
updateCount();
}
});
}
360,7 → 441,6
checked = true;
parseChecked.add(table.getText(i, 6));
count--;
}
}
sizeChecked=parseChecked.size();
372,10 → 452,9
new ResponseTextHandler() {
public void onCompletion(String str) {
// On ne lance la suppression qu'a la fin
// Optimisation : on ne lance la suppression qu'a la fin
if (itemDeleted==sizeChecked) {
gotoEnd();
update(true);
updateCount();
}
}
});
406,98 → 485,16
}
 
 
/**
*
* Lancement des initialisations dependantes de réponses asynchrones : le
* retour d'une demande d'initialisation declanche la demande
* d'initialisation suivantes user : resultat recherche nom d'utilisateur
* count : resultat nombre d'enregistrements d'inventaires affichage
* enregistrements trouvés
*
*/
private void initAsync() {
 
navBar = new NavBar();
 
// Information complementaire : un tableau associe au retour de
// l'assistant de saisie
 
// Mise en forme du header
 
header.setCellSpacing(0);
header.setCellPadding(2);
header.setWidth("100%");
 
header.setStyleName("taxon-ListHeader");
 
header.setText(0, 0, "");
header.setText(0, 1, "Nom saisi");
header.setText(0, 2, "Nom retenu");
header.setHTML(0, 3, "Code<br>Nomenclatural");
header.setHTML(0, 4, "Code<br>Taxonomique");
header.setText(0, 5, "Famille");
 
header.getCellFormatter().setWidth(0, 0, "2%");
header.getCellFormatter().setWidth(0, 1, "31%");
header.getCellFormatter().setWidth(0, 2, "31%");
header.getCellFormatter().setWidth(0, 3, "9%");
header.getCellFormatter().setWidth(0, 4, "9%");
header.getCellFormatter().setWidth(0, 5, "18%");
 
// Mise en forme de la table.
 
table.setCellSpacing(0);
table.setBorderWidth(0);
table.setCellPadding(2);
table.setWidth("100%");
 
// Mise en forme barre navigation
 
navBar.setWidth("100%");
 
table.setStyleName("taxon-List");
 
panel.add(navBar);
panel.add(header);
panel.add(table);
 
getCount();
// update()
 
}
 
/**
* Recherche utilisateur en cours
* Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours
*
*/
private void getUser() {
 
 
HTTPRequest.asyncGet(serviceBaseUrl + "/User/",
new ResponseTextHandler() {
 
public void onCompletion(String str) {
JSONValue jsonValue = JSONParser.parse(str);
JSONString jsonString;
if ((jsonString = jsonValue.isString()) != null) {
user = jsonString.stringValue();
}
initAsync();
}
});
 
}
 
/**
* Recherche nombre d'enregistrement pour l'utilisateur en cours
*
*/
private void getCount() {
public void updateCount() {
setStatusDisabled();
 
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/",
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryTaxonList/" + user + "/" + location,
new ResponseTextHandler() {
 
public void onCompletion(String str) {
507,7 → 504,13
if ((jsonNumber = jsonValue.isNumber()) != null) {
count = (int) jsonNumber.getValue();
gotoEnd(); // Derniere page
update(true);
if (count==0) {
location="all";
}
if (location.compareTo("")==0)
location="000null";
mediator.onTaxonListUpdate(location);
update();
}
}
});
519,9 → 522,10
* saisies. La valeur de this.startIndex permet de determiner quelles
* données seront affichées
*
* @param deep : force une mise a jour totale
*/
 
private void update(final boolean deep) {
public void update() {
 
setStatusDisabled();
 
534,7 → 538,7
// TODO : ou alors prevoir un update pour les ajouts (forcemment à la fin) et un update pour les suppressions ...
// Sauf qu'il y a les chgts de pages ... : oui, la un fait un update normal ...
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/"
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryTaxonList/" + user + "/" + location +"/"
+ startIndex + "/" + VISIBLE_TAXON_COUNT,
 
new ResponseTextHandler() {
545,22 → 549,13
JSONArray jsonArray;
JSONArray jsonArrayNested;
 
// Lifo ...
if (deep) {
for (int i = table.getRowCount() - 1; i >= 0; i--) {
table.removeRow(i);
}
for (int i = table.getRowCount() - 1; i >= 0; i--) {
table.removeRow(i);
}
else {
table.removeRow(table.getRowCount());
}
if ((jsonArray = jsonValue.isArray()) != null) {
int arraySize = jsonArray.size();
for (int i = 0; i < arraySize; ++i) {
if (!deep && i != arraySize -1) {
continue;
}
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
int row = table.insertRow(table.getRowCount());
// Case a cocher
600,23 → 595,13
}
}
setStatusEnabled();
 
}
});
 
}
 
/**
* Recuperation du prefixe d'appel des services
*/
 
private String getServiceBaseUrl() {
 
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
 
/**
* Affichage message d'attente et désactivation navigation
*
694,5 → 679,21
 
}
 
public void setNameProvider(NameAssistant nameAssistant) {
this.nameProvider = nameAssistant;
}
 
public void setLocationProvider(LocationAssistant locationAssistant) {
this.locationProvider = locationAssistant;
}
 
public void setLocation(String location) {
this.location = location;
}
 
 
}