Subversion Repositories eFlore/Archives.cel-v1

Compare Revisions

Ignore whitespace Rev 25 → Rev 26

/trunk/src/org/tela_botanica/client/InventoryItemList.java
1,23 → 1,52
/**
David Delon david.delon@clapas.net 2007
*/
 
/*
* Copyright 2006 Google Inc.
* InventoryItemList.java (Composite de Panel)
*
* Cas d'utilisation :
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
* Affichage de releve
*
* 1 : Recherche du nombre de releves associe au navigateur ou a l'utilisateur est connecte, en fonction des criteres de selection
* 2 : Recherche des releves correspondant au critere precedent
* 3 : Affichage des releves avec positionnement sur le dernier releve
*
* http://www.apache.org/licenses/LICENSE-2.0
* Selection de releve
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
* 1 : L'utilisateur selectionne un releve : lancement de l'affichage detaille pour le releve selectionne
*
*
* Pagination :
*
* 1 : Avancement ou recul d'une page
*
*
* C(R)UD Element d'inventaire : (TODO : creer un nouvel objet pour cela)
*
* 1 : Ajoute d'un element
* 2 : Modification d'un element
* 3 : Suppression d'un element
*/
 
 
/* Actions declenchees :
*
* onInventoryItemSelected(numero d'ordre de la ligne selectionne) : selection d'une ligne
* onInventoryItemUnselected(numero d'ordre de la ligne selectionne) : deselection d'une ligne
* onInventoryUpdated(location) : action suite a la modification, suppression, creation d'un element d'inventaire
*
*/
 
 
package org.tela_botanica.client;
 
import java.util.Iterator;
import java.util.Vector;
 
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONParser;
34,7 → 63,6
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;
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;
42,30 → 70,18
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
 
/*
* Le retour de getUser appelle updateCount qui appelle update pour veiller à une
* initialisation correcte
*
*/
 
public class InventoryItemList extends Composite implements
AutoCompleteAsyncTextBoxListener {
public class InventoryItemList extends Composite
{
 
// Barre de navigation
// Debut Barre de navigation
 
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();
 
72,36 → 88,27
public NavBar() {
initWidget(bar);
HorizontalPanel bar = new HorizontalPanel();
bar.setStyleName("navbar");
status.setStyleName("status");
HorizontalPanel buttons = new HorizontalPanel();
buttons.add(status);
buttons.setCellHorizontalAlignment(status,
HasHorizontalAlignment.ALIGN_RIGHT);
buttons.setCellVerticalAlignment(status,
HasVerticalAlignment.ALIGN_MIDDLE);
buttons.setCellWidth(status, "100%");
bar.add(status);
bar.setCellHorizontalAlignment(status, HasHorizontalAlignment.ALIGN_RIGHT);
bar.setCellVerticalAlignment(status, HasVerticalAlignment.ALIGN_MIDDLE);
bar.setCellWidth(status, "100%");
 
 
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(gotoFirst);
bar.add(gotoPrev);
bar.add(gotoNext);
bar.add(gotoEnd);
bar.setCellHorizontalAlignment(buttons, DockPanel.ALIGN_LEFT);
 
bar.setVerticalAlignment(DockPanel.ALIGN_MIDDLE);
initWidget(bar);
}
 
public void onClick(Widget sender) {
if (sender == gotoNext) {
130,33 → 137,30
 
}
 
private void setStatusText(String text) {
navBar.status.setText(text);
}
// Fin Barre de navigation
 
private static final int VISIBLE_TAXON_COUNT = 15;
 
 
// Conteneur (header et table sont dans panel)
private Grid header = new Grid(1, 3);
 
private FlexTable table = new FlexTable();
 
private VerticalPanel panel = new VerticalPanel();
 
private int startIndex = 0;
 
// Services
private String serviceBaseUrl = null;
 
private int count = 65000;
 
private String user;
private Mediator mediator = null;
 
// Navigation
private int startIndex = 0;
private int count = 0;
private static final int VISIBLE_TAXON_COUNT = 15;
private NavBar navBar=null;
private Mediator mediator = null;
private int selectedRow = -1;
 
private int selectedRow = -1;
// Filtre par defaut :
private String location = "all";
private String date = "all";
163,21 → 167,22
private String search = "all";
private String station = "all";
 
 
public InventoryItemList(Mediator med) {
// Traitement contexte utilisateur et service
 
mediator=med;
mediator.registerInventoryItemList(this);
user=mediator.getUser();
serviceBaseUrl = mediator.getServiceBaseUrl();
// Barre navigation integree au header
navBar = new NavBar();
 
// Information complementaire : un tableau associe au retour de
// l'assistant de saisie
 
// Mise en forme du header
 
header.setCellSpacing(0);
188,7 → 193,7
 
header.setWidget(0, 2, navBar);
 
// Mise en forme de la table.
// Mise en forme de la table (contenu)
 
table.setCellSpacing(0);
table.setBorderWidth(0);
196,26 → 201,29
table.setWidth("100%");
 
// Mise en forme barre navigation
 
navBar.setWidth("100%");
 
table.setStyleName("inventoryItem-List");
 
//panel.add(navBar);
panel.add(header);
panel.add(table);
 
// Hook up events.
table.addTableListener(new TableListener () {
public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
if ((table.getWidget(row, 0)!=null) && (cell>0)){
selectRow(row);
// Numero d'ordre
mediator.onInventoryItemSelected(table.getText(row, 5));
if (row!=selectedRow) {
selectRow(row);
// Numero d'ordre
mediator.onInventoryItemSelected(table.getText(row, 5));
}
// Deselection
else {
styleRow(row, false);
selectedRow=-1;
// Numero d'ordre
mediator.onInventoryItemUnselected(table.getText(row, 5));
}
}
}
 
222,90 → 230,53
});
 
//updateCount();
// update()
 
initWidget(panel);
 
 
}
/**
* Gestion affichage selection/deselection d'un element d'inventaire
*
*/
private void selectRow(int row) {
 
styleRow(selectedRow, false);
styleRow(row, true);
 
selectedRow = row;
}
}
private void styleRow(int row, boolean selected) {
if (row != -1) {
if (selected)
table.getRowFormatter().addStyleName(row, "inventoryItem-SelectedRow");
else
if (row < table.getRowCount()) {
table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
}
}
}
private void styleRow(int row, boolean selected) {
if (row != -1) {
if (selected)
table.getRowFormatter().addStyleName(row, "inventoryItem-SelectedRow");
else
if (row < table.getRowCount()) {
table.getRowFormatter().removeStyleName(row, "inventoryItem-SelectedRow");
}
}
}
 
 
 
/**
* Action lancee par la completion d'un nom dans l'assistant de saisie
* Recherche d'information complémentaires ....
*
* @return void
*/
public void onComplete(ResponseTextHandler sender, String str, String value) {
if (sender instanceof NameAssistant) {
mediator.onNameCompleted(value);
}
 
}
 
/**
* 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
* Lancement de la mise a jour d'une ligne d'inventaire (appele par Mediator.onModifyInventoryItem())
*
*/
public void onValidate(SourcesAutoCompleteAsyncTextBoxEvents sender,
String str, String value) {
public void updateElement() {
if (mediator.getEntryPanel().getOrdre()==null) {
mediator.onAddInventoryItem();
}
else {
mediator.onModifyInventoryItem(mediator.getEntryPanel().getOrdre());
mediator.getEntryPanel().setOrdre(null);
}
 
}
 
// Action sur modification d'un element
public void updateElement() {
if (mediator.inventoryItemIsValid()) {
final InventoryItem inventoryItem=mediator.getInventoryItem();
setStatusDisabled();
// Modification d'un nom faisant parti du referentiel : recherche du nom valide correspondant
if (inventoryItem.getNomenclaturalNumber() !=null) {
318,8 → 289,7
JSONArray jsonArray;
if ((jsonArray = jsonValue.isArray()) != null) {
// Nom retenu, Num Nomen nom retenu, Num Taxon,
// Famille
// Nom retenu, Num Nomen nom retenu, Num Taxon, Famille
updateElement(inventoryItem.getOrdre(),inventoryItem.getName(), inventoryItem.getNomenclaturalNumber(),
((JSONString) jsonArray.get(0))
.stringValue(),
335,7 → 305,7
});
}
// Saisie libre
// Modification d'un nom ne faisant pas parti du referentiel (saisie libre)
else {
updateElement(inventoryItem.getOrdre(),inventoryItem.getName(), " ", " ", " ", " ", " ",inventoryItem.getLocation(),inventoryItem.getLocation_id(),inventoryItem.getDate(),inventoryItem.getComplementlocation(),inventoryItem.getComment());
}
342,15 → 312,18
}
else {
// TODO : message d'erreur
return;
}
}
 
/**
* Lancement de la creation d'une ligne d'inventaire (appele par Mediator.onAddInventoryItem())
*
*/
// Action sur ajout d'un element
public void addelement() {
360,20 → 333,8
setStatusDisabled();
// 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
// Creation d'un nom faisant parti du referentiel : recherche du nom valide correspondant
 
if (inventoryItem.getNomenclaturalNumber() !=null) {
HTTPRequest.asyncGet(serviceBaseUrl + "/NameValid/" + inventoryItem.getNomenclaturalNumber(),
409,12 → 370,15
}
else {
// TODO : message d'erreur
return;
}
}
 
/**
* Ajoute un element à l'inventaire
* Ajoute effectif d'un element a l'inventaire (appel interne)
*
* @param nom_sel :
* nom selectionne
449,7 → 413,6
location="000null";
}
mediator.onInventoryUpdated(location);
updateCount();
}
});
}
457,7 → 420,7
 
/**
* Modifie un element de l'inventaire
* Modification effective d'un element de l'inventaire (appel interne)
*
* @param ordre : numero d'ordre
* @param nom_sel :
488,30 → 451,28
 
public void onCompletion(String str) {
mediator.onInventoryUpdated(location);
update();
}
});
}
 
/**
* Transmission de releve à Tela
* Suppression effective d'un element lde l'inventaire, a partir de son numero d'ordre
*
*/
 
public void transmitElement() {
public void deleteElement() {
 
setStatusDisabled();
Vector parseChecked = new Vector();
 
// TODO : optimiser
// Lifo ...
for (int i = table.getRowCount() - 1; i >= 0; i--) {
if (table.getWidget(i, 0)!=null) {
if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
// Numero ordre
parseChecked.add(table.getText(i, 5));
count--;
}
}
}
520,15 → 481,14
ids.append((String)it.next());
if (it.hasNext()) ids.append(",");
}
if (ids.length()>0) {
HTTPRequest.asyncPost(serviceBaseUrl + "/InventoryTransmit/" + user
+ "/" + ids.toString(), "transmission=1",
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
+ "/" + ids.toString(), "action=DELETE",
new ResponseTextHandler() {
public void onCompletion(String str) {
update();
mediator.onInventoryUpdated(location);
}
});
}
535,60 → 495,62
setStatusEnabled();
 
}
/**
* Suppression d'un element lde l'inventaire, a partir de son numero d'ordre
*
* Transmission de releve a Tela (TODO : a appeler par Mediator)
*/
 
public void deleteElement() {
 
public void transmitElement() {
setStatusDisabled();
Vector parseChecked = new Vector();
 
// TODO : optimiser
// Lifo ...
for (int i = table.getRowCount() - 1; i >= 0; i--) {
if (table.getWidget(i, 0)!=null) {
if (((CheckBox) table.getWidget(i, 0)).isChecked()) {
// Numero ordre
parseChecked.add(table.getText(i, 5));
count--;
}
}
}
StringBuffer ids=new StringBuffer();
for (Iterator it = parseChecked.iterator(); it.hasNext();) {
ids.append((String)it.next());
if (it.hasNext()) ids.append(",");
}
if (ids.length()>0) {
HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user
+ "/" + ids.toString(), "action=DELETE",
HTTPRequest.asyncPost(serviceBaseUrl + "/InventoryTransmit/" + user
+ "/" + ids.toString(), "transmission=1",
new ResponseTextHandler() {
public void onCompletion(String str) {
mediator.onInventoryUpdated("all");
updateCount();
update(); // Pour affichage logo
}
});
}
setStatusEnabled();
 
}
/**
* Selection de l'ensemble des elements affichés
* Selection/Deselection de l'ensemble des elements affiches
*
*/
 
public void selectAll() {
 
// TODO : optimiser ...
for (int i = table.getRowCount() - 1; i >= 0; i--) {
if (table.getWidget(i, 0)!=null)
((CheckBox) table.getWidget(i, 0)).setChecked(true);
597,7 → 559,6
 
public void deselectAll() {
// TODO : optimiser ...
for (int i = table.getRowCount() - 1; i >= 0; i--) {
if (table.getWidget(i, 0)!=null)
((CheckBox) table.getWidget(i, 0)).setChecked(false);
610,16 → 571,20
* Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours
*
*/
public void updateCount () {
setStatusDisabled();
 
// Transformation de la date selectionne vers date time stamp
String adate="all";
if (date.compareTo("all")!=0) {
adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
}
 
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location + "/" + adate + "/" + search + "/" + station,
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + URL.encodeComponent(location) + "/" + adate + "/" + URL.encodeComponent(search) + "/" + URL.encodeComponent(station),
new ResponseTextHandler() {
 
public void onCompletion(String str) {
628,14 → 593,7
JSONNumber jsonNumber;
if ((jsonNumber = jsonValue.isNumber()) != null) {
count = (int) jsonNumber.getValue();
/*
if (count==0) {
location="all";
}
*/
if (location.compareTo("")==0)
location="000null";
// mediator.onInventoryItemUpdate(location);
// if (location.compareTo("")==0) location="000null";
gotoEnd(); // Derniere page
update();
}
644,6 → 602,7
 
}
// Utilitaire affichage
private String subLeft(String text, int length) {
return (text.length() < length) ? text : text.substring(0, length)+ " ...";
650,83 → 609,29
}
 
/**
* Mise a jour de l'affichage, à partir des données d'inventaire deja
* Mise a jour de l'affichage, a partir des donnaes d'inventaire deja
* saisies. La valeur de this.startIndex permet de determiner quelles
* données seront affichées
* donnaes seront affichees
*
* @param deep : force une mise a jour totale
*/
 
public void update() {
 
// Mise a jour boutton export feuille de calcul
mediator.getActionPanel().getExportButton().setHTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/"
+ user + "/"
+ location + "/"
+ station + "/"
+ search + "/"
+ date +
"\">"+"Export&nbsp;tableur</a>");
 
// table.setBorderWidth(1); // Debug
// table.setBorderWidth(1);
// Ligne d'information
setStatusDisabled();
 
String adate="all";
if (date.compareTo("all")!=0) {
adate=date.substring(6,10)+"-"+date.substring(3,5)+"-"+date.substring(0,2)+" 00:00:00";
}
String com;
if (location.compareTo("all")==0) {
com="Toutes communes";
}
else {
if (location.compareTo("000null")==0) {
com="Communes non renseign&eacute;es";
}
else {
com="Commune de "+location;
}
}
 
String dat;
if (date.compareTo("all")==0) {
dat=", toutes p&eacute;riodes";
}
else {
if (date.compareTo("00/00/0000")==0) {
dat=", p&eacute;riodes non renseign&eacute;es";
}
else {
dat=", le "+ date;
}
}
String stat;
if (station.compareTo("all")==0) {
stat=", toutes stations";
}
else {
if (station.compareTo("000null")==0) {
stat=", stations non renseign&eacute;es";
}
else {
stat=", station "+ station;
}
}
header.setHTML(0, 0, com + dat + stat );
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + location +"/" + adate + "/" + search + "/" + station + "/"
HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + URL.encodeComponent(location) +"/" + adate + "/" + search + "/" + URL.encodeComponent(station) + "/"
+ startIndex + "/" + VISIBLE_TAXON_COUNT,
 
new ResponseTextHandler() {
737,17 → 642,17
JSONArray jsonArray;
JSONArray jsonArrayNested;
StringBuffer left=new StringBuffer();
StringBuffer center=new StringBuffer();
StringBuffer right=new StringBuffer();
 
int row=0;
int i=0;
if ((jsonArray = jsonValue.isArray()) != null) {
StringBuffer left=new StringBuffer();
StringBuffer center=new StringBuffer();
StringBuffer right=new StringBuffer();
 
int arraySize = jsonArray.size();
for (i = 0; i < arraySize; ++i) {
if ((jsonArrayNested = jsonArray.get(i).isArray()) != null) {
if (i>=table.getRowCount()) {
888,26 → 793,10
String aordre=((JSONString) jsonArrayNested.get(7)).stringValue();
// Numero d'ordre (caché)
// Numero d'ordre (cache)
table.setText(row, 5, aordre);
 
/*
if (add){
if (i ==(arraySize -1)) {
selectRow(row);
mediator.getEntryPanel().setOrdre(aordre);
}
}
else {
if ((mediator.getEntryPanel().getOrdre()!=null) && (mediator.getEntryPanel().getOrdre().compareTo(aordre)==0)) {
selectRow(row);
}
}
*/
 
table.getCellFormatter().setVisible(row, 5, false);
 
940,7 → 829,7
 
 
/**
* Affichage message d'attente et désactivation navigation
* Affichage message d'attente et desactivation navigation
*
* @param
* @return void
953,7 → 842,7
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
 
setStatusText("Patientez ...");
navBar.status.setText("Patientez ...");
}
 
/**
976,31 → 865,31
// page
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
setStatusText((startIndex + 1) + " - "
navBar.status.setText((startIndex + 1) + " - "
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );
} else { // Derniere page
setStatusText((startIndex + 1) + " - " + count + " sur " + count );
navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count );
}
} else { // Premiere page
if (count > VISIBLE_TAXON_COUNT) { // Des pages derrieres
navBar.gotoNext.setEnabled(true);
navBar.gotoEnd.setEnabled(true);
setStatusText((startIndex + 1) + " - "
navBar.status.setText((startIndex + 1) + " - "
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count);
} else {
setStatusText((startIndex + 1) + " - " + count + " sur " + count);
navBar.status.setText((startIndex + 1) + " - " + count + " sur " + count);
}
}
}
 
else { // Pas d'inventaire, pas de navigation
setStatusText("0 - 0 sur 0");
navBar.status.setText("0 - 0 sur 0");
}
}
 
/*
* Positionnement index de parcours (this.startIndex) pour affichage de la
* dernière page
* derniere page
*
* @param
* @return void
1025,7 → 914,6
this.search = search;
}
 
 
/*
* Localite en cours
1037,23 → 925,137
}
 
 
/*
* Station en cours
*
*/
 
public void setStation(String station) {
this.station = station;
}
 
 
/*
* Date en cours
*
*/
 
public void setDate(String date) {
this.date = date;
}
 
/*
* Utilisateur en cours
*
*/
 
public void setUser(String user) {
this.user = user;
}
 
 
public String getDate() {
return date;
}
 
 
public String getLocation() {
return location;
}
 
 
public String getSearch() {
return search;
}
 
 
public String getStation() {
return station;
}
 
 
public Grid getHeader() {
return header;
}
 
public void setStation(String station) {
this.station = station;
public void displayFilter() {
// Mise a jour boutton export feuille de calcul
mediator.getActionPanel().getExportButton().setHTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/"
+ user + "/"
+ URL.encodeComponent(location) + "/"
+ URL.encodeComponent(station)+ "/"
+ URL.encodeComponent(search) + "/"
+ date +
"\">"+"Export&nbsp;tableur</a>");
 
// Mise a jour ligne de selection
 
String com;
if (location.compareTo("all")==0) {
com="Toutes communes";
}
else {
if (location.compareTo("000null")==0) {
com="Communes non renseign&eacute;es";
}
else {
com="Commune de "+location;
}
}
 
String dat;
if (date.compareTo("all")==0) {
dat=", toutes p&eacute;riodes";
}
else {
if (date.compareTo("00/00/0000")==0) {
dat=", p&eacute;riodes non renseign&eacute;es";
}
else {
dat=", le "+ date;
}
}
 
String stat;
if (station.compareTo("all")==0) {
stat=", toutes stations";
}
else {
if (station.compareTo("000null")==0) {
stat=", stations non renseign&eacute;es";
}
else {
stat=", station "+ station;
}
}
 
header.setHTML(0, 0, com + dat + stat );
 
}
 
 
}
 
/* +--Fin du code ---------------------------------------------------------------------------------------+
* $Log$
*/