Rev 247 | Rev 259 | Go to most recent revision | Blame | Compare with Previous | 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.RegistreId;import org.tela_botanica.client.i18n.Constantes;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Personne;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.Style.HorizontalAlignment;import com.extjs.gxt.ui.client.Style.LayoutRegion;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.Style.VerticalAlignment;import com.extjs.gxt.ui.client.event.ComponentEvent;import com.extjs.gxt.ui.client.event.KeyListener;import com.extjs.gxt.ui.client.widget.ContentPanel;import com.extjs.gxt.ui.client.widget.TabItem;import com.extjs.gxt.ui.client.widget.TabPanel;import com.extjs.gxt.ui.client.widget.form.Field;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.form.TextArea;import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;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.LayoutData;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.user.client.Window;import com.google.gwt.user.client.ui.Image;public class PersonneDetailPanneauVue extends TabPanel implements Rafraichissable {// Le panneau détail se compose de formulaires tabulés// Onglet 1 : identite & contactprivate TabItem tabIdentite;private ContentPanel panneauIdentite;private ContentPanel panneauImage;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;// > Se baser sur la présentation thunderBirdpublic PersonneDetailPanneauVue() {//Constructeur de la classeRegistry.register(RegistreId.PANNEAU_PERSONNE_DETAIL, this);setLayout(new FitLayout());tabIdentite = new TabItem("Identité");TableLayout tLayout = new TableLayout(2);tabIdentite.setLayout(tLayout);tabIdentite.setScrollMode(Scroll.AUTO);panneauIdentite = new ContentPanel();panneauIdentite.setWidth("400px");panneauIdentite.setHeaderVisible(false);panneauIdentite.setBorders(false);panneauIdentite.setBodyBorder(false);panneauImage = new ContentPanel();panneauImage.setLayout(new FlowLayout());panneauImage.setBorders(false);panneauImage.setWidth(350);panneauImage.setBodyBorder(false);panneauImage.setHeaderVisible(false);panneauImage.setStyleName("conteneur-image-centre");tabIdentite.add(panneauIdentite);TableData td = new TableData();tabIdentite.add(panneauImage, td);td.setVerticalAlign(VerticalAlignment.TOP);fsIdentite = new FieldSet();fsIdentite.setLayout(new FormLayout());fsContact = new FieldSet();fsContact.setLayout(new FormLayout());this.add(tabIdentite);//Onglet Adresse:tabAdresse = new TabItem("Adresse");fsAdressePerso = new FieldSet();fsAdressePerso.setLayout(new FormLayout());this.add(tabAdresse);//Onglet info naturalistestabInfosNat = new TabItem("Informations naturalistes");this.add(tabInfosNat);}public void afficherDetailPersonne(Personne personne) {if (personne != null) {//MAJ Identité : Configurer les fieldSetpanneauIdentite.removeAll();panneauImage.removeAll();fsIdentite.setHeading("Identité");fsIdentite.setWidth("350px");fsContact.setHeading("Contact");fsContact.setWidth("350px");panneauIdentite.add(fsIdentite);//La personne peut avoir un ou plusieurs logopanneauImage.setHeight("100%");LinkedList<String> listeLogos = (LinkedList<String>) personne.getChaineDenormaliseAsMapOrList("truk_logo");if ((listeLogos != null)&&(listeLogos.size() > 0)) {for (int i = 0; i < listeLogos.size(); i++) {String logoUrl = listeLogos.get(i);if ((logoUrl!=null)&&(!logoUrl.trim().equals(""))) {//Si c'est le cas, on l'affiche sur la même ligne que fsIdentitéImage img = new Image();img.setUrl(logoUrl);panneauImage.add(img);if (panneauImage.getWidth() < (img.getWidth() + 15)) {panneauImage.setWidth(img.getWidth() + 15);}}}}panneauIdentite.add(fsContact);fsIdentite.removeAll();fsContact.removeAll();fsAdressePerso.removeAll();//Ajout des champs Identité// TODO: projet// nom completObject nomComplet = personne.obtenirValeurChamp("fmt_nom_complet");ajouterTextFieldNonEditable(fsIdentite,"Nom Complet", nomComplet);// TODO : nom autre// abreviationObject abreviation = personne.obtenirValeurChamp("abreviation");ajouterTextFieldNonEditable(fsIdentite, "Abreviation", abreviation);// date naissanceObject dateNaissance = personne.obtenirValeurChamp("date_naissance");ajouterTextFieldNonEditable(fsIdentite, "Date de naissance", dateNaissance);// lieu naissanceObject lieuNaissance = personne.obtenirValeurChamp("lieu_naissance");ajouterTextFieldNonEditable(fsIdentite, "Lieu de naissance", lieuNaissance);// date decesObject dateDeces = personne.obtenirValeurChamp("date_deces");ajouterTextFieldNonEditable(fsIdentite, "Date de décès", dateDeces);// lieu decesObject lieuDeces = personne.obtenirValeurChamp("lieu_deces");ajouterTextFieldNonEditable(fsIdentite, "Lieu de décès", lieuDeces);//DescriptionString description = (String) personne.obtenirValeurChamp("description");if ((description!=null)&&(!description.trim().equals(""))) {LabelField txtDescription = new LabelField();txtDescription.setFieldLabel("Description:");txtDescription.setValue(description);//rendreNonEditable(txtDescription);fsIdentite.add(txtDescription);}// CONTACT// Téléphones// > 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);}panneauIdentite.add(fsContact);fsAdressePerso.setHeading("Adresse personnelle");/** Adresses :* */String adresse01 = (String) personne.obtenirValeurChamp("adresse_01");ajouterTextFieldNonEditable(fsAdressePerso, "Adresse", adresse01);String adresse02 = (String) personne.obtenirValeurChamp("adresse_02");ajouterTextFieldNonEditable(fsAdressePerso, "", adresse02);String boitePostale = (String) personne.obtenirValeurChamp("bp");ajouterTextFieldNonEditable(fsAdressePerso, "Boite Postale", boitePostale);String codePostal = (String) personne.obtenirValeurChamp("code_postal");ajouterTextFieldNonEditable(fsAdressePerso, "Code postal", codePostal);String ville = (String) personne.obtenirValeurChamp("ville");ajouterTextFieldNonEditable(fsAdressePerso, "Ville", ville);String region = (String) personne.obtenirValeurChamp("region");ajouterTextFieldNonEditable(fsAdressePerso, "Région", region);String pays = (String) personne.obtenirValeurChamp("pays");ajouterTextFieldNonEditable(fsAdressePerso, "Pays", pays);fsAdressePerso.addText("<br >");fsAdressePerso.setWidth("350px");tabAdresse.add(fsAdressePerso);tabAdresse.setScrollMode(Scroll.AUTO);layout();}}private void ajouterTextFieldNonEditable(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);// Non éditable : on empêche l'évènement par défaut// > MAJ 27/07 : inutile avec LabelField//rendreNonEditable(tf);//Ajout au fieldSetfs.add(tf);}}/** private void rendreNonEditable(Field field) {field.addKeyListener(new KeyListener() {public void componentKeyPress(ComponentEvent ev) {ev.stopEvent();}});}*/public void rafraichir(Object nouvelleDonnees) {// Si on a reçu une personne on en affiche les détailsif (nouvelleDonnees instanceof Personne) {afficherDetailPersonne((Personne) nouvelleDonnees);}}}