Subversion Repositories eFlore/Applications.coel

Rev

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