Rev 1044 | Rev 1322 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import org.tela_botanica.client.ComposantClass;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.RegistreId;import org.tela_botanica.client.configuration.Configuration;import org.tela_botanica.client.i18n.Constantes;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import org.tela_botanica.client.modeles.aDonnee;import org.tela_botanica.client.modeles.projet.Projet;import org.tela_botanica.client.modeles.projet.ProjetListe;import org.tela_botanica.client.util.Debug;import org.tela_botanica.client.util.UtilString;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.util.Format;import com.extjs.gxt.ui.client.util.Params;import com.extjs.gxt.ui.client.widget.HtmlContainer;import com.extjs.gxt.ui.client.widget.LayoutContainer;import com.extjs.gxt.ui.client.widget.TabItem;import com.extjs.gxt.ui.client.widget.layout.FitLayout;import com.google.gwt.core.client.GWT;public abstract class DetailVue extends LayoutContainer implements Rafraichissable {protected Mediateur mediateur = null;protected Constantes i18nC = null;protected HashMap<String, Valeur> ontologie = null;protected boolean ontologieChargementOk = false;private HashMap<Integer, String> ontologiesEnAttenteDeReception = null;protected ProjetListe projets = null;protected boolean projetsChargementOk = false;protected String sautLigneTpl = null;public DetailVue(Mediateur mediateurCourant) {mediateur = mediateurCourant;i18nC = Mediateur.i18nC;initialiserSautLigneTpl();ontologie = new HashMap<String, Valeur>();ontologieChargementOk = false;ontologiesEnAttenteDeReception = new HashMap<Integer, String>();chargerProjets();setLayout(new FitLayout());setBorders(false);setScrollMode(Scroll.AUTO);}private void initialiserSautLigneTpl() {sautLigneTpl = "<br />\n";}private void chargerProjets() {mediateur.selectionnerProjet(this, null);}protected String construireTxtProjet(String idProjet) {String chaineARetourner = idProjet;if (projets != null) {Projet projet = projets.get(idProjet);if (projet != null) {String nomDuProjet = projet.getNom();if (!nomDuProjet.equals("")) {chaineARetourner = nomDuProjet;}}}return chaineARetourner;}protected String construireTxtTruck(String chaineAAnalyser) {ArrayList<String> termes = new ArrayList<String>();if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals(""))) {String[] valeurs = chaineAAnalyser.split(aDonnee.SEPARATEUR_VALEURS);int nbreValeurs = valeurs.length;if (nbreValeurs > 0) {for (int i = 0; i < nbreValeurs; i++) {String valeur = valeurs[i];String valeurFormatee = formaterValeurTruck(valeur);termes.add(valeurFormatee);}}}String chaineARetourner = formaterTableauDeTxt(termes);return chaineARetourner;}private String formaterValeurTruck(String valeur) {String chaineARetourner = "";if (valeur.matches("^[^#]+##[^$]+$")) {String[] cleValeur = valeur.split(aDonnee.SEPARATEUR_TYPE_VALEUR);chaineARetourner = (UtilString.isEmpty(cleValeur[1]) || cleValeur[1].equals("null") ? aDonnee.VALEUR_NULL : cleValeur[1]) +" "+formaterParenthese(cleValeur[0]);} else if (!valeur.equals("")) {chaineARetourner = valeur;} else {GWT.log("Valeur truck posant problème :"+valeur, null);}return chaineARetourner;}protected String formaterParenthese(String chaineAAfficher) {if (!chaineAAfficher.equals("")) {chaineAAfficher = "("+chaineAAfficher+")";}return chaineAAfficher;}protected String formaterTableauDeTxt(ArrayList<String> tableauDeTxt) {String chaineAAfficher = "";int tailleDuTableau = tableauDeTxt.size();if (tailleDuTableau > 0) {int indexAvtDernier = tailleDuTableau - 1;for (int i = 0; i < tailleDuTableau; i++) {String mot = tableauDeTxt.get(i);if (i != indexAvtDernier) {chaineAAfficher += mot+", ";} else {chaineAAfficher += nettoyerPointFinal(mot)+".";}}}return UtilString.ucFirst(chaineAAfficher);}protected String nettoyerPointFinal(String mot) {mot = mot.replaceAll("[.]$", "");return mot;}protected String formaterContenu(String template, Params parametres) {String cHtml = Format.substitute(template, parametres);Params cssParams = new Params();cssParams.set("css_lien_ext", ComposantClass.LIEN_EXTERNE);cssParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);cssParams.set("css_label", ComposantClass.LABEL);cssParams.set("css_indentation", ComposantClass.INDENTATION);cssParams.set("css_fieldset", ComposantClass.FIELDSET);cssParams.set("css_clear", ComposantClass.CLEAR);cHtml = Format.substitute(cHtml, cssParams);return cHtml;}protected void afficherOnglet(String template, Params parametres, TabItem onglet) {String cHtml = formaterContenu(template, parametres);HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);onglet.removeAll();onglet.add(corpsConteneurDuHtml);}protected String formaterAutre(String chaineAAfficher) {if (!chaineAAfficher.equals("")) {chaineAAfficher = " ["+i18nC.autres()+" : "+chaineAAfficher+"]";}return chaineAAfficher;}protected String formaterOuiNon(String chaineAFormater) {String txtARetourner = "";if (chaineAFormater.equals("0")) {txtARetourner = i18nC.non();} else if (chaineAFormater.equals("1")) {txtARetourner = i18nC.oui();}return txtARetourner;}protected String formaterSautDeLigne(String chaineAFormater) {String txtARetourner = chaineAFormater.replaceAll("\n", sautLigneTpl);return txtARetourner;}protected void lancerChargementListesValeurs(String[] listesCodes) {Configuration configuration = (Configuration) Registry.get(RegistreId.CONFIG);for (int i = 0; i < listesCodes.length ; i++) {String code = listesCodes[i];ontologiesEnAttenteDeReception.put(configuration.getListeId(code), code);mediateur.obtenirListeValeurEtRafraichir(this, code);}}protected void receptionerListeValeurs(ValeurListe listeValeursReceptionnee) {mettreAJourOntologieEnAttenteDeReception(listeValeursReceptionnee);ajouterListeValeursAOntologie(listeValeursReceptionnee);}protected void mettreAJourOntologieEnAttenteDeReception(ValeurListe listeValeursReceptionnee) {ontologiesEnAttenteDeReception.remove(listeValeursReceptionnee.getId());if (ontologiesEnAttenteDeReception.size() == 0) {ontologieChargementOk = true;}}protected void ajouterListeValeursAOntologie(ValeurListe listeValeursReceptionnee) {Iterator<String> it = listeValeursReceptionnee.keySet().iterator();while (it.hasNext()) {String cle = it.next();Valeur valeur = listeValeursReceptionnee.get(cle);if (valeur != null) {ontologie.put(cle, valeur);}}}public String construireTxtListeOntologie(String chaineAAnalyser) {return construireTxtListeOntologie(chaineAAnalyser, true, true, false);}public String construireTxtListeOntologie(String chaineAAnalyser, boolean valeurEstOntologie, boolean typeEstOntologie, boolean donneeEstOntologie) {ArrayList<String> termes = new ArrayList<String>();ArrayList<String> autres = new ArrayList<String>();chaineAAnalyser = chaineAAnalyser.trim();if (!UtilString.isEmpty(chaineAAnalyser)) {String[] valeurs = chaineAAnalyser.split(aDonnee.SEPARATEUR_VALEURS);int nbreValeurs = valeurs.length;if (nbreValeurs > 0) {for (int i = 0; i < nbreValeurs; i++) {String valeur = valeurs[i];// VALEUR SANS TYPE// La valeur sans type est une entrée de l'ontologieif (valeurEstOntologie && valeur.matches("^[0-9]+$")) {if (valeur.equals("0")) {valeur = "";} else if (ontologie != null) {Valeur valeurOntologie = ontologie.get(valeur);if (valeurOntologie != null) {valeur = valeurOntologie.getNom();}}}// VALEUR AVEC TYPE// Type : AUTREString valeurTypeAutre = aDonnee.TYPE_AUTRE+aDonnee.SEPARATEUR_TYPE_VALEUR;if (valeur.matches("^"+valeurTypeAutre+".+$")) {String txtAutre = valeur.replaceFirst("^"+valeurTypeAutre, "");if (!txtAutre.equals("")) {autres.add(txtAutre);}valeur = "";}// Type correspondant à une entrée de l'ontologieif (typeEstOntologie) {String valeurTypeOntologie = "[0-9]+"+aDonnee.SEPARATEUR_TYPE_VALEUR;if (valeur.matches("^"+valeurTypeOntologie+".+$")) {String type = valeur.substring(0, valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR));if (ontologie != null && ontologie.get(type) != null) {Valeur valeurOntologie = ontologie.get(type);valeur = valeur.replaceFirst("^"+type, valeurOntologie.getNom()+": ");}}}// Donnée correspondant à une entrée de l'ontologieif (donneeEstOntologie) {String donneeOntologie = aDonnee.SEPARATEUR_TYPE_VALEUR+"[0-9]+";if (valeur.matches("^.+"+donneeOntologie+"$")) {String donnee = valeur.substring(valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR), valeur.length());donnee = donnee.replaceFirst("^"+aDonnee.SEPARATEUR_TYPE_VALEUR, "");if (ontologie != null && ontologie.get(donnee) != null) {Valeur valeurOntologie = ontologie.get(donnee);valeur = valeur.replaceFirst(donnee+"$", valeurOntologie.getNom());}}}// Nettoyage finalvaleur = valeur.replaceFirst(aDonnee.SEPARATEUR_TYPE_VALEUR, "");if (!UtilString.isEmpty(valeur)) {termes.add(valeur);}}}}String chaineTermes = formaterTableauDeTxt(termes);String chaineAutres = formaterTableauDeTxt(autres);String chaineARetourner = chaineTermes+formaterAutre(chaineAutres);return chaineARetourner;}}