18,6 → 18,7 |
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; |
41,7 → 42,7 |
import com.google.gwt.user.client.ui.Label; |
|
/* |
* Le retour de getUser appelle updateCount qui appelle update pour veiller à une |
* Le retour de getUser appelle getCount qui appelle update pour veiller à une |
* initialisation correcte |
* |
*/ |
192,7 → 193,7 |
} |
} |
} |
update(); |
update(true); |
} |
|
} |
211,7 → 212,7 |
|
private int startIndex = 0; |
|
private String serviceBaseUrl = null; |
private String serviceBaseUrl = getServiceBaseUrl(); |
|
private int count = 65000; |
|
218,86 → 219,14 |
private String user; |
|
private NavBar navBar=null; |
|
private Mediator mediator = null; |
|
// Optimization |
|
int sizeChecked=0; |
int itemDeleted=0; |
|
|
// 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; |
public TaxonList() { |
|
private String location = "all"; |
|
public TaxonList(Mediator med) { |
|
mediator=med; |
getUser(); // Appelle le reste des initialisations |
|
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); |
|
|
311,75 → 240,59 |
* @return void |
*/ |
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, |
String str, String value) { |
|
// Le nom de plante est requis |
final String str,final String value) { |
|
setStatusDisabled(); |
|
// On met a jour rapidement l'affichage puis on lance la requete .... |
|
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(); |
int row = table.insertRow(table.getRowCount()); |
// Case a cocher |
table.setWidget(row, 0, new CheckBox()); |
// Nom saisi |
table.setText(row, 1, str); |
|
// 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 |
table.getFlexCellFormatter().setWidth(row, 0, "2%"); |
table.getFlexCellFormatter() |
.setWidth(row, 1, "31%"); |
|
if (nameValue !=null) { |
// 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, " ", " ", " ", " ", " "); |
} |
|
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); |
} |
|
|
} |
|
/** |
400,7 → 313,7 |
*/ |
|
public void addElement(String nom_sel, String num_nom_sel, String nom_ret, |
String num_nom_ret, String num_taxon, String famille,final String loc, String id_location) { |
String num_nom_ret, String num_taxon, String famille) { |
|
// Calcul du nouveau numéro d'ordre |
|
413,13 → 326,19 |
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 + "&location=" + loc + "&id_location=" + id_location, |
+ "&num_taxon=" + num_taxon + "&famille=" + famille, |
|
new ResponseTextHandler() { |
|
public void onCompletion(String str) { |
location=loc; |
updateCount(); |
// (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); |
} |
} |
}); |
} |
441,6 → 360,7 |
checked = true; |
parseChecked.add(table.getText(i, 6)); |
count--; |
|
} |
} |
sizeChecked=parseChecked.size(); |
452,9 → 372,10 |
|
new ResponseTextHandler() { |
public void onCompletion(String str) { |
// Optimisation : on ne lance la suppression qu'a la fin |
// On ne lance la suppression qu'a la fin |
if (itemDeleted==sizeChecked) { |
updateCount(); |
gotoEnd(); |
update(true); |
} |
} |
}); |
485,16 → 406,98 |
} |
|
|
/** |
* |
* 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 nombre d'enregistrement pour l'utilisateur et la localite en cours |
* Recherche utilisateur en cours |
* |
*/ |
public void updateCount() { |
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() { |
|
setStatusDisabled(); |
|
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryTaxonList/" + user + "/" + location, |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/", |
new ResponseTextHandler() { |
|
public void onCompletion(String str) { |
504,13 → 507,7 |
if ((jsonNumber = jsonValue.isNumber()) != null) { |
count = (int) jsonNumber.getValue(); |
gotoEnd(); // Derniere page |
if (count==0) { |
location="all"; |
} |
if (location.compareTo("")==0) |
location="000null"; |
mediator.onTaxonListUpdate(location); |
update(); |
update(true); |
} |
} |
}); |
522,10 → 519,9 |
* saisies. La valeur de this.startIndex permet de determiner quelles |
* données seront affichées |
* |
* @param deep : force une mise a jour totale |
*/ |
|
public void update() { |
private void update(final boolean deep) { |
|
setStatusDisabled(); |
|
538,7 → 534,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 + "/InventoryTaxonList/" + user + "/" + location +"/" |
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryList/" + user + "/" |
+ startIndex + "/" + VISIBLE_TAXON_COUNT, |
|
new ResponseTextHandler() { |
549,13 → 545,22 |
JSONArray jsonArray; |
JSONArray jsonArrayNested; |
|
for (int i = table.getRowCount() - 1; i >= 0; i--) { |
table.removeRow(i); |
// Lifo ... |
if (deep) { |
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 |
595,13 → 600,23 |
} |
} |
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 |
* |
679,21 → 694,5 |
|
} |
|
public void setNameProvider(NameAssistant nameAssistant) { |
this.nameProvider = nameAssistant; |
} |
|
public void setLocationProvider(LocationAssistant locationAssistant) { |
this.locationProvider = locationAssistant; |
} |
|
public void setLocation(String location) { |
this.location = location; |
} |
|
|
|
|
|
|
} |