Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 3 → Rev 4

/trunk/src/org/tela_botanica/client/TaxonList.java
16,6 → 16,7
package org.tela_botanica.client;
 
 
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;
33,11 → 34,16
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Widget;
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 com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HasAlignment;
 
import java.util.Vector;
 
/* 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.
*/
68,8 → 74,8
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_RIGHT);
bar.add(status, DockPanel.CENTER);
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
bar.setCellHorizontalAlignment(status, HasAlignment.ALIGN_RIGHT);
bar.setCellVerticalAlignment(status, HasAlignment.ALIGN_MIDDLE);
bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
bar.setCellWidth(status, "100%");
 
// Initialize prev & first button to disabled.
124,20 → 130,32
 
private static final int VISIBLE_TAXON_COUNT = 15;
private Grid header = new Grid(1,3);
private Grid header = new Grid(1,6);
private FlexTable table = new FlexTable();
private CellFormatter cellFormater = table.getCellFormatter();
private VerticalPanel panel = new VerticalPanel();
private int startIndex=0;
private String serviceBaseUrl=getServiceBaseUrl();
private int count=65000;
private Vector complements=null;
private String element=null;
private String complement=null;
private String user;
private NavBar navBar = new NavBar();
public TaxonList() {
public TaxonList(Vector comps) {
 
getUser();
 
// Information complementaire
complements=comps;
// Setup the header
header.setCellSpacing(0);
146,15 → 164,29
 
header.setStyleName("taxon-ListHeader");
header.setText(0, 0, "Action");
header.setText(0, 1, "Nom");
header.setText(0, 2, "Famille");
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, "");
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%");
 
 
header.setCellSpacing(0);
header.setCellPadding(2);
 
// Setup the table.
table.setCellSpacing(0);
table.setBorderWidth(0);
table.setCellPadding(2);
table.setWidth("100%");
 
171,46 → 203,60
initWidget(panel);
// Recherche derniere ligne ... (il y a une autre stratégie pour la calculer si le resultat n'arrive pas assez vite)
 
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/",
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;
}
update();
}
}
});
 
}
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender, String str) {
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,int pos, String str) {
// Ajout ligne
// Recherche informations complementaires :
// et Ajout ligne
if (pos>=0) {
complement=(String) complements.get(pos);
element=str;
HTTPRequest.asyncGet(serviceBaseUrl+"/NameValid/"+complement,
new ResponseTextHandler(){
 
count++;
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str,
new ResponseTextHandler(){
public void onCompletion(String str) {
JSONValue jsonValue= JSONParser.parse(str);
JSONArray jsonArray;
complements.clear();
if ((jsonArray = jsonValue.isArray()) != null) {
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
addElement(element,complement,((JSONString) jsonArray.get(0)).stringValue(),
((JSONString) jsonArray.get(1)).stringValue(),((JSONString) jsonArray.get(2)).stringValue(),
((JSONString) jsonArray.get(3)).stringValue());
}
}
 
public void onCompletion(String str) {
});
}
else {
complements.clear();
 
addElement(str," "," "," "," "," ");
}
}
 
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;
if (table.getRowCount()>0) {
lastOrdre=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,
new ResponseTextHandler(){
public void onCompletion(String str) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
217,31 → 263,32
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
if (startIndex < 0) {
startIndex = 0;
}
update();
}
});
}
});
}
 
}
 
public void deleteElement() {
 
// Lifo ...
for (int i=table.getRowCount()-1; i>=0;i--){
if (((CheckBox) table.getWidget(i,0)).isChecked()) {
String str=table.getText(i,2);
String str=table.getText(i,6);
count--;
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE",
HTTPRequest.asyncPost(serviceBaseUrl+"/Inventory/"+user+"/"+str, "action=DELETE",
new ResponseTextHandler(){
 
public void onCompletion(String str) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
if ((count%VISIBLE_TAXON_COUNT)==0) {
startIndex=count-VISIBLE_TAXON_COUNT;
}
if (startIndex < 0) {
startIndex = 0;
}
update();
}
});
249,9 → 296,63
}
}
}
 
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();
}
getCount();
}
});
 
}
 
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;
}
update();
}
}
});
 
}
 
private void update() {
// TODO : optimisation : ne supprimer que les lignes qui ne seront pas alimentes .
 
navBar.gotoFirst.setEnabled(false);
navBar.gotoPrev.setEnabled(false);
260,7 → 361,7
setStatusText("Patientez ...");
 
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+startIndex+"/"+VISIBLE_TAXON_COUNT,
HTTPRequest.asyncGet(serviceBaseUrl+"/InventoryList/"+user+"/"+startIndex+"/"+VISIBLE_TAXON_COUNT,
new ResponseTextHandler(){
 
public void onCompletion(String str) {
275,18 → 376,40
}
 
 
int j=0;
if ((jsonArray = jsonValue.isArray()) != null) {
int i;
for (i = 0; i < jsonArray.size(); ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
int row=table.insertRow(table.getRowCount());
// Case a cocher
table.setWidget(row,0,new CheckBox());
// Nom saisi
table.setText(row,1,((JSONString) jsonArrayNested.get(0)).stringValue());
table.setText(row,2,((JSONString) jsonArrayNested.get(1)).stringValue());
cellFormater.setVisible(row,2,false);
// Nom retenu
table.setText(row,2,((JSONString) jsonArrayNested.get(2)).stringValue());
// Num nomenclatural
table.setText(row,3,((JSONString) jsonArrayNested.get(1)).stringValue());
// Num Taxonomique
table.setText(row,4,((JSONString) jsonArrayNested.get(4)).stringValue());
// Famille
table.setText(row,5,((JSONString) jsonArrayNested.get(5)).stringValue());
// Numero d'ordre
table.setText(row,6,((JSONString) jsonArrayNested.get(6)).stringValue());
table.getCellFormatter().setVisible(row,6,true);
table.getFlexCellFormatter().setWidth(row,0,"2%");
table.getFlexCellFormatter().setWidth(row,1,"31%");
table.getFlexCellFormatter().setWidth(row,2,"31%");
table.getFlexCellFormatter().setWidth(row,3,"9%");
table.getFlexCellFormatter().setWidth(row,4,"9%");
table.getFlexCellFormatter().setWidth(row,5,"18%");
j++;
}
}
// Calcul nombre d'enregistrement total
// Calcul nombre d'enregistrement total (c'est un doublon, c'est normal ...)
if (i<VISIBLE_TAXON_COUNT) {
count = startIndex+i;
}
293,14 → 416,19
// Navigation
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
 
// Premiere page
if (startIndex<VISIBLE_TAXON_COUNT) {
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
312,21 → 440,37
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);
}
}
});
 
}
private String getServiceBaseUrl() {
Dictionary theme = Dictionary.getDictionary("Parameters");
return theme.get("serviceBaseUrl");
 
}
 
 
 
}