Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 2 → Rev 3

/trunk/src/org/tela_botanica/client/TaxonList.java
17,6 → 17,7
 
 
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
25,9 → 26,16
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.DockPanel;
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.HTMLTable.CellFormatter;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HasAlignment;
 
 
/**
36,13 → 44,100
public class TaxonList extends Composite implements AutoCompleteAsyncTextBoxListener {
 
 
private class NavBar extends Composite implements ClickListener {
public final DockPanel bar = new DockPanel();
public final Button gotoFirst = new Button("<<", this);
public final Button gotoNext = new Button(">", this);
public final Button gotoPrev = new Button("<", this);
public final Button gotoEnd = new Button(">>", this);
public final HTML status = new HTML();
 
public NavBar() {
initWidget(bar);
bar.setStyleName("navbar");
status.setStyleName("status");
 
HorizontalPanel buttons = new HorizontalPanel();
buttons.add(gotoFirst);
buttons.add(gotoPrev);
buttons.add(gotoNext);
buttons.add(gotoEnd);
bar.add(buttons, DockPanel.EAST);
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.setCellWidth(status, "100%");
 
// Initialize prev & first button to disabled.
//
}
 
public void onClick(Widget sender) {
if (sender == gotoNext) {
// Move forward a page.
startIndex += VISIBLE_TAXON_COUNT;
if (startIndex >= count)
startIndex -= VISIBLE_TAXON_COUNT;
}
else {
if (sender == gotoPrev) {
// Move back a page.
startIndex -= VISIBLE_TAXON_COUNT;
if (startIndex < 0)
startIndex = 0;
}
else {
if (sender==gotoEnd) {
if ((count%VISIBLE_TAXON_COUNT)>0) {
startIndex=count-(count%VISIBLE_TAXON_COUNT);
}
else {
startIndex=count-VISIBLE_TAXON_COUNT;
}
}
else {
if (sender== gotoFirst) {
startIndex = 0;
}
}
}
}
update();
}
 
}
 
public void setStatusText(String text) {
navBar.status.setText(text);
}
 
public void clearStatusText() {
navBar.status.setHTML("&nbsp;");
}
 
 
private static final int VISIBLE_TAXON_COUNT = 15;
private Grid header = new Grid(1,3);
private FlexTable table = new FlexTable();
private CellFormatter cellFormater = table.getCellFormatter();
private VerticalPanel panel = new VerticalPanel();
private int startIndex=0;
private int count=65000;
private NavBar navBar = new NavBar();
public TaxonList() {
 
// Setup the header
header.setCellSpacing(0);
54,6 → 149,8
header.setText(0, 0, "Action");
header.setText(0, 1, "Nom");
header.setText(0, 2, "Famille");
// Setup the table.
61,36 → 158,66
table.setCellPadding(2);
table.setWidth("100%");
 
 
navBar.setWidth("100%");
 
table.setStyleName("taxon-List");
 
panel.add(navBar);
panel.add(header);
panel.add(table);
initWidget(panel);
update();
// 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) {
// TODO : passer par une table de stockage temporaire
// TODO : creer un objet externe ...
// Ajout ligne
 
count++;
int lastOrdre=new Integer(table.getText(table.getRowCount()-1,2)).intValue()+1;
int row=table.insertRow(table.getRowCount());
table.setWidget(row,0,new CheckBox());
table.setText(row,1,str);
table.setText(row,2,new Integer(lastOrdre).toString());
cellFormater.setVisible(row,2,false);
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/", "identifiant=dd&nom="+str,
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;
}
update();
}
});
103,12 → 230,19
// Lifo ...
for (int i=table.getRowCount()-1; i>=0;i--){
if (((CheckBox) table.getWidget(i,0)).isChecked()) {
String str=table.getText(i,2);
table.removeRow(i);
String str=table.getText(i,2);
count--;
HTTPRequest.asyncPost("http://localhost/david/jrest/Inventory/dd/"+str, "action=DELETE",
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;
}
update();
}
});
 
118,9 → 252,15
private void update() {
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+"1",
 
navBar.gotoFirst.setEnabled(false);
navBar.gotoPrev.setEnabled(false);
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
setStatusText("Patientez ...");
 
HTTPRequest.asyncGet("http://localhost/david/jrest/InventoryList/dd/"+startIndex+"/"+VISIBLE_TAXON_COUNT,
new ResponseTextHandler(){
 
public void onCompletion(String str) {
136,7 → 276,8
 
 
if ((jsonArray = jsonValue.isArray()) != null) {
for (int i = 0; i < jsonArray.size(); ++i) {
int i;
for (i = 0; i < jsonArray.size(); ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
int row=table.insertRow(table.getRowCount());
table.setWidget(row,0,new CheckBox());
145,11 → 286,47
cellFormater.setVisible(row,2,false);
}
}
// Calcul nombre d'enregistrement total
if (i<VISIBLE_TAXON_COUNT) {
count = startIndex+i;
}
// Navigation
setStatusText((startIndex + 1) + " - " + (startIndex + VISIBLE_TAXON_COUNT));
 
// Premiere page
if (startIndex<VISIBLE_TAXON_COUNT) {
navBar.gotoPrev.setEnabled(false);
navBar.gotoFirst.setEnabled(false);
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
}
// 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);
}
else {
navBar.gotoPrev.setEnabled(true);
navBar.gotoFirst.setEnabled(true);
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
}
}
}
}
});
 
}
 
}