Subversion Repositories eFlore/Applications.coel

Rev

Rev 1818 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
936 jpm 1
package org.tela_botanica.client.vues;
453 jp_milcent 2
 
3
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.Iterator;
6
 
7
import org.tela_botanica.client.ComposantClass;
8
import org.tela_botanica.client.Mediateur;
813 jpm 9
import org.tela_botanica.client.RegistreId;
907 jpm 10
import org.tela_botanica.client.configuration.Configuration;
453 jp_milcent 11
import org.tela_botanica.client.i18n.Constantes;
12
import org.tela_botanica.client.interfaces.Rafraichissable;
13
import org.tela_botanica.client.modeles.Valeur;
14
import org.tela_botanica.client.modeles.ValeurListe;
961 jpm 15
import org.tela_botanica.client.modeles.aDonnee;
1322 gduche 16
import org.tela_botanica.client.synchronisation.Sequenceur;
1818 mathias 17
import org.tela_botanica.client.util.Analytics;
967 jpm 18
import org.tela_botanica.client.util.Debug;
819 gduche 19
import org.tela_botanica.client.util.UtilString;
453 jp_milcent 20
 
813 jpm 21
import com.extjs.gxt.ui.client.Registry;
453 jp_milcent 22
import com.extjs.gxt.ui.client.Style.Scroll;
23
import com.extjs.gxt.ui.client.util.Format;
24
import com.extjs.gxt.ui.client.util.Params;
25
import com.extjs.gxt.ui.client.widget.HtmlContainer;
26
import com.extjs.gxt.ui.client.widget.LayoutContainer;
27
import com.extjs.gxt.ui.client.widget.TabItem;
28
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
29
import com.google.gwt.core.client.GWT;
30
 
31
public abstract class DetailVue extends LayoutContainer implements Rafraichissable {
32
 
33
	protected Mediateur mediateur = null;
34
	protected Constantes i18nC = null;
35
 
36
	protected HashMap<String, Valeur> ontologie = null;
813 jpm 37
	protected boolean ontologieChargementOk = false;
38
	private HashMap<Integer, String> ontologiesEnAttenteDeReception = null;
39
 
453 jp_milcent 40
	protected String sautLigneTpl = null;
41
 
42
	public DetailVue(Mediateur mediateurCourant) {
43
		mediateur = mediateurCourant;
602 jp_milcent 44
		i18nC = Mediateur.i18nC;
453 jp_milcent 45
 
46
		initialiserSautLigneTpl();
47
 
48
		ontologie = new HashMap<String, Valeur>();
813 jpm 49
		ontologieChargementOk = false;
50
		ontologiesEnAttenteDeReception = new HashMap<Integer, String>();
453 jp_milcent 51
 
52
		setLayout(new FitLayout());
53
		setBorders(false);
54
		setScrollMode(Scroll.AUTO);
55
	}
56
 
57
	private void initialiserSautLigneTpl() {
58
		sautLigneTpl = "<br />\n";
59
	}
813 jpm 60
 
453 jp_milcent 61
	protected String construireTxtTruck(String chaineAAnalyser) {
1369 cyprien 62
		return construireTxtTruck(chaineAAnalyser, true);
63
	}
64
 
65
	protected String construireTxtTruck(String chaineAAnalyser, boolean ucFirst) {
453 jp_milcent 66
		ArrayList<String> termes = new ArrayList<String>();
67
 
68
		if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals("")))	{
961 jpm 69
			String[] valeurs = chaineAAnalyser.split(aDonnee.SEPARATEUR_VALEURS);
453 jp_milcent 70
			int nbreValeurs = valeurs.length;
71
			if (nbreValeurs > 0)	{
72
				for (int i = 0; i < nbreValeurs; i++)	{
73
					String valeur = valeurs[i];
74
					String valeurFormatee = formaterValeurTruck(valeur);
75
					termes.add(valeurFormatee);
76
				}
77
			}
78
		}
79
 
1369 cyprien 80
		String chaineARetourner = formaterTableauDeTxt(termes, ucFirst);
453 jp_milcent 81
		return chaineARetourner;
82
	}
83
 
84
	private String formaterValeurTruck(String valeur) {
85
		String chaineARetourner = "";
86
 
87
		if (valeur.matches("^[^#]+##[^$]+$"))	{
961 jpm 88
			String[] cleValeur = valeur.split(aDonnee.SEPARATEUR_TYPE_VALEUR);
1044 gduche 89
			chaineARetourner = (UtilString.isEmpty(cleValeur[1]) || cleValeur[1].equals("null") ? aDonnee.VALEUR_NULL : cleValeur[1]) +" "+formaterParenthese(cleValeur[0]);
453 jp_milcent 90
		} else if (!valeur.equals(""))	{
91
			chaineARetourner = valeur;
92
		} else {
961 jpm 93
			GWT.log("Valeur truck posant problème :"+valeur, null);
453 jp_milcent 94
		}
95
 
96
		return chaineARetourner;
97
	}
98
 
99
	protected String formaterParenthese(String chaineAAfficher) {
100
		if (!chaineAAfficher.equals("")) {
101
			chaineAAfficher = "("+chaineAAfficher+")";
102
		}
103
		return chaineAAfficher;
104
	}
105
 
1369 cyprien 106
	protected String formaterTableauDeTxt(ArrayList<String> tableauDeTxt, boolean ucFirst) {
453 jp_milcent 107
		String chaineAAfficher = "";
108
		int tailleDuTableau = tableauDeTxt.size();
109
		if (tailleDuTableau > 0) {
110
			int indexAvtDernier = tailleDuTableau - 1;
111
			for (int i = 0; i < tailleDuTableau; i++)	{
112
				String mot = tableauDeTxt.get(i);
113
				if (i != indexAvtDernier) {
114
					chaineAAfficher += mot+", ";
115
				} else {
116
					chaineAAfficher += nettoyerPointFinal(mot)+".";
117
				}
118
			}
119
		}
1369 cyprien 120
		if (ucFirst) return UtilString.ucFirst(chaineAAfficher);
121
		else return chaineAAfficher;
453 jp_milcent 122
	}
123
 
124
	protected String nettoyerPointFinal(String mot) {
125
		mot = mot.replaceAll("[.]$", "");
126
		return mot;
127
	}
128
 
803 jpm 129
	protected String formaterContenu(String template, Params parametres) {
453 jp_milcent 130
		String cHtml = Format.substitute(template, parametres);
131
 
132
		Params cssParams = new Params();
1121 jpm 133
		cssParams.set("css_lien_ext", ComposantClass.LIEN_EXTERNE);
453 jp_milcent 134
		cssParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
135
		cssParams.set("css_label", ComposantClass.LABEL);
136
		cssParams.set("css_indentation", ComposantClass.INDENTATION);
137
		cssParams.set("css_fieldset", ComposantClass.FIELDSET);
138
		cssParams.set("css_clear", ComposantClass.CLEAR);
139
		cHtml = Format.substitute(cHtml, cssParams);
140
 
803 jpm 141
		return cHtml;
142
	}
143
 
144
	protected void afficherOnglet(String template, Params parametres, TabItem onglet) {
145
		String cHtml = formaterContenu(template, parametres);
146
 
453 jp_milcent 147
		HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
148
		onglet.removeAll();
149
		onglet.add(corpsConteneurDuHtml);
150
	}
151
 
152
	protected String formaterAutre(String chaineAAfficher) {
153
		if (!chaineAAfficher.equals("")) {
154
			chaineAAfficher = " ["+i18nC.autres()+" : "+chaineAAfficher+"]";
155
		}
156
		return chaineAAfficher;
157
	}
158
 
159
	protected String formaterOuiNon(String chaineAFormater) {
160
		String txtARetourner = "";
161
		if (chaineAFormater.equals("0")) {
162
			txtARetourner = i18nC.non();
163
		} else if (chaineAFormater.equals("1")) {
164
			txtARetourner = i18nC.oui();
165
		}
166
		return txtARetourner;
167
	}
1693 raphael 168
 
169
	protected String formaterOuiNon(Integer intAFormater) {
170
		if(intAFormater == null) return "";
171
		if(intAFormater.intValue() == 0) return i18nC.non();
172
		if(intAFormater.intValue() == 1) return i18nC.oui();
173
		return "";
174
	}
453 jp_milcent 175
 
176
	protected String formaterSautDeLigne(String chaineAFormater) {
177
		String txtARetourner = chaineAFormater.replaceAll("\n", sautLigneTpl);
178
		return txtARetourner;
179
	}
180
 
813 jpm 181
	protected void lancerChargementListesValeurs(String[] listesCodes) {
1322 gduche 182
		lancerChargementListesValeurs(listesCodes, null);
183
	}
184
	protected void lancerChargementListesValeurs(String[] listesCodes, Sequenceur sequenceur) {
813 jpm 185
		Configuration configuration = (Configuration) Registry.get(RegistreId.CONFIG);
186
		for (int i = 0; i < listesCodes.length ; i++) {
187
			String code = listesCodes[i];
188
			ontologiesEnAttenteDeReception.put(configuration.getListeId(code), code);
1322 gduche 189
			mediateur.obtenirListeValeurEtRafraichir(this, code, sequenceur);
813 jpm 190
		}
191
	}
192
 
816 jpm 193
	protected void receptionerListeValeurs(ValeurListe listeValeursReceptionnee) {
813 jpm 194
		mettreAJourOntologieEnAttenteDeReception(listeValeursReceptionnee);
195
		ajouterListeValeursAOntologie(listeValeursReceptionnee);
196
	}
197
 
198
	protected void mettreAJourOntologieEnAttenteDeReception(ValeurListe listeValeursReceptionnee) {
199
		ontologiesEnAttenteDeReception.remove(listeValeursReceptionnee.getId());
200
	}
201
 
202
	protected void ajouterListeValeursAOntologie(ValeurListe listeValeursReceptionnee) {
203
		Iterator<String> it = listeValeursReceptionnee.keySet().iterator();
453 jp_milcent 204
		while (it.hasNext()) {
205
			String cle = it.next();
813 jpm 206
			Valeur valeur = listeValeursReceptionnee.get(cle);
453 jp_milcent 207
			if (valeur != null) {
208
				ontologie.put(cle, valeur);
209
			}
210
		}
211
	}
524 gduche 212
 
936 jpm 213
	public String construireTxtListeOntologie(String chaineAAnalyser) {
967 jpm 214
		return construireTxtListeOntologie(chaineAAnalyser, true, true, false);
215
	}
216
 
217
	public String construireTxtListeOntologie(String chaineAAnalyser, boolean valeurEstOntologie, boolean typeEstOntologie, boolean donneeEstOntologie) {
524 gduche 218
		ArrayList<String> termes = new ArrayList<String>();
219
		ArrayList<String> autres = new ArrayList<String>();
1028 jpm 220
		chaineAAnalyser = chaineAAnalyser.trim();
221
		if (!UtilString.isEmpty(chaineAAnalyser)) {
961 jpm 222
			String[] valeurs = chaineAAnalyser.split(aDonnee.SEPARATEUR_VALEURS);
524 gduche 223
			int nbreValeurs = valeurs.length;
224
			if (nbreValeurs > 0)	{
225
				for (int i = 0; i < nbreValeurs; i++)	{
967 jpm 226
					String valeur = valeurs[i];
227
					// VALEUR SANS TYPE
228
					// La valeur sans type est une entrée de l'ontologie
229
					if (valeurEstOntologie && valeur.matches("^[0-9]+$"))	{
230
						if (valeur.equals("0")) {
231
							valeur = "";
232
						} else if (ontologie != null) {
1322 gduche 233
 
967 jpm 234
							Valeur valeurOntologie = ontologie.get(valeur);
235
							if (valeurOntologie != null) {
236
								valeur = valeurOntologie.getNom();
819 gduche 237
							}
524 gduche 238
						}
1322 gduche 239
 
967 jpm 240
					}
241
 
242
					// VALEUR AVEC TYPE
243
					// Type : AUTRE
244
					String valeurTypeAutre = aDonnee.TYPE_AUTRE+aDonnee.SEPARATEUR_TYPE_VALEUR;
1329 cyprien 245
					if (valeur.matches("^"+valeurTypeAutre+".*$")) {
967 jpm 246
						String txtAutre = valeur.replaceFirst("^"+valeurTypeAutre, "");
247
						if (!txtAutre.equals("")) {
248
							autres.add(txtAutre);
249
						}
250
						valeur = "";
251
					}
252
					// Type correspondant à une entrée de l'ontologie
253
					if (typeEstOntologie) {
254
						String valeurTypeOntologie = "[0-9]+"+aDonnee.SEPARATEUR_TYPE_VALEUR;
255
						if (valeur.matches("^"+valeurTypeOntologie+".+$")) {
256
							String type = valeur.substring(0, valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR));
257
							if (ontologie != null && ontologie.get(type) != null) {
258
								Valeur valeurOntologie = ontologie.get(type);
259
								valeur = valeur.replaceFirst("^"+type, valeurOntologie.getNom()+": ");
524 gduche 260
							}
261
						}
262
					}
967 jpm 263
					// Donnée correspondant à une entrée de l'ontologie
264
					if (donneeEstOntologie) {
265
						String donneeOntologie = aDonnee.SEPARATEUR_TYPE_VALEUR+"[0-9]+";
266
						if (valeur.matches("^.+"+donneeOntologie+"$")) {
267
							String donnee = valeur.substring(valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR), valeur.length());
268
							donnee = donnee.replaceFirst("^"+aDonnee.SEPARATEUR_TYPE_VALEUR, "");
269
							if (ontologie != null && ontologie.get(donnee) != null) {
270
								Valeur valeurOntologie = ontologie.get(donnee);
271
								valeur = valeur.replaceFirst(donnee+"$", valeurOntologie.getNom());
272
							}
273
						}
274
					}
275
 
276
					// Nettoyage final
277
					valeur = valeur.replaceFirst(aDonnee.SEPARATEUR_TYPE_VALEUR, "");
278
 
279
					if (!UtilString.isEmpty(valeur)) {
280
						termes.add(valeur);
281
					}
524 gduche 282
				}
283
			}
284
		}
285
 
1369 cyprien 286
		String chaineTermes = formaterTableauDeTxt(termes, true);
287
		String chaineAutres = formaterTableauDeTxt(autres, true);
524 gduche 288
		String chaineARetourner = chaineTermes+formaterAutre(chaineAutres);
289
 
290
		return chaineARetourner;
291
	}
1693 raphael 292
}