Rev 2 | Go to most recent revision | Blame | Last modification | View Log | RSS feed
/**
David Delon david.delon@clapas.net 2007
*/
/*
* ListeObservationsVue.java (Composite de Panel)
*
* Cas d'utilisation :
*
* 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
*
* Selection de releve
*
* 1 : L'utilisateur selectionne un releve : lancement de l'affichage detaille pour le releve selectionne
*
*
* Pagination :
*
* 1 : Avancement ou recul d'une page
*
*
*
* Suppression d'une liste d'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(localite) : action suite a la modification, suppression, creation d'un element d'inventaire
*
*/
package org.tela_botanica.client.observation;
import org.tela_botanica.client.modeles.Observation;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
public class ListeObservationsVue extends Composite {
// 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 Label status = new Label();
public NavBar() {
initWidget(bar);
status.setWordWrap(false);
HorizontalPanel buttons = new HorizontalPanel();
buttons.add(status);
buttons.setCellHorizontalAlignment(status,
HasHorizontalAlignment.ALIGN_RIGHT);
buttons.setCellVerticalAlignment(status,
HasVerticalAlignment.ALIGN_MIDDLE);
buttons.add(gotoFirst);
buttons.add(gotoPrev);
buttons.add(gotoNext);
buttons.add(gotoEnd);
bar.add(buttons, DockPanel.EAST);
}
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) {
gotoEnd();
} else {
if (sender == gotoFirst) {
startIndex = 0;
}
}
}
}
getListeObservation();
}
}
// Fin Barre de navigation
// Conteneur (header et table sont dans panel)
// private ContentPanel panel =null;
// private Table table = null;
// Services
private String serviceBaseUrl = null;
private String user;
private ObservationMediateur observationMediateur = null;
// Navigation
private int startIndex = 0;
private int count = 0;
private static final int VISIBLE_TAXON_COUNT = 15;
private NavBar navBar = null;
// Filtre par defaut :
private String identifiantLocalite = "all";
private String localite = "all";
private String annee = "all";
private String mois = "all";
private String jour = "all";
private String rechercheLibre = "all";
private String lieudit = "all";
private String ordre = null;
public ListeObservationsVue(ObservationMediateur observationMediateur) {
// Traitement contexte utilisateur et service
this.observationMediateur = observationMediateur;
// panel= new ContentPanel(Style.HEADER);
// panel.setLayout(new FillLayout());
// Barre navigation integree au header
navBar = new NavBar();
// panel.getHeader().addWidget(navBar);
// Contenu :
// Colonnes :
// TableColumn[] columns = new TableColumn[6];
// TODO : renderer date, alignement etc
/*
* columns[0] = new TableColumn("etat","Aransmis", 50);
*
* columns[1] = new TableColumn("nom","Nom saisi", 250);
*
* columns[2] = new TableColumn("nomr","Nom retenu", 250);
*
* columns[3] = new TableColumn("lieu","Lieu", 350);
*
* columns[4] = new TableColumn("date","Date", 75);
*
* columns[5] = new TableColumn("ordre","Ordre", 50);
*
*
* TableColumnModel cm = new TableColumnModel(columns);
* // Table :
*
* table = new Table(Style.MULTI | Style.HORIZONTAL, cm);
* table.setBorders(false);
*
*
* panel.add(table);
*
*
* // Selection d'une ligne table.addListener(Events.RowClick, new
* Listener() {
*
* public void handleEvent(BaseEvent be) { TableItem item=(TableItem)
* be.item; if (item!=null) { if (ordre==null) { // Affichage de la
* ligne selectionne ordre= (String) item.getValue(5); //
* observationMediateur.onInventoryItemSelected(ordre); } else { // Si
* une ligne etait deja selectionne if (ordre.compareTo((String)
* item.getValue(5))==0) { // C'est la meme, on la deselectionne
* ordre=null; table.deselect(be.rowIndex); //
* observationMediateur.onInventoryItemUnselected(); } else { ordre=
* (String) item.getValue(5); // C'est une autre, on la selectionne //
* observationMediateur.onInventoryItemSelected(ordre); }
* } } } });
*/
// initWidget(panel);
}
/**
* Suppression d'un ensemble d'element de la liste d'inventaire, on garde
* ici car s'applique a plusieurs elements
*
*/
public void deleteElement() {
/*
* setStatusDisabled(); TableItem[] selection=table.getSelection();
*
* StringBuffer ids=new StringBuffer(); for (int i = 0; i <
* selection.length; i++) { ids.append((String)(((TableItem)
* selection[i]).getValue(5))); if (i<(selection.length-1))
* ids.append(","); }
*
* if (ids.length()>0) {
*
* HTTPRequest.asyncPost(serviceBaseUrl + "/Inventory/" + user + "/" +
* ids.toString(), "action=DELETE",
*
* new ResponseTextHandler() { public void onCompletion(String str) { //
* observationMediateur.onInventoryUpdated(identifiantLocalite,"all","all"); //
* observationMediateur.getEntryView().clear(); } }); }
*
* setStatusEnabled();
*/
}
/**
* Transmission de releve a Tela, on garde ici car s'applique a plusieurs
* elements
*/
public void transmitElement() {
setStatusDisabled();
/*
* TableItem[] selection=table.getSelection();
*
* StringBuffer ids=new StringBuffer(); for (int i = 0; i <
* selection.length; i++) { ids.append((String)(((TableItem)
* selection[i]).getValue(5))); if (i<(selection.length-1))
* ids.append(","); }
*
* if (ids.length()>0) {
*
* HTTPRequest.asyncPost(serviceBaseUrl + "/InventoryTransmit/" + user +
* "/" + ids.toString(), "transmission=1",
*
* new ResponseTextHandler() { public void onCompletion(String str) {
* getListeObservation(); // Pour affichage logo } }); }
*
* setStatusEnabled();
*
*/
}
/**
* Recherche nombre d'enregistrement pour l'utilisateur et la localite en
* cours
*
*/
public void initialiser() {
setStatusDisabled();
// observationMediateur.addListener(ObservationMediateur.NOMBRE_OBSERVATION,this);
observationMediateur.getNombreObservation(identifiantLocalite,
localite, annee, mois, jour, lieudit, rechercheLibre); // Retour
// dans
// handlevent()
// NOMBRE_OBSERVATION
}
/**
* Mise a jour de l'affichage, a partir des donnaes d'inventaire deja
* saisies. La valeur de this.startIndex permet de determiner quelles
* donnaes seront affichees
*
*/
public void getListeObservation() {
// observationMediateur.addListener(ObservationMediateur.LISTE_OBSERVATION,this);
observationMediateur.getListeObservation(identifiantLocalite, localite,
annee, mois, jour, lieudit, rechercheLibre, startIndex,
VISIBLE_TAXON_COUNT); // Retour dans handlevent()
// LISTE_OBSERVATION
}
public void afficherListeObservation() {
Observation[] listeObservation = observationMediateur.getObservation()
.getListeObservation();
for (int i = 0; i < listeObservation.length; i++) {
Object[] values = new Object[6];
values[0] = "0";
values[2] = "2";
values[3] = "3";
values[4] = "4";
values[5] = "5";
values[1] = listeObservation[i].getNomSaisi();
// table.add(new TableItem(values));
}
// Ligne d'information
// Toutes date par defaut
/*
*
* HTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user +
* "/" + identifiantLocalite + "/" + URL.encodeComponent(localite) +"/" +
* annee + "/" + mois + "/" + jour + "/" +
* URL.encodeComponent(rechercheLibre) + "/" +
* URL.encodeComponent(lieudit) + "/" + startIndex + "/" +
* VISIBLE_TAXON_COUNT,
*
* new ResponseTextHandler() {
*
* public void onCompletion(String str) {
*
* JSONValue jsonValue = JSONParser.parse(str); JSONArray jsonArray;
* JSONArray jsonArrayNested;
*
* int i=0;
*
* if ((jsonArray = jsonValue.isArray()) != null) {
*
* StringBuffer lieu=null;
*
* int arraySize = jsonArray.size();
*
* for (i = 0; i < arraySize; ++i) { if ((jsonArrayNested =
* jsonArray.get(i).isArray()) != null) {
*
*
* Object[] values = new Object[6];
*
* // Statut Observation transmise ?
*
* String atransmit=((JSONString) jsonArrayNested
* .get(13)).stringValue();
*
* if (atransmit.compareTo("1")==0) { values[0] = new Image("tela.gif"); }
* else { values[0] = new HTML(" "); }
*
* // Nom saisi
*
* values[1] = new HTML("<b>"+Util.toCelString(((JSONString)
* jsonArrayNested .get(0)).toString())+"</b>");
*
*
* // Nom retenu String aname=Util.toCelString(((JSONString)
* jsonArrayNested .get(2)).toString());
*
* if (aname.compareTo("null")==0) { values[2] = new HTML(" "); }
* else { values[2] = new HTML(aname); } /*
* /* // Num nomenclatural String ann=((JSONString) jsonArrayNested
* .get(3)).stringValue();
*
* if (ann.compareTo("0")!=0) { observationText.append(""+ann+"-"); }
* else { observationText.append("0-"); }
*
* // Num Taxonomique
*
* String ant=((JSONString) jsonArrayNested .get(4)).stringValue();
*
* if (ant.compareTo("0")!=0) { observationText.append(ant+", "); } else {
* observationText.append("0, "); }
* // Famille
*
*
* String afamily=Util.toCelString(((JSONString) jsonArrayNested
* .get(5)).toString());
*
* if (afamily.compareTo("null")==0) { // } else {
* observationText.append(afamily+", "); }
*/
/*
* // Localisation - Lieu
*
* lieu=new StringBuffer();
*
* String aloc=Util.toCelString(((JSONString) jsonArrayNested
* .get(6)).toString());
*
* if (aloc.compareTo("000null")==0) { if (lieu.length()==0) {
* lieu.append("Commune absente"); } else { lieu.append("commune
* absente"); } } else { if (lieu.length()==0) { lieu.append("Commune de
* "+aloc); } else { lieu.append("commune de "+aloc); }
* }
*
*
* String alieudit=Util.toCelString(((JSONString) jsonArrayNested
* .get(9)).toString());
* // Localisation - Lieu dit
*
* if (alieudit.compareTo("000null")!=0) { lieu.append(", "+alieudit); }
*
* // Station -
*
* String astation=Util.toCelString(((JSONString) jsonArrayNested
* .get(10)).toString());
*
*
* if (astation.compareTo("000null")!=0) { lieu.append(", "+astation); }
*
* // Milieu
*
* String amilieu=Util.toCelString(((JSONString) jsonArrayNested
* .get(11)).toString());
*
*
* if (amilieu.compareTo("000null")!=0) { lieu.append(", "+amilieu); }
*
* String acomment=Util.toCelString(((JSONString) jsonArrayNested
* .get(12)).toString()); // Commentaire
*
* if (acomment.compareTo("null")!=0) { lieu.append(", "+acomment); }
*
*
* if (lieu.toString().compareTo("")==0) { values[3] = new
* HTML(" "); } else { values[3] = new HTML(lieu.toString()); }
*
*
* String adate=((JSONString) jsonArrayNested .get(8)).stringValue();
* // Date if (adate.compareTo("0000-00-00 00:00:00")!=0) {
* values[4]=new HTML("<b>"+adate+"</b>"); } else { values[4] = new
* HTML(" "); }
*
*
*
* String aordre=((JSONString) jsonArrayNested.get(7)).stringValue();
* // Numero d'ordre (cache)
*
* values[5] = aordre;
*
*
*
*
* if (i>=table.getItemCount()) { TableItem item = new
* TableItem(values); table.add(item); } else { TableItem
* item=table.getItem(i); item.setValue(0,values[0]);
* item.setValue(1,values[1]); item.setValue(2,values[2]);
* item.setValue(3,values[3]); item.setValue(4,values[4]);
* item.setValue(5,values[5]); }
* // Spagetti if (ordre!=null) { if (aordre.compareTo(ordre)==0) {
* table.select(i); } else { table.deselect(i); } }
* }
* } }
* // Suppression fin ancien affichage if (i<table.getItemCount()) {
* for (int j = table.getItemCount() -1 ; j >= i; j--) { TableItem
* item=table.getItem(j); table.remove(item); } }
*
* setStatusEnabled();
*
* } });
*/
}
/**
* Affichage message d'attente et desactivation navigation
*
* @param
* @return void
*/
private void setStatusDisabled() {
navBar.gotoFirst.setEnabled(false);
navBar.gotoPrev.setEnabled(false);
navBar.gotoNext.setEnabled(false);
navBar.gotoEnd.setEnabled(false);
navBar.status.setText("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);
navBar.status.setText((startIndex + 1) + " - "
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur "
+ count);
} else { // Derniere page
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);
navBar.status.setText((startIndex + 1) + " - "
+ (startIndex + VISIBLE_TAXON_COUNT) + " sur "
+ count);
} else {
navBar.status.setText((startIndex + 1) + " - " + count
+ " sur " + count);
}
}
}
else { // Pas d'inventaire, pas de navigation
navBar.status.setText("0 - 0 sur 0");
}
}
/*
* Positionnement index de parcours (this.startIndex) pour affichage de la
* derniere 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;
}
}
/*
* Recherche en cours
*
*/
public void setRechercheLibre(String search) {
this.rechercheLibre = search;
}
/*
* Departement en cours
*
*/
public void setIdLocation(String id_location) {
this.identifiantLocalite = id_location;
}
/*
* Localite en cours
*
*/
public void setLocalite(String location) {
this.localite = location;
}
/*
* Lieudit en cours
*
*/
public void setLieudit(String lieudit) {
this.lieudit = lieudit;
}
/*
* Date en cours
*
*/
public void setAnnee(String year) {
this.annee = year;
}
public void setMois(String month) {
this.mois = month;
}
public void setJour(String day) {
this.jour = day;
}
/*
* Utilisateur en cours
*
*/
public void setUser(String user) {
this.user = user;
}
public void displayFilter() {
// Mise a jour boutton export feuille de calcul
/*
* observationMediateur.getActionView().getExportButton().setHTML("<a
* href=\""+observationMediateur.getServiceBaseUrl()+"/InventoryExport/" +
* user + "/" + URL.encodeComponent(identifiantLocalite) + "/" +
* URL.encodeComponent(localite) + "/" + URL.encodeComponent(lieudit)+
* "/" + annee + "/" + mois + "/" + jour + "\">"+"Export tableur</a>");
*
*/
// Mise a jour ligne de selection
String dep;
if (identifiantLocalite.compareTo("all") == 0) {
dep = "Tous départements";
} else {
if (identifiantLocalite.compareTo("000null") == 0) {
dep = "Départements non renseignées ";
} else {
dep = "Département " + identifiantLocalite;
}
}
String com;
if (localite.compareTo("all") == 0) {
com = ", toutes communes";
} else {
if (localite.compareTo("000null") == 0) {
com = ", communes non renseignées";
} else {
com = ", commune de " + localite;
}
}
String lieu;
if (lieudit.compareTo("all") == 0) {
lieu = ", tous lieux dits";
} else {
if (lieudit.compareTo("000null") == 0) {
lieu = ", lieu-dit non renseignées";
} else {
lieu = ", lieu-dit " + lieudit;
}
}
String dat;
if ((annee.compareTo("all") == 0) && (mois.compareTo("all") == 0)
&& (jour.compareTo("all") == 0)) {
dat = ", toutes periodes";
}
else {
String yea = "";
String da = "";
String mont = "";
if (annee.compareTo("all") == 0) {
yea = ", toutes années";
} else {
if (annee.compareTo("0") == 0) {
yea = ", periode non renseignée";
} else {
yea = ", " + annee;
if (mois.compareTo("all") == 0) {
mont = ", tous mois";
} else {
mont = "/" + mois;
}
if (jour.compareTo("all") == 0) {
da = ", tous jours";
} else {
da = "/" + jour;
}
}
}
dat = yea + mont + da;
}
// panel.getHeader().setText(dep + com + lieu + dat);
}
// / EVENEMENTS
/**
* Evenements
*
*/
/*
* public void handleEvent(BaseEvent be) { switch (be.type) { case
* ObservationMediateur.NOMBRE_OBSERVATION: gotoEnd();
* getListeObservation(); break; case
* ObservationMediateur.LISTE_OBSERVATION: afficherListeObservation();
* break; } }
*/
}
/*
* +--Fin du code
* ---------------------------------------------------------------------------------------+
* $Log: not supported by cvs2svn $ Revision 1.1 2008-09-19 10:27:18
* aperonnet Carnet en ligne, utilisant gwt 1.5 et la nouvelle version de
* gwt-ext (plus de bugs au demarrage dans firefox, plus rapide et annotations
* java)
*
* Revision 1.3 2008-06-17 14:16:16 aperonnet *** empty log message ***
*
* Revision 1.2 2008-06-09 16:29:01 ddelon import branche observation
*
* Revision 1.1 2008-06-09 14:19:37 ddelon Initialisation observation
*
* Revision 1.3 2008-04-28 13:10:43 ddelon Integration MyGwt
*
* Revision 1.2 2008-01-30 08:55:40 ddelon fin mise en place mygwt
*
* Revision 1.1 2008-01-02 21:26:04 ddelon mise en place mygwt
*
* Revision 1.8 2007-12-22 14:48:53 ddelon Documentation et refactorisation
*
* Revision 1.7 2007-09-17 19:25:34 ddelon Documentation
*
*/