Rev 30 | Blame | Compare with Previous | 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(location) : action suite a la modification, suppression, creation d'un element d'inventaire**/package org.tela_botanica.client;import net.mygwt.ui.client.Events;import net.mygwt.ui.client.Style;import net.mygwt.ui.client.event.BaseEvent;import net.mygwt.ui.client.event.Listener;import net.mygwt.ui.client.widget.ContentPanel;import net.mygwt.ui.client.widget.WidgetContainer;import net.mygwt.ui.client.widget.layout.BorderLayoutData;import net.mygwt.ui.client.widget.layout.FillLayout;import net.mygwt.ui.client.widget.table.Table;import net.mygwt.ui.client.widget.table.TableColumn;import net.mygwt.ui.client.widget.table.TableColumnModel;import net.mygwt.ui.client.widget.table.TableItem;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;import com.google.gwt.json.client.JSONString;import com.google.gwt.json.client.JSONValue;import com.google.gwt.user.client.HTTPRequest;import com.google.gwt.user.client.ResponseTextHandler;import com.google.gwt.user.client.ui.Composite;import com.google.gwt.user.client.ui.DockPanel;import com.google.gwt.user.client.ui.HTML;import com.google.gwt.user.client.ui.HorizontalPanel;import com.google.gwt.user.client.ui.Image;import com.google.gwt.user.client.ui.Button;import com.google.gwt.user.client.ui.Label;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;public class InventoryListView{// Debut Barre de navigationprivate 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;}}}}update();}}// Fin Barre de navigation// Conteneur (header et table sont dans panel)private ContentPanel panel =null;private Table table = null;// Servicesprivate String serviceBaseUrl = null;private String user;private Mediator mediator = null;// Navigationprivate int startIndex = 0;private int count = 0;private static final int VISIBLE_TAXON_COUNT = 15;private NavBar navBar=null;// Filtre par defaut :private String id_location = "all";private String location = "all";private String year = "all";private String month = "all";private String day = "all";private String search = "all";private String lieudit = "all";private String ordre= null;public InventoryListView(Mediator med) {// Traitement contexte utilisateur et servicemediator=med;user=mediator.getUser();serviceBaseUrl = mediator.getServiceBaseUrl();panel= new ContentPanel(Style.HEADER);panel.setLayout(new FillLayout());// Barre navigation integree au headernavBar = new NavBar();panel.getHeader().addWidget(navBar);// Contenu :// Colonnes :TableColumn[] columns = new TableColumn[6];// TODO : renderer date, alignement etccolumns[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);WidgetContainer center=mediator.getCenterContainer();BorderLayoutData centerData = new BorderLayoutData(Style.CENTER, .75f, 100, 1000);center.add(panel,centerData);// Selection d'une lignetable.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 selectionneordre= (String) item.getValue(5);mediator.onInventoryItemSelected(ordre);}else {// Si une ligne etait deja selectionneif (ordre.compareTo((String) item.getValue(5))==0) { // C'est la meme, on la deselectionneordre=null;table.deselect(be.rowIndex);mediator.onInventoryItemUnselected();}else {ordre= (String) item.getValue(5); // C'est une autre, on la selectionnemediator.onInventoryItemSelected(ordre);}}}}});}/*** 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) {mediator.onInventoryUpdated(id_location,"all","all");mediator.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) {update(); // Pour affichage logo}});}setStatusEnabled();}/*** Recherche nombre d'enregistrement pour l'utilisateur et la localite en cours**/public void updateCount () {setStatusDisabled();// Transformation de la date selectionne vers date time stampHTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + id_location + "/" + URL.encodeComponent(location) + "/" + year + "/" + month + "/" + day + "/" + URL.encodeComponent(search) + "/" + URL.encodeComponent(lieudit),new ResponseTextHandler() {public void onCompletion(String str) {JSONValue jsonValue = JSONParser.parse(str);JSONNumber jsonNumber;if ((jsonNumber = jsonValue.isNumber()) != null) {count = (int) jsonNumber.getValue();// if (location.compareTo("")==0) location="000null";gotoEnd(); // Derniere pageupdate();}}});}/*** 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 update() {// TODO : optimisation (ne pas supprimer mais remplacer)// Ligne d'information// Toutes date par defautHTTPRequest.asyncGet(serviceBaseUrl + "/InventoryItemList/" + user + "/" + id_location + "/" + URL.encodeComponent(location) +"/" + year + "/" + month + "/" + day + "/" + URL.encodeComponent(search) + "/" + 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 saisivalues[1] = new HTML("<b>"+Util.toCelString(((JSONString) jsonArrayNested .get(0)).toString())+"</b>");// Nom retenuString 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 - Lieulieu=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 ditif (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);}// MilieuString 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());// Commentaireif (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();// Dateif (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]);}// Spagettiif (ordre!=null) {if (aordre.compareTo(ordre)==0) {table.select(i);}else {table.deselect(i);}}}}}// Suppression fin ancien affichageif (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 iciif (count > 0) {if (startIndex >= VISIBLE_TAXON_COUNT) { // Au dela de la// premiere pagenavBar.gotoPrev.setEnabled(true);navBar.gotoFirst.setEnabled(true);if (startIndex < (count - VISIBLE_TAXON_COUNT)) { // Pas la// derniere// pagenavBar.gotoNext.setEnabled(true);navBar.gotoEnd.setEnabled(true);navBar.status.setText((startIndex + 1) + " - "+ (startIndex + VISIBLE_TAXON_COUNT) + " sur " + count );} else { // Derniere pagenavBar.status.setText((startIndex + 1) + " - " + count + " sur " + count );}} else { // Premiere pageif (count > VISIBLE_TAXON_COUNT) { // Des pages derrieresnavBar.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 navigationnavBar.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 setSearch(String search) {this.search = search;}/** Departement en cours**/public void setIdLocation(String id_location) {this.id_location = id_location;}/** Localite en cours**/public void setLocation(String location) {this.location = location;}/** Lieudit en cours**/public void setLieudit(String lieudit) {this.lieudit = lieudit;}/** Date en cours**/public void setYear(String year) {this.year = year;}public void setMonth(String month) {this.month = month;}public void setDay(String day) {this.day = day;}/** Utilisateur en cours**/public void setUser(String user) {this.user = user;}public void displayFilter() {// Mise a jour boutton export feuille de calculmediator.getActionView().getExportButton().setHTML("<a href=\""+mediator.getServiceBaseUrl()+"/InventoryExport/"+ user + "/"+ URL.encodeComponent(id_location) + "/"+ URL.encodeComponent(location) + "/"+ URL.encodeComponent(lieudit)+ "/"+ year + "/"+ month + "/"+ day+ "\">"+"Export tableur</a>");// Mise a jour ligne de selectionString dep;if (id_location.compareTo("all")==0) {dep="Tous départements";}else {if (id_location.compareTo("000null")==0) {dep="Départements non renseignées ";}else {dep="Département "+id_location;}}String com;if (location.compareTo("all")==0) {com=", toutes communes";}else {if (location.compareTo("000null")==0) {com=", communes non renseignées";}else {com=", commune de "+location;}}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 ((year.compareTo("all")==0) && (month.compareTo("all")==0) && (day.compareTo("all")==0)) {dat=", toutes periodes";}else {String yea="";String da="";String mont="";if (year.compareTo("all")==0) {yea=", toutes années";}else {if (year.compareTo("0")==0) {yea=", periode non renseignée";}else {yea=", "+ year;if (month.compareTo("all")==0) {mont=", tous mois";}else {mont="/"+ month;}if (day.compareTo("all")==0) {da=", tous jours";}else {da="/"+ day;}}}dat=yea + mont + da;}panel.getHeader().setText(dep + com + lieu + dat);}}/* +--Fin du code ---------------------------------------------------------------------------------------+* $Log$* 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**/