New file |
0,0 → 1,683 |
package org.tela_botanica.client.vues; |
|
|
import java.util.Iterator; |
|
import org.tela_botanica.client.modeles.ListeObservation; |
import org.tela_botanica.client.modeles.Observation; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import org.tela_botanica.client.interfaces.ListePaginable; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.interfaces.VueListable; |
|
import com.google.gwt.user.client.Window; |
import com.gwtext.client.core.EventObject; |
import com.gwtext.client.core.Ext; |
import com.gwtext.client.core.ExtElement; |
import com.gwtext.client.core.Function; |
import com.gwtext.client.data.ArrayReader; |
import com.gwtext.client.data.FieldDef; |
import com.gwtext.client.data.MemoryProxy; |
import com.gwtext.client.data.Record; |
import com.gwtext.client.data.RecordDef; |
import com.gwtext.client.data.SimpleStore; |
import com.gwtext.client.data.Store; |
import com.gwtext.client.data.StringFieldDef; |
import com.gwtext.client.widgets.Component; |
import com.gwtext.client.widgets.Tool; |
import com.gwtext.client.widgets.event.ContainerListenerAdapter; |
import com.gwtext.client.widgets.form.ComboBox; |
import com.gwtext.client.widgets.grid.CellMetadata; |
import com.gwtext.client.widgets.grid.ColumnConfig; |
import com.gwtext.client.widgets.grid.ColumnModel; |
import com.gwtext.client.widgets.grid.GridPanel; |
import com.gwtext.client.widgets.grid.Renderer; |
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter; |
|
/** |
* Liste d'observation composée de ligne d'observation |
* l'interface rafraichissable et l'interface vueListable |
* |
* @author David Delon 2008 |
*/ |
public class ListeObservationVue extends GridPanel implements Rafraichissable, |
VueListable, ListePaginable { |
|
/** |
* Le médiateur associé à la vue |
*/ |
private ObservationMediateur observationMediateur = null; |
|
|
/** |
* Config de colonne |
*/ |
private ColumnConfig etatObservation; |
/** |
* Config de colonne |
*/ |
private ColumnConfig nomSaisiObservation; |
/** |
* Config de colonne |
*/ |
private ColumnConfig nomRetenuObservation; |
/** |
* Config de colonne |
*/ |
private ColumnConfig lieuObservation; |
/** |
* Config de colonne |
*/ |
private ColumnConfig dateObservation; |
/** |
* Config de colonne |
*/ |
private ColumnConfig ordreObservation; |
/** |
* Modele de colonnes |
*/ |
private ColumnModel modeleColonnes; |
|
|
/** |
* Store qui contient les données à afficher |
*/ |
private Store st = null; |
|
|
/** |
* Barre de pagination |
*/ |
private BarrePaginationVue bt = null ; |
|
/** |
* Numéro de page en cours |
*/ |
private int pageEncours = 0 ; |
/** |
* Nombre de pages totales |
*/ |
private int pageMax = 1 ; |
/** |
* Taille de page (par défaut 20) |
*/ |
private int taillePage = 20 ; |
/** |
* Nombre d'éléments total correspondant à la requete |
*/ |
private int nbElements = 0 ; |
|
|
private ListeObservation cacheListeObservation = null; |
|
private Tool exporterObservations = null ; |
|
/** |
* Constructeur sans arguments (privé car ne doit pas être utilisé) |
*/ |
@SuppressWarnings("unused") |
private ListeObservationVue() |
{ |
super() ; |
} |
|
/** |
* Constructeur avec argument |
* @param im le médiateur à associer |
*/ |
public ListeObservationVue(ObservationMediateur obs) { |
|
this.observationMediateur = obs; |
|
setHeader(true); |
|
|
// on place la barre de pagination |
bt = new BarrePaginationVue(this); |
bt.setLabelElement("Observations"); |
bt.setTaillePageParDefaut(20); |
bt.setIntervallesPages(new String[] {"400","200", "100" , "50" , "20"}) ; |
this.setBottomToolbar(bt) ; |
|
exporterObservations = new Tool(Tool.PIN, new Function() { |
|
public void execute() { |
observationMediateur.exporterObservations() ; |
} |
|
}, "Exporter des observations") ; |
|
this.addTool(exporterObservations) ; |
|
this.setTitle("Observations") ; |
|
// on construit le modèle de colonnes |
|
// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir) |
|
Renderer colRend = new Renderer() { |
|
public String render(Object value, CellMetadata cellMetadata, |
Record record, int rowIndex, int colNum, Store store) { |
|
if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) { |
|
return "" ; |
} |
else |
{ |
|
} |
|
return value.toString() ; |
} |
|
} ; |
|
etatObservation = new ColumnConfig("Transmis", "etat_observation", 60, true, new Renderer() { |
|
public String render(Object value, CellMetadata cellMetadata, |
Record record, int rowIndex, int colNum, Store store) { |
if(value.equals("1")) |
{ |
return "<input type=\"checkbox\" checked =\"checked\" disabled=\"disabled\" />" ; |
} |
else |
{ |
return "" ; |
} |
} |
|
}); |
nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 200, true, colRend); |
nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 200, true, colRend); |
lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 200, true, colRend); |
dateObservation = new ColumnConfig("Date", "date_observation", 120, true, colRend); |
ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 50, true, colRend); |
|
|
// on associe le modèle de colonnes |
|
ColumnConfig[] cm = {etatObservation, nomSaisiObservation, nomRetenuObservation, lieuObservation, dateObservation, ordreObservation}; |
|
modeleColonnes = new ColumnModel(cm); |
|
this.setColumnModel(modeleColonnes); |
|
this.setAutoScroll(true); |
this.setEnableColumnResize(true); |
|
//temp dd viewport desactive ajout de ces 2 lignes |
// this.setAutoWidth(true); |
// temp |
|
// creation du store |
|
FieldDef defEtatObservation = new StringFieldDef("etat_observation"); |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation"); |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation"); |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation"); |
FieldDef defDateObservation = new StringFieldDef("date_observation"); |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation"); |
|
|
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation, |
defLieuObservation, defDateObservation, defOrdreObservation }; |
|
RecordDef rd = new RecordDef(defTab); |
st = new Store(rd); |
|
// on associe le store |
|
this.setStore(st); |
this.getView().setAutoFill(true); |
this.getView().setForceFit(true) ; |
|
// on crée un masque de chargement qui s'affichera lors des mises à jour |
this.setLoadMask("Chargement"); |
|
// on ajoute les listeners |
ajouterListeners(); |
|
|
} |
|
|
/** |
* Ajoute les listeners pour la gestion des évènements |
*/ |
private void ajouterListeners() { |
|
this.addGridRowListener(new GridRowListenerAdapter() { |
|
// gestion du clic sur une ligne |
public void onRowClick(GridPanel grid, int rowIndex, |
EventObject e) { |
// on notifie le médiateur et on lui passe le nuémro de ligne |
Record rd = getSelectionModel().getSelected(); |
String ordreObservation = rd.getAsString("ordre_observation") ; |
observationMediateur.onClicListeObservation(rowIndex,ordreObservation); |
|
} |
|
// gestion du clic droit |
public void onRowContextMenu(GridPanel grid, int rowIndex, |
EventObject e) { |
// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu |
e.stopEvent() ; |
// on notifie le médiateur en lui passant l'évenement |
observationMediateur.montrerContextMenu(e); |
} |
|
// gestion du double clic |
public void onRowDblClick(GridPanel grid, int rowIndex, |
EventObject e) { |
// on notifie le médiateur en lui passant le numéro de ligne |
observationMediateur.doubleClicListeObservation(rowIndex); |
} |
|
}); |
|
|
/*this.getSelectionModel().addListener(new RowSelectionListenerAdapter() { |
|
// gestion de la sélection |
|
public void onSelectionChange(RowSelectionModel sm) { |
|
// si on a rien de sélectionné |
if (sm.getCount() <= 0) { |
// on notifie le médiateur (qui désactive notamment l'accès à certaines infos) |
// getobservationMediateur().aucuneSelection(); |
} else { |
// sinon on notifie le médiateur |
// getobservationMediateur().selection(); |
// et on lui demande de synchroniser la selection avec les autres vues |
// getobservationMediateur().synchroniserSelection("liste"); |
} |
} |
});*/ |
} |
|
/** |
* Méthode héritée de l'interface VueListable |
* Sélectionne les observations dans la liste suivant les identifiants donnés en paramètres |
*/ |
|
public String[] getIdSelectionnees() { |
|
Record[] selection = this.getSelectionModel().getSelections(); |
int taille = selection.length; |
String id_selection[] = new String[taille]; |
|
for (int i = 0; i < selection.length; i++) { |
|
id_selection[i] = selection[i].getAsString("ordre_observation"); |
} |
|
return id_selection; |
} |
|
|
|
/** |
* Sélectionne des enregistrements donné |
* @param sel un tableau d'enregistrement à selectionner |
*/ |
public void selectionnerEnregistrements(Record[] sel) { |
|
getSelectionModel().clearSelections(); |
getSelectionModel().selectRecords(sel); |
|
} |
|
/** |
* Accesseur pour la toolbar de pagination |
* @return la toolbar de pagination |
*/ |
|
public BarrePaginationVue getToolBarVue() |
{ |
return bt ; |
} |
|
|
/** |
* Recherche l'élement actuellement affiché et affiche son message de chargement |
*/ |
public void masquerChargement() |
{ |
ExtElement masked = Ext.get(getId()) ; |
|
|
if (masked!=null) { |
masked.mask("Chargement") ; |
} |
|
} |
|
/** |
* Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché |
*/ |
public void demasquerChargement() |
{ |
ExtElement masked = Ext.get(getId()) ; |
|
|
if (masked!=null) { |
|
if(masked.isMasked()) |
{ |
masked.unmask() ; |
} |
} |
} |
|
|
|
/** |
* Méthode héritée de l'interface rafraichissable |
* @param nouvelleDonnees les nouvelles données |
* @param repandreRafraichissement le booleen de notification du rafraichissement |
*/ |
|
|
|
public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) { |
|
|
|
|
// si l'on a reçu une liste d'observation |
if(nouvelleDonnees instanceof ListeObservation) |
{ |
|
ListeObservation data = (ListeObservation) nouvelleDonnees ; |
Object[][] observationData = new Object[data.size()][7]; |
int i = 0 ; |
|
if(data.size() == 0) |
{ |
pageEncours = 0 ; |
} |
|
// on la parse et on récupère les informations qui nous interessent |
for (Iterator it = data.keySet().iterator(); it.hasNext();) |
{ |
|
Observation obs=(Observation) data.get(it.next()); |
|
observationData[i][0]= obs.getTransmis(); |
observationData[i][1]= obs.getNomSaisi(); |
observationData[i][2]= obs.getNomRetenu(); |
observationData[i][3]= obs.getLieudit(); |
observationData[i][4]= obs.getDate(); |
observationData[i][5]= obs.getNumeroOrdre(); |
observationData[i][6]= obs.getNumeroNomenclaturalSaisi(); |
|
|
i++ ; |
} |
|
// creation du store qui les contient |
|
FieldDef defEtatObservation = new StringFieldDef("etat_observation"); |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation"); |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation"); |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation"); |
FieldDef defDateObservation = new StringFieldDef("date_observation"); |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation"); |
|
// Non affiches : |
FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation"); |
|
|
// on associe le store |
|
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation, |
defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation }; |
|
RecordDef rd = new RecordDef(defTab); |
|
final MemoryProxy dataProxy = new MemoryProxy(observationData); |
final ArrayReader reader = new ArrayReader(rd); |
|
final Store observationStore = new Store(dataProxy, reader); |
|
|
st = observationStore ; |
st.load() ; |
|
|
// et on reconfigure et rafraichit la vue |
this.reconfigure(st, this.getColumnModel()); |
|
demasquerChargement(); |
|
cacheListeObservation=data; |
|
observationMediateur.onRafraichissementListeObservations(); |
|
|
} |
|
|
// Si on reçoit un tableau d'entiers |
// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères |
if(nouvelleDonnees instanceof int[]) |
{ |
int[] pages = (int[])nouvelleDonnees ; |
|
// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle |
pageMax = calculerNbPages(pages[0]) ; |
nbElements = pages[0] ; |
|
|
// et on notifie de le mediateur du changement des valeurs |
changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ; |
|
masquerChargement(); |
observationMediateur.obtenirListeObservation(this); |
} |
|
|
// si l'on a reçu une Observation |
|
if(nouvelleDonnees instanceof Observation) { |
|
Observation obs= (Observation) nouvelleDonnees; |
if (obs.getNumeroOrdre()==null) { // Nouvelle observation |
// On affiche la dernière page |
|
pageEncours = pageMax ; |
masquerChargement(); |
|
observationMediateur.obtenirNombreObservation(); |
|
} |
else { // Modification d'une observation |
|
|
masquerChargement(); |
|
observationMediateur.obtenirNombreObservation(); |
|
} |
} |
|
} |
|
|
// GESTION DE LA PAGINATION |
|
|
public ListeObservation getCacheListeObservation() { |
return cacheListeObservation; |
} |
|
/** |
* Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page |
* en cours |
* @param nbElements le nombre d'élements total |
* @return le nombre de pages |
*/ |
public int calculerNbPages(int nbElements) |
{ |
// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement |
// pour eviter qu'il arrondisse mal la division |
// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur |
|
double nPage = (1.0*nbElements)/(1.0*taillePage) ; |
double nPageRound = Math.ceil(nPage) ; |
Double nPageInt = new Double(nPageRound) ; |
|
// on convertit en entier |
return nPageInt.intValue() ; |
} |
|
|
/** |
* Recalcule la page en cours lors du changement du nombre d'élements |
* @param nbElements le nombre d'élements total |
* @return la nouvelle page encours |
*/ |
public int calculerPageCourante(int nbElements) |
{ |
// on calcule le nombre de page |
int nouvelNbPages = calculerNbPages(nbElements) ; |
// la nouvelle page en cours |
double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ; |
|
// on arrondit au supérieur |
double nPageRound = Math.ceil(nPageCourante) ; |
Double nPageInt = new Double(nPageRound) ; |
|
// on convertit en entier |
return Math.abs(nPageInt.intValue()) ; |
} |
|
|
/** |
* Appelle le modèle pour lui demander les données d'une page à afficher |
* @param pageCourante le numéro de page à affciher |
*/ |
public void changerNumeroPage(int pageCourante) { |
|
|
|
pageEncours = pageCourante ; |
|
masquerChargement(); |
|
// On lance le chargerment des observations |
observationMediateur.obtenirNombreObservation(); |
|
getToolBarVue().changerPageCourante(pageCourante); |
|
} |
|
|
/** |
* Appelle le modèle pour qu'il change la taille de page utilisée |
* @param nouvelleTaillePage la nouvelle taille de page |
*/ |
|
public void changerTaillePage(int nouvelleTaillePage) |
{ |
|
taillePage = nouvelleTaillePage ; |
pageEncours = calculerPageCourante(nbElements) ; |
|
masquerChargement(); |
|
// On lance le chargement des observations |
observationMediateur.obtenirNombreObservation(); |
|
|
// et on met à jour la taille de page dans les barres d'outils |
getToolBarVue().selectionnerTaillePage(nouvelleTaillePage); |
|
|
} |
|
|
/** |
* Met à jour les barre d'outils avec des nouvelles valeurs |
* @param pageMax le nombre de pages |
* @param pageEncours la page en cours |
* @param taillePage la taille de page |
* @param nbElement le nombre d'élements par page |
*/ |
public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) |
{ |
|
int[] pages = {pageMax,pageEncours, taillePage, nbElement} ; |
getToolBarVue().rafraichir(pages, false) ; |
|
} |
|
/** |
* Renvoie la taille de page en cours d'utilisation |
* @return la taille de page |
*/ |
public int getTaillePage() { |
|
return taillePage; |
} |
|
/** |
* Renvoie le numéro de la page encours (attention on commence à 0) |
* @return le numéro de la page en cours |
*/ |
public int getPageEncours() { |
|
return pageEncours; |
} |
|
public void afficherFiltres(String nLieu, String nDate) |
{ |
|
String titre = "Observations " ; |
|
if(!nLieu.equals("")) |
{ |
titre += " - Lieu : "+nLieu ; |
|
} |
|
if(!nDate .equals("")) |
{ |
titre += " - Date : "+nDate ; |
} |
|
this.setTitle(titre) ; |
} |
|
public void raz() { |
|
|
// creation du store qui les contient |
|
FieldDef defEtatObservation = new StringFieldDef("etat_observation"); |
FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation"); |
FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation"); |
FieldDef defLieuObservation = new StringFieldDef("lieu_observation"); |
FieldDef defDateObservation = new StringFieldDef("date_observation"); |
FieldDef defOrdreObservation = new StringFieldDef("ordre_observation"); |
|
// Non affiches : |
FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation"); |
|
FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation, |
defLieuObservation, defDateObservation, defOrdreObservation }; |
|
RecordDef rd = new RecordDef(defTab); |
st = new Store(rd); |
|
// on associe le store |
|
this.setStore(st); |
|
} |
|
} |
Property changes: |
Added: svn:executable |
+* |
\ No newline at end of property |