37,7 → 37,6 |
import com.google.gwt.user.client.ui.ClickListener; |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
import com.google.gwt.user.client.ui.HasVerticalAlignment; |
import com.google.gwt.user.client.ui.HTMLTable.CellFormatter; |
|
import java.util.Vector; |
|
44,12 → 43,14 |
|
/* Le retour de getUser appelle getCount qui appelle update pour veiller à une initialisation correcte |
|
/** |
* A composite that displays a list of emails that can be selected. |
*/ |
|
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener { |
|
|
|
// Barre de navigation |
|
private class NavBar extends Composite implements ClickListener { |
|
public final DockPanel bar = new DockPanel(); |
78,8 → 79,6 |
bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE); |
bar.setCellWidth(status, "100%"); |
|
// Initialize prev & first button to disabled. |
// |
} |
|
|
99,14 → 98,9 |
} |
else { |
if (sender==gotoEnd) { |
if ((count%VISIBLE_TAXON_COUNT)>0) { |
startIndex=count-(count%VISIBLE_TAXON_COUNT); |
gotoEnd(); |
} |
else { |
startIndex=count-VISIBLE_TAXON_COUNT; |
} |
} |
else { |
if (sender== gotoFirst) { |
startIndex = 0; |
} |
118,16 → 112,11 |
|
} |
|
public void setStatusText(String text) { |
private void setStatusText(String text) { |
navBar.status.setText(text); |
} |
|
public void clearStatusText() { |
navBar.status.setHTML(" "); |
} |
|
|
|
private static final int VISIBLE_TAXON_COUNT = 15; |
|
private Grid header = new Grid(1,6); |
149,14 → 138,13 |
public TaxonList(Vector comps) { |
|
|
getUser(); |
initAsync(); |
|
// Information complementaire : un tableau associe au retour de l'assistant de saisie |
|
// Information complementaire |
|
complements=comps; |
|
// Setup the header |
// Mise en forme du header |
|
header.setCellSpacing(0); |
header.setCellPadding(2); |
169,7 → 157,7 |
header.setText(0, 2, "Nom retenu"); |
header.setHTML(0, 3, "Code<br>Nomenclatural"); |
header.setHTML(0, 4, "Code<br>Taxonomique"); |
header.setText(0, 5, ""); |
header.setText(0, 5, "Famille"); |
|
header.getCellFormatter().setWidth(0,0,"2%"); |
header.getCellFormatter().setWidth(0,1,"31%"); |
178,23 → 166,18 |
header.getCellFormatter().setWidth(0,4,"9%"); |
header.getCellFormatter().setWidth(0,5,"18%"); |
|
// Mise en forme de la table. |
|
|
header.setCellSpacing(0); |
header.setCellPadding(2); |
|
// Setup the 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); |
206,15 → 189,27 |
|
} |
|
/** |
* Action lancee par la selection d'un nom dans l'assistant de saisie. Lance la recherche d'informations |
* complémentaires (famille, numero nomenclaturaux etc) et met a jour l'inventaire (addelement()) |
* @return void |
*/ |
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) { |
|
setStatusDisabled(); |
|
// Recherche informations complementaires : |
// et Ajout ligne |
// Il y a surement une meilleure facon de faire que de passer par une variable de classe |
// pour atteindre une inner classe |
|
element=str; |
|
// Saisie assistée |
|
if (pos>=0) { |
|
// Le vecteur complements contient les informations complémentaires associées à un nom. |
|
complement=(String) complements.get(pos); |
element=str; |
|
HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement, |
new ResponseTextHandler(){ |
236,47 → 231,62 |
|
}); |
} |
// Saisie libre |
else { |
complements.clear(); |
|
addElement(str," "," "," "," "," "); |
addElement(element," "," "," "," "," "); |
} |
} |
|
/** |
* Ajoute un element à l'inventaire |
* @param nom_sel : nom selectionne |
* @param num_nom_sel : numero nomenclatural nom selectionne |
* @param nom_ret : nom retenu |
* @param num_nom_ret : numero nomenclaturel nom retenu |
* @param num_taxon : numero taxonomique |
* @param famille : famille |
*/ |
|
public void addElement(String nom_sel, String num_nom_sel, String nom_ret, String num_nom_ret, String num_taxon, String famille) { |
|
int lastOrdre=1; |
// Calcul du nouveau numéro d'ordre |
|
/* int order=1; |
if (table.getRowCount()>0) { |
lastOrdre=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1; |
} |
order=new Integer(table.getText(table.getRowCount()-1,6)).intValue()+1; |
}*/ |
|
count++; |
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+"&ordre="+lastOrdre, |
+"&nom_ret="+nom_ret+"&num_nom_ret="+num_nom_ret+"&num_taxon="+num_taxon+"&famille="+famille, |
|
new ResponseTextHandler(){ |
|
public void onCompletion(String str) { |
if ((count%VISIBLE_TAXON_COUNT)>0) { |
startIndex=count-(count%VISIBLE_TAXON_COUNT); |
} |
else { |
startIndex=count-VISIBLE_TAXON_COUNT; |
} |
if (startIndex < 0) { |
startIndex = 0; |
} |
gotoEnd(); |
update(); |
} |
}); |
} |
|
/** |
* Suppression d'un element lde l'inventaire, a partir de son numero d'ordre |
* |
*/ |
|
|
public void deleteElement() { |
|
|
setStatusDisabled(); |
boolean checked=false; |
|
// Lifo ... |
for (int i=table.getRowCount()-1; i>=0;i--){ |
if (((CheckBox) table.getWidget(i,0)).isChecked()) { |
checked=true; |
String str=table.getText(i,6); |
count--; |
HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE", |
283,12 → 293,7 |
new ResponseTextHandler(){ |
|
public void onCompletion(String str) { |
if ((count%VISIBLE_TAXON_COUNT)==0) { |
startIndex=count-VISIBLE_TAXON_COUNT; |
} |
if (startIndex < 0) { |
startIndex = 0; |
} |
gotoEnd(); |
update(); |
} |
}); |
295,9 → 300,37 |
|
} |
} |
if (!checked) { |
setStatusEnabled(); |
} |
} |
|
/** |
* |
* 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() { |
|
getUser(); |
// getCount() |
// update() |
|
} |
|
/** |
* Recherche utilisateur en cours |
* |
*/ |
private void getUser() { |
|
|
setStatusDisabled(); |
|
HTTPRequest.asyncGet(serviceBaseUrl+"/User/", |
new ResponseTextHandler(){ |
|
315,32 → 348,22 |
|
} |
|
|
/** |
* Recherche nombre d'enregistrement pour l'utilisateur en cours |
* |
*/ |
private void getCount() { |
// Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite) |
|
|
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/", |
new ResponseTextHandler(){ |
|
public void onCompletion(String str) { |
|
//On se positionne sur la dernière page ... |
|
JSONValue jsonValue= JSONParser.parse(str); |
JSONNumber jsonNumber; |
if ((jsonNumber = jsonValue.isNumber()) != null) { |
count=(int) jsonNumber.getValue(); |
if ((count%VISIBLE_TAXON_COUNT)>0) { |
startIndex=count-(count%VISIBLE_TAXON_COUNT); |
} |
else { |
startIndex=count-VISIBLE_TAXON_COUNT; |
} |
if (startIndex < 0) { |
startIndex = 0; |
} |
|
gotoEnd(); // Derniere page |
update(); |
} |
} |
348,20 → 371,21 |
|
} |
|
/** |
* Mise a jour de l'affichage, à partir des données d'inventaire deja saisies. |
* La valeur de this.startIndex permet de determiner quelles données seront affichées |
* |
*/ |
|
private void update() { |
|
|
setStatusDisabled(); |
|
// TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes . |
|
navBar.gotoFirst.setEnabled(false); |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT, |
|
setStatusText("Patientez ..."); |
|
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT, |
new ResponseTextHandler(){ |
|
public void onCompletion(String str) { |
378,8 → 402,7 |
|
int j=0; |
if ((jsonArray = jsonValue.isArray()) != null) { |
int i; |
for (i = 0; i < jsonArray.size(); ++i) { |
for (int i = 0; i < jsonArray.size(); ++i) { |
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) { |
int row=table.insertRow(table.getRowCount()); |
// Case a cocher |
397,7 → 420,7 |
// Numero d'ordre |
table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue()); |
|
table.getCellFormatter().setVisible(row,6,true); |
table.getCellFormatter().setVisible(row,6,false); |
|
table.getFlexCellFormatter().setWidth(row,0,"2%"); |
table.getFlexCellFormatter().setWidth(row,1,"31%"); |
409,68 → 432,101 |
} |
|
} |
// Calcul nombre d'enregistrement total (c'est un doublon, c'est normal ...) |
if (i<VISIBLE_TAXON_COUNT) { |
count = startIndex+i; |
} |
setStatusEnabled(); |
|
// Navigation |
} |
}); |
|
} |
|
// Premiere page |
if (startIndex<VISIBLE_TAXON_COUNT ) { |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoFirst.setEnabled(false); |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
if (count < VISIBLE_TAXON_COUNT) { |
setStatusText((startIndex + 1) + " - " + count ); |
/** |
* Recuperation du prefixe d'appel des services |
*/ |
|
private String getServiceBaseUrl() { |
|
Dictionary theme = Dictionary.getDictionary("Parameters"); |
return theme.get("serviceBaseUrl"); |
|
|
} |
else { |
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT)); |
} |
|
} |
// Derniere page |
else { |
if (startIndex>=(count-VISIBLE_TAXON_COUNT)) { |
navBar.gotoPrev.setEnabled(true); |
navBar.gotoFirst.setEnabled(true); |
|
/** |
* Affichage message d'attente et désactivation navigation |
* @param |
* @return void |
*/ |
|
private void setStatusDisabled() { |
|
navBar.gotoFirst.setEnabled(false); |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
setStatusText((startIndex + 1) + " - " + count); |
|
setStatusText("Patientez ..."); |
} |
// Page normale |
else { |
|
|
/** |
* Affichage numero de page et gestion de la navigation |
* |
*/ |
|
private void setStatusEnabled() { |
|
// Il y a forcemment un disabled avant d'arriver ici |
|
if (count > 0 ) { |
|
if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la premiere page |
navBar.gotoPrev.setEnabled(true); |
navBar.gotoFirst.setEnabled(true); |
if (startIndex<(count-VISIBLE_TAXON_COUNT)) { // Pas la derniere page |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT)); |
} |
else { // Derniere page |
setStatusText((startIndex + 1) + " - " + count); |
} |
} |
// Tableau vide (TODO : despaguettiser) |
if (j==0) { |
navBar.gotoPrev.setEnabled(false); |
navBar.gotoFirst.setEnabled(false); |
navBar.gotoNext.setEnabled(false); |
navBar.gotoEnd.setEnabled(false); |
setStatusText(0 + " - " + 0); |
else { // Premiere page |
if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres |
navBar.gotoNext.setEnabled(true); |
navBar.gotoEnd.setEnabled(true); |
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT)); |
} |
else { |
setStatusText((startIndex + 1) + " - " + count); |
} |
}); |
} |
} |
|
|
else { // Pas d'inventaire, pas de navigation |
setStatusText(0 + " - " + 0); |
} |
} |
|
private String getServiceBaseUrl() { |
|
Dictionary theme = Dictionary.getDictionary("Parameters"); |
return theme.get("serviceBaseUrl"); |
/** |
* Positionnement index de parcours (this.startIndex) pour affichage de la dernière page |
* @param |
* @return void |
*/ |
|
private void gotoEnd() { |
|
if ( (count==0) || (count%VISIBLE_TAXON_COUNT)>0) { |
startIndex=count-(count%VISIBLE_TAXON_COUNT); |
} |
else { |
startIndex=count-VISIBLE_TAXON_COUNT; |
} |
|
} |
|
|
} |