Subversion Repositories eFlore/Applications.coel

Rev

Rev 961 | Rev 1028 | 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);
453 jp_milcent 109
			chaineARetourner = cleValeur[1]+" "+formaterParenthese(cleValeur[0]);
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();
152
		cssParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
153
		cssParams.set("css_label", ComposantClass.LABEL);
154
		cssParams.set("css_indentation", ComposantClass.INDENTATION);
155
		cssParams.set("css_fieldset", ComposantClass.FIELDSET);
156
		cssParams.set("css_clear", ComposantClass.CLEAR);
157
		cHtml = Format.substitute(cHtml, cssParams);
158
 
803 jpm 159
		return cHtml;
160
	}
161
 
162
	protected void afficherOnglet(String template, Params parametres, TabItem onglet) {
163
		String cHtml = formaterContenu(template, parametres);
164
 
453 jp_milcent 165
		HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
166
		onglet.removeAll();
167
		onglet.add(corpsConteneurDuHtml);
168
	}
169
 
170
	protected String formaterAutre(String chaineAAfficher) {
171
		if (!chaineAAfficher.equals("")) {
172
			chaineAAfficher = " ["+i18nC.autres()+" : "+chaineAAfficher+"]";
173
		}
174
		return chaineAAfficher;
175
	}
176
 
177
	protected String formaterOuiNon(String chaineAFormater) {
178
		String txtARetourner = "";
179
		if (chaineAFormater.equals("0")) {
180
			txtARetourner = i18nC.non();
181
		} else if (chaineAFormater.equals("1")) {
182
			txtARetourner = i18nC.oui();
183
		}
184
		return txtARetourner;
185
	}
186
 
187
	protected String formaterSautDeLigne(String chaineAFormater) {
188
		String txtARetourner = chaineAFormater.replaceAll("\n", sautLigneTpl);
189
		return txtARetourner;
190
	}
191
 
813 jpm 192
	protected void lancerChargementListesValeurs(String[] listesCodes) {
193
		Configuration configuration = (Configuration) Registry.get(RegistreId.CONFIG);
194
		for (int i = 0; i < listesCodes.length ; i++) {
195
			String code = listesCodes[i];
196
			ontologiesEnAttenteDeReception.put(configuration.getListeId(code), code);
197
			mediateur.obtenirListeValeurEtRafraichir(this, code);
198
		}
199
	}
200
 
816 jpm 201
	protected void receptionerListeValeurs(ValeurListe listeValeursReceptionnee) {
813 jpm 202
		mettreAJourOntologieEnAttenteDeReception(listeValeursReceptionnee);
203
		ajouterListeValeursAOntologie(listeValeursReceptionnee);
204
	}
205
 
206
	protected void mettreAJourOntologieEnAttenteDeReception(ValeurListe listeValeursReceptionnee) {
207
		ontologiesEnAttenteDeReception.remove(listeValeursReceptionnee.getId());
208
		if (ontologiesEnAttenteDeReception.size() == 0) {
209
			ontologieChargementOk = true;
210
		}
211
	}
212
 
213
	protected void ajouterListeValeursAOntologie(ValeurListe listeValeursReceptionnee) {
214
		Iterator<String> it = listeValeursReceptionnee.keySet().iterator();
453 jp_milcent 215
		while (it.hasNext()) {
216
			String cle = it.next();
813 jpm 217
			Valeur valeur = listeValeursReceptionnee.get(cle);
453 jp_milcent 218
			if (valeur != null) {
219
				ontologie.put(cle, valeur);
220
			}
221
		}
222
	}
524 gduche 223
 
936 jpm 224
	public String construireTxtListeOntologie(String chaineAAnalyser) {
967 jpm 225
		return construireTxtListeOntologie(chaineAAnalyser, true, true, false);
226
	}
227
 
228
	public String construireTxtListeOntologie(String chaineAAnalyser, boolean valeurEstOntologie, boolean typeEstOntologie, boolean donneeEstOntologie) {
524 gduche 229
		ArrayList<String> termes = new ArrayList<String>();
230
		ArrayList<String> autres = new ArrayList<String>();
231
		if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals("")))	{
961 jpm 232
			String[] valeurs = chaineAAnalyser.split(aDonnee.SEPARATEUR_VALEURS);
524 gduche 233
			int nbreValeurs = valeurs.length;
234
			if (nbreValeurs > 0)	{
235
				for (int i = 0; i < nbreValeurs; i++)	{
967 jpm 236
					String valeur = valeurs[i];
237
 
238
					// VALEUR SANS TYPE
239
					// La valeur sans type est une entrée de l'ontologie
240
					if (valeurEstOntologie && valeur.matches("^[0-9]+$"))	{
241
						if (valeur.equals("0")) {
242
							valeur = "";
243
						} else if (ontologie != null) {
244
							Valeur valeurOntologie = ontologie.get(valeur);
245
							if (valeurOntologie != null) {
246
								valeur = valeurOntologie.getNom();
819 gduche 247
							}
524 gduche 248
						}
967 jpm 249
					}
250
 
251
					// VALEUR AVEC TYPE
252
					// Type : AUTRE
253
					String valeurTypeAutre = aDonnee.TYPE_AUTRE+aDonnee.SEPARATEUR_TYPE_VALEUR;
254
					if (valeur.matches("^"+valeurTypeAutre+".+$")) {
255
						String txtAutre = valeur.replaceFirst("^"+valeurTypeAutre, "");
256
						if (!txtAutre.equals("")) {
257
							autres.add(txtAutre);
258
						}
259
						valeur = "";
260
					}
261
					// Type correspondant à une entrée de l'ontologie
262
					if (typeEstOntologie) {
263
						String valeurTypeOntologie = "[0-9]+"+aDonnee.SEPARATEUR_TYPE_VALEUR;
264
						if (valeur.matches("^"+valeurTypeOntologie+".+$")) {
265
							String type = valeur.substring(0, valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR));
266
							if (ontologie != null && ontologie.get(type) != null) {
267
								Valeur valeurOntologie = ontologie.get(type);
268
								valeur = valeur.replaceFirst("^"+type, valeurOntologie.getNom()+": ");
524 gduche 269
							}
270
						}
271
					}
967 jpm 272
					// Donnée correspondant à une entrée de l'ontologie
273
					if (donneeEstOntologie) {
274
						String donneeOntologie = aDonnee.SEPARATEUR_TYPE_VALEUR+"[0-9]+";
275
						if (valeur.matches("^.+"+donneeOntologie+"$")) {
276
							String donnee = valeur.substring(valeur.indexOf(aDonnee.SEPARATEUR_TYPE_VALEUR), valeur.length());
277
							donnee = donnee.replaceFirst("^"+aDonnee.SEPARATEUR_TYPE_VALEUR, "");
278
							if (ontologie != null && ontologie.get(donnee) != null) {
279
								Valeur valeurOntologie = ontologie.get(donnee);
280
								valeur = valeur.replaceFirst(donnee+"$", valeurOntologie.getNom());
281
							}
282
						}
283
					}
284
 
285
					// Nettoyage final
286
					valeur = valeur.replaceFirst(aDonnee.SEPARATEUR_TYPE_VALEUR, "");
287
 
288
					if (!UtilString.isEmpty(valeur)) {
289
						termes.add(valeur);
290
					}
524 gduche 291
				}
292
			}
293
		}
294
 
295
		String chaineTermes = formaterTableauDeTxt(termes);
296
		String chaineAutres = formaterTableauDeTxt(autres);
297
		String chaineARetourner = chaineTermes+formaterAutre(chaineAutres);
298
 
299
		return chaineARetourner;
300
	}
453 jp_milcent 301
}