Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 4 → Rev 5

/trunk/src/org/tela_botanica/client/CenterPanel.java
17,7 → 17,7
 
public class CenterPanel extends Composite {
 
private Vector complements=new Vector();
private Vector complements=new Vector(); // Complements de saisie associé à nameassistant ... (design a revoir ...).
private TaxonList taxonList = new TaxonList(complements);
private NameAssistant nameAssistant = new NameAssistant(taxonList,complements);
 
/trunk/src/org/tela_botanica/client/TaxonList.java
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,12 → 98,7
}
else {
if (sender==gotoEnd) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
gotoEnd();
}
else {
if (sender== gotoFirst) {
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
// Information complementaire : un tableau associe au retour de l'assistant de saisie
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,12 → 166,7
header.getCellFormatter().setWidth(0,4,"9%");
header.getCellFormatter().setWidth(0,5,"18%");
 
 
header.setCellSpacing(0);
header.setCellPadding(2);
 
// Setup the table.
// Mise en forme de la table.
table.setCellSpacing(0);
table.setBorderWidth(0);
190,10 → 173,10
table.setCellPadding(2);
table.setWidth("100%");
 
 
// Mise en forme barre navigation
navBar.setWidth("100%");
 
table.setStyleName("taxon-List");
 
205,16 → 188,28
}
 
/**
* 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();
// Il y a surement une meilleure facon de faire que de passer par une variable de classe
// pour atteindre une inner classe
// Recherche informations complementaires :
// et Ajout ligne
element=str;
// Saisie assistée
if (pos>=0) {
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);
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,8 → 420,8
// 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%");
table.getFlexCellFormatter().setWidth(row,2,"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;
}
// 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 );
}
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);
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
setStatusText((startIndex + 1) + " - " + count);
}
// Page normale
else {
navBar.gotoPrev.setEnabled(true);
navBar.gotoFirst.setEnabled(true);
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_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);
}
}
setStatusEnabled();
}
});
 
}
private String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
/**
* 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
* @param
* @return void
*/
private void setStatusDisabled() {
navBar.gotoFirst.setEnabled(false);
navBar.gotoPrev.setEnabled(false);
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
setStatusText("Patientez ...");
}
 
 
 
/**
* 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);
}
}
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);
}
}
/**
* 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;
}
}
}