Rev 436 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.MissingResourceException;import org.tela_botanica.client.ComposantClass;import org.tela_botanica.client.ComposantId;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.RegistreId;import org.tela_botanica.client.i18n.Constantes;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Configuration;import org.tela_botanica.client.modeles.Personne;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import org.tela_botanica.client.util.UtilTruk;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.Style.VerticalAlignment;import com.extjs.gxt.ui.client.util.Format;import com.extjs.gxt.ui.client.util.Params;import com.extjs.gxt.ui.client.widget.ContentPanel;import com.extjs.gxt.ui.client.widget.Html;import com.extjs.gxt.ui.client.widget.LayoutContainer;import com.extjs.gxt.ui.client.widget.TabItem;import com.extjs.gxt.ui.client.widget.TabPanel;import com.extjs.gxt.ui.client.widget.Text;import com.extjs.gxt.ui.client.widget.form.FieldSet;import com.extjs.gxt.ui.client.widget.form.LabelField;import com.extjs.gxt.ui.client.widget.layout.ColumnData;import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;import com.extjs.gxt.ui.client.widget.layout.FitLayout;import com.extjs.gxt.ui.client.widget.layout.FlowLayout;import com.extjs.gxt.ui.client.widget.layout.FormLayout;import com.extjs.gxt.ui.client.widget.layout.RowData;import com.extjs.gxt.ui.client.widget.layout.RowLayout;import com.extjs.gxt.ui.client.widget.layout.TableData;import com.extjs.gxt.ui.client.widget.layout.TableLayout;import com.google.gwt.core.client.GWT;import com.google.gwt.i18n.client.DateTimeFormat;import com.google.gwt.user.client.ui.Image;public class PersonneDetailVue extends LayoutContainer implements Rafraichissable {private LayoutContainer lcDetailHaut;// Le panneau détail se compose de formulaires tabulésprivate TabPanel tabPanel;// Onglet 1 : identite & contactprivate TabItem tabIdentite;private FieldSet fsIdentite;private FieldSet fsContact;// Onglet 2 : Adressesprivate TabItem tabAdresse;private FieldSet fsAdressePerso;// contient : adresse perso / adresse pro// Onglet 3 : Informations naturalistesprivate TabItem tabInfosNat;private FieldSet fsSpec;//Onglet 4 : logosprivate TabItem tabLogos;private Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);//Templatesstyle='display:inline-block; padding-left:15px; width:70%; font-size:11px'private String enteteTpl = "<div id='{css_id}'>"+"<h1>{nom}</h1>"+"<h2><a href='{mail}'>{mail}</a></h2>" +"</div>";private String tabIdentiteTpl = "<div class='coel-fieldset'>" +" <span><b>Nom Complet:</b></span> {nom_complet}<br />" +" <span><b>Autres noms:</b></span> {nom_autre}<br />" +" <span><b>Abréviation:</b></span> {abreviation}<br />" +" <span><b>Autres Abréviations:</b></b></span> {abreviation_autre}<br /><br />" +" <span><b>Date de naissance</b></span> {naissance_date}<br />" +" <span><b>Lieu de naissance:</b></span> {naissance_lieu}<br /><br />" +" <span><b>Date de décès:</b></span> {deces_date}<br />" +" <span><b>Lieu de décès:</b></span> {deces_lieu}<br /><br />" +"</div>" +"<div class='coel-fieldset'>" +" <span style='vertical-align:top'><b>Description:</b></span> {description}<br />" +"</div>";public PersonneDetailVue() {setLayout(new RowLayout());ContentPanel cp = new ContentPanel();cp.setLayout(new FlowLayout());lcDetailHaut = new LayoutContainer();lcDetailHaut.setLayout(new RowLayout());//this.add(lcDetailHaut, new RowData(1, 0.2));cp.setTopComponent(lcDetailHaut);add(lcDetailHaut);tabPanel = new TabPanel();this.add(tabPanel, new RowData(1, 1));//Constructeur de la classeRegistry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);//setLayout(new FitLayout());tabIdentite = new TabItem("Identité");tabIdentite.setLayout(new FitLayout());tabIdentite.setScrollMode(Scroll.AUTO);fsIdentite = new FieldSet();fsIdentite.setLayout(new FormLayout());fsContact = new FieldSet();fsContact.setLayout(new FormLayout());tabPanel.add(tabIdentite);//Onglet Adresse:tabAdresse = new TabItem("Adresses");fsAdressePerso = new FieldSet();fsAdressePerso.setLayout(new FormLayout());tabPanel.add(tabAdresse);//Onglet info naturalistestabInfosNat = new TabItem("Informations naturalistes");fsSpec = new FieldSet();fsSpec.setLayout(new FormLayout());tabInfosNat.setScrollMode(Scroll.AUTO);tabPanel.add(tabInfosNat);tabLogos = new TabItem("Logos");tabLogos.setLayout(new FlowLayout());tabPanel.add(tabLogos);}private HashMap hmLabelFieldRegion = new HashMap();public void afficherDetailPersonne(Personne personne) {if (personne != null) {//MAJ Identité : Configurer les fieldSetParams enteteParams = new Params();enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE);enteteParams.set("css_meta", ComposantClass.META);enteteParams.set("nom", (String) personne.get("fmt_nom_complet"));enteteParams.set("mail", (String) personne.get("courriel_princ"));LinkedList lstLogos = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_logo");if (lstLogos!=null && lstLogos.size() > 0) {tabLogos.removeAll();String urlLogoPrinc = (String) lstLogos.get(0);if (!urlLogoPrinc.trim().equals("")) {enteteTpl = "<div style='position:absolute; right:0; width:30%; text-align:right'><img src='{image}' alt='logo' height='45px'/></div>" + enteteTpl;enteteParams.set("image", urlLogoPrinc);}Iterator<String> itLogo = lstLogos.iterator();while (itLogo.hasNext()){String urlLogoCourant = itLogo.next();Image imgCourante = new Image(urlLogoCourant);tabLogos.add(imgCourante);}tabLogos.enable();} else {tabLogos.disable();}lcDetailHaut.el().setInnerHtml(Format.substitute(enteteTpl, enteteParams));Params tabIdentiteParams = new Params();tabIdentiteParams.set("nom_complet", personne.getString("fmt_nom_complet"));tabIdentiteParams.set("abreviation", personne.getString("abreviation"));tabIdentiteParams.set("naissance_date", personne.getString("naissance_date"));tabIdentiteParams.set("naissance_lieu", personne.getString("naissance_lieu"));tabIdentiteParams.set("deces_date", personne.getString("deces_date"));tabIdentiteParams.set("deces_lieu", personne.getString("deces_lieu"));tabIdentiteParams.set("description", personne.getString("description"));fsAdressePerso.removeAll();fsSpec.removeAll();tabInfosNat.removeAll();// Nom autre : champ truk; non-typéLinkedList<String> nomsAutre = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_nom_autre");String listeNoms = "";if ((nomsAutre != null)&&(nomsAutre.size() > 0)) {listeNoms = UtilTruk.traiterTrukListe(nomsAutre, ", ");}tabIdentiteParams.set("nom_autre", listeNoms);// Abréviations, autre : non-typéLinkedList<String> abrevAutres = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_abreviation_autre");String listeAbrev = "";if ((abrevAutres != null)&&(abrevAutres.size() > 0)) {listeAbrev = UtilTruk.traiterTrukListe(abrevAutres, ", ");}tabIdentiteParams.set("abreviation_autre", listeAbrev);tabIdentite.el().setInnerHtml(Format.substitute(tabIdentiteTpl, tabIdentiteParams));// CONTACT > Plusieurs téléphones possible, typésConstantes constantesI18n = (Constantes) GWT.create(Constantes.class);HashMap<String, String> mapTelephones = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_telephone");if ((mapTelephones != null)&&(mapTelephones.size() > 0)) {Collection<String> telephoneKeys = mapTelephones.keySet();Iterator<String> itTelephones = telephoneKeys.iterator();while (itTelephones.hasNext()) {String key = itTelephones.next();LabelField telephoneLabel = new LabelField();String label = "";try {label = constantesI18n.getString(key);}catch (MissingResourceException e) {label = key;}telephoneLabel.setFieldLabel( label + ":");telephoneLabel.setValue(mapTelephones.get(key));fsContact.add(telephoneLabel);}}// Fax// > Plusieurs fax possible, typésHashMap<String, String> mapFax = (HashMap<String, String>) personne.getChaineDenormaliseAsMapOrList("truk_fax");if ((mapFax != null)&&(mapFax.size() > 0)) {Collection<String> faxKeys = mapFax.keySet();Iterator<String> itFax = faxKeys.iterator();while (itFax.hasNext()) {String key = itFax.next();LabelField faxLabel = new LabelField();String label = "";try {label = constantesI18n.getString(key);}catch (MissingResourceException e) {label = key;}faxLabel.setFieldLabel( label + ":");faxLabel.setValue(mapTelephones.get(key));fsContact.add(faxLabel);}}// Courriel// Courriel est un champ truk de la forme "Adresse@adr.com;; adr2@adr.fr ..."LinkedList<String> listeCourriel = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_courriel");if ((listeCourriel!=null)&&(listeCourriel.size() > 0)) {String strLabelCourriel = "Courriel";if (listeCourriel.size() > 1) {strLabelCourriel += "s";}LabelField labelCourriel = new LabelField();labelCourriel.setFieldLabel(strLabelCourriel);String valeurCourriel = "";Iterator<String> itCourriel = listeCourriel.iterator();while (itCourriel.hasNext()) {String valeurCourante = itCourriel.next();valeurCourriel += "<a href=\"mailto:" + valeurCourante + "\">" + valeurCourante + "</a><br />";}labelCourriel.setValue(valeurCourriel);fsContact.add(labelCourriel);}// Url Site WebsLinkedList listeUrl = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_url");if (listeUrl!=null && listeUrl.size() > 0) {String strUrl = "";Iterator<String> urlIt = listeUrl.iterator();while (urlIt.hasNext()) {String urlCourante = urlIt.next();strUrl += "<a href=\""+urlCourante+"\">" + urlCourante + "</a> <br/>";}LabelField urlLabelField = new LabelField();urlLabelField.setFieldLabel("Url:");urlLabelField.setValue(strUrl);fsContact.add(urlLabelField);}tabIdentite.setStyleAttribute("padding", "15px");//tabIdentite.add(fsContact);fsAdressePerso.setHeading("Adresse personnelle");/** Adresses :* */String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");ajouterLabelField(fsAdressePerso, "Adresse", adresse01);String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");ajouterLabelField(fsAdressePerso, "", adresse02);String boitePostale = (String) personne.obtenirValeurChamp("bp");ajouterLabelField(fsAdressePerso, "Boite Postale", boitePostale);String codePostal = (String) personne.obtenirValeurChamp("code_postal");ajouterLabelField(fsAdressePerso, "Code postal", codePostal);String ville = (String) personne.obtenirValeurChamp("ville");ajouterLabelField(fsAdressePerso, "Ville", ville);String region = (String) personne.obtenirValeurChamp("region");ajouterLabelField(fsAdressePerso, "Région", region);String pays = (String) personne.obtenirValeurChamp("pays");ajouterLabelField(fsAdressePerso, "Pays", pays);fsAdressePerso.addText("<br >");fsAdressePerso.setWidth("350px");tabAdresse.add(fsAdressePerso);// Infos naturalistes// Biographie// Spécialité (typé)fsSpec.setHeading("Spécialités");tabInfosNat.add(fsSpec);HashMap hmSpecialite = (HashMap) personne.getChaineDenormaliseAsMapOrList("ce_truk_specialite");if ((hmSpecialite != null)&&(hmSpecialite.size() > 0)) {Collection<String> specialiteKeys = hmSpecialite.keySet();Iterator<String> itSpec = specialiteKeys.iterator();while (itSpec.hasNext()) {String key = itSpec.next();LabelField specLabel = new LabelField();String label = "";try {label = constantesI18n.getString(key);}catch (MissingResourceException e) {label = key;}specLabel.setFieldLabel( label + ":");specLabel.setValue(hmSpecialite.get(key));fsSpec.add(specLabel);}}// RécolteLinkedList<String> lstRecolte = (LinkedList) personne.getChaineDenormaliseAsMapOrList("truk_recolte");if ((lstRecolte!=null)&&(lstRecolte.size()>0)) {FieldSet fsRecolte = new FieldSet();fsRecolte.setHeading("Récoltes");fsRecolte.setLayout(new FormLayout());Iterator<String> itRecolte = lstRecolte.iterator();while (itRecolte.hasNext()) {String recolteCourante = itRecolte.next();LabelField lfRecolte = new LabelField();String[] splitRecolte = recolteCourante.split("\\|");String labelRecolte = "";if (splitRecolte.length > 1) {lfRecolte.setValue(splitRecolte[1]);}lfRecolte.setFieldLabel(splitRecolte[0]);fsRecolte.add(lfRecolte);LinkedList<LabelField> lstComposantsRegion = (LinkedList<LabelField>) hmLabelFieldRegion.get(splitRecolte[0]);if (lstComposantsRegion == null) {lstComposantsRegion = new LinkedList<LabelField>();}lstComposantsRegion.add(lfRecolte);hmLabelFieldRegion.remove(splitRecolte[0]);hmLabelFieldRegion.put(splitRecolte[0], lstComposantsRegion);}tabInfosNat.add(fsRecolte);}changerLabelRegions();// tabInfosNatlayout();}}private void changerLabelRegions() {Collection<String> colClesComposants = hmLabelFieldRegion.keySet();Iterator<String> itComposants = colClesComposants.iterator();while (itComposants.hasNext()) {String region = itComposants.next();mediateur.obtenirValeurEtRafraichir(this, "region", region);}}private void ajouterLabelField(FieldSet fs, String tfLabel, Object tfValue) {if ((tfValue!=null)&&(!tfValue.toString().trim().equals(""))) {LabelField tf = new LabelField();tf.setFieldLabel(tfLabel + ":");if ((tfLabel==null)||("".equals(tfLabel))) {tf.setHideLabel(true);tf.setStyleAttribute("margin", "0 0 0 105px");}tf.setValue(tfValue);//Ajout au fieldSetfs.add(tf);}}private Configuration config = (Configuration) Registry.get(RegistreId.CONFIG);public void rafraichir(Object nouvellesDonnees) {// Si on a reçu une personne on en affiche les détailsif (nouvellesDonnees instanceof Personne) {afficherDetailPersonne((Personne) nouvellesDonnees);} else if (nouvellesDonnees instanceof ValeurListe) {ValeurListe listeValeur = (ValeurListe) nouvellesDonnees;if (listeValeur.getId().equals(config.getListeId("region"))) {Collection colCleListeValeur = listeValeur.keySet();Iterator<String> itLv = colCleListeValeur.iterator();while (itLv.hasNext()) {String idRegion = itLv.next();Valeur region = listeValeur.get(idRegion);if (region != null) {String strRegionId = region.getAbreviation();LinkedList<LabelField> listComposantsRegion = (LinkedList) hmLabelFieldRegion.get(strRegionId);for (int i=0; i < listComposantsRegion.size(); i++) {LabelField lfRegion = listComposantsRegion.get(i);lfRegion.setFieldLabel(region.getNom());}}}}}}}