Subversion Repositories eFlore/Applications.coel

Rev

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