Subversion Repositories eFlore/Applications.coel

Rev

Rev 813 | Rev 819 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
453 jp_milcent 1
package org.tela_botanica.client.vues;
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;
453 jp_milcent 10
import org.tela_botanica.client.i18n.Constantes;
11
import org.tela_botanica.client.interfaces.Rafraichissable;
813 jpm 12
import org.tela_botanica.client.modeles.Configuration;
453 jp_milcent 13
import org.tela_botanica.client.modeles.Projet;
14
import org.tela_botanica.client.modeles.ProjetListe;
15
import org.tela_botanica.client.modeles.Valeur;
16
import org.tela_botanica.client.modeles.ValeurListe;
17
 
813 jpm 18
import com.extjs.gxt.ui.client.Registry;
453 jp_milcent 19
import com.extjs.gxt.ui.client.Style.Scroll;
20
import com.extjs.gxt.ui.client.util.Format;
21
import com.extjs.gxt.ui.client.util.Params;
22
import com.extjs.gxt.ui.client.widget.HtmlContainer;
23
import com.extjs.gxt.ui.client.widget.LayoutContainer;
24
import com.extjs.gxt.ui.client.widget.TabItem;
25
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
26
import com.google.gwt.core.client.GWT;
27
 
28
public abstract class DetailVue extends LayoutContainer implements Rafraichissable {
29
 
30
	protected Mediateur mediateur = null;
31
	protected Constantes i18nC = null;
32
 
33
	protected HashMap<String, Valeur> ontologie = null;
813 jpm 34
	protected boolean ontologieChargementOk = false;
35
	private HashMap<Integer, String> ontologiesEnAttenteDeReception = null;
36
 
453 jp_milcent 37
	protected ProjetListe projets = null;
813 jpm 38
	protected boolean projetsChargementOk = false;
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>();
51
		chargerProjets();
453 jp_milcent 52
 
53
		setLayout(new FitLayout());
54
		setBorders(false);
55
		setScrollMode(Scroll.AUTO);
56
	}
57
 
58
	private void initialiserSautLigneTpl() {
59
		sautLigneTpl = "<br />\n";
60
	}
61
 
813 jpm 62
	private void chargerProjets() {
453 jp_milcent 63
		mediateur.selectionnerProjets(this);
64
	}
813 jpm 65
 
453 jp_milcent 66
	protected String construireTxtProjet(String idProjet) {
67
		String chaineARetourner = idProjet;
68
 
69
		if (projets != null) {
70
			Projet projet = projets.get(idProjet);
813 jpm 71
			if (projet != null) {
72
				String nomDuProjet = projet.getNom();
73
				if  (!nomDuProjet.equals("")) {
74
					chaineARetourner = nomDuProjet;
75
				}
453 jp_milcent 76
			}
77
		}
78
 
79
		return chaineARetourner;
80
	}
81
 
82
	protected String construireTxtTruck(String chaineAAnalyser) {
83
		ArrayList<String> termes = new ArrayList<String>();
84
 
85
		if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals("")))	{
86
			String[] valeurs = chaineAAnalyser.split(";;");
87
			int nbreValeurs = valeurs.length;
88
			if (nbreValeurs > 0)	{
89
				for (int i = 0; i < nbreValeurs; i++)	{
90
					String valeur = valeurs[i];
91
					String valeurFormatee = formaterValeurTruck(valeur);
92
					termes.add(valeurFormatee);
93
				}
94
			}
95
		}
96
 
97
		String chaineARetourner = formaterTableauDeTxt(termes);
98
		return chaineARetourner;
99
	}
100
 
101
	private String formaterValeurTruck(String valeur) {
102
		String chaineARetourner = "";
103
 
104
		if (valeur.matches("^[^#]+##[^$]+$"))	{
105
			String[] cleValeur = valeur.split("##");
106
			chaineARetourner = cleValeur[1]+" "+formaterParenthese(cleValeur[0]);
107
		} else if (!valeur.equals(""))	{
108
			chaineARetourner = valeur;
109
		} else {
110
			GWT.log("Valeur truck posant problèlme :"+valeur, null);
111
		}
112
 
113
		return chaineARetourner;
114
	}
115
 
116
	protected String formaterParenthese(String chaineAAfficher) {
117
		if (!chaineAAfficher.equals("")) {
118
			chaineAAfficher = "("+chaineAAfficher+")";
119
		}
120
		return chaineAAfficher;
121
	}
122
 
123
	protected String formaterTableauDeTxt(ArrayList<String> tableauDeTxt) {
124
		String chaineAAfficher = "";
125
		int tailleDuTableau = tableauDeTxt.size();
126
		if (tailleDuTableau > 0) {
127
			int indexAvtDernier = tailleDuTableau - 1;
128
			for (int i = 0; i < tailleDuTableau; i++)	{
129
				String mot = tableauDeTxt.get(i);
130
				if (i != indexAvtDernier) {
131
					chaineAAfficher += mot+", ";
132
				} else {
133
					chaineAAfficher += nettoyerPointFinal(mot)+".";
134
				}
135
			}
136
		}
137
		return chaineAAfficher;
138
	}
139
 
140
	protected String nettoyerPointFinal(String mot) {
141
		mot = mot.replaceAll("[.]$", "");
142
		return mot;
143
	}
144
 
803 jpm 145
	protected String formaterContenu(String template, Params parametres) {
453 jp_milcent 146
		String cHtml = Format.substitute(template, parametres);
147
 
148
		Params cssParams = new Params();
149
		cssParams.set("css_corps", ComposantClass.DETAIL_CORPS_CONTENU);
150
		cssParams.set("css_label", ComposantClass.LABEL);
151
		cssParams.set("css_indentation", ComposantClass.INDENTATION);
152
		cssParams.set("css_fieldset", ComposantClass.FIELDSET);
153
		cssParams.set("css_clear", ComposantClass.CLEAR);
154
		cHtml = Format.substitute(cHtml, cssParams);
155
 
803 jpm 156
		return cHtml;
157
	}
158
 
159
	protected void afficherOnglet(String template, Params parametres, TabItem onglet) {
160
		String cHtml = formaterContenu(template, parametres);
161
 
453 jp_milcent 162
		HtmlContainer corpsConteneurDuHtml = new HtmlContainer(cHtml);
163
		onglet.removeAll();
164
		onglet.add(corpsConteneurDuHtml);
165
	}
166
 
167
	protected String formaterAutre(String chaineAAfficher) {
168
		if (!chaineAAfficher.equals("")) {
169
			chaineAAfficher = " ["+i18nC.autres()+" : "+chaineAAfficher+"]";
170
		}
171
		return chaineAAfficher;
172
	}
173
 
174
	protected String formaterOuiNon(String chaineAFormater) {
175
		String txtARetourner = "";
176
		if (chaineAFormater.equals("0")) {
177
			txtARetourner = i18nC.non();
178
		} else if (chaineAFormater.equals("1")) {
179
			txtARetourner = i18nC.oui();
180
		}
181
		return txtARetourner;
182
	}
183
 
184
	protected String formaterSautDeLigne(String chaineAFormater) {
185
		String txtARetourner = chaineAFormater.replaceAll("\n", sautLigneTpl);
186
		return txtARetourner;
187
	}
188
 
813 jpm 189
	protected void lancerChargementListesValeurs(String[] listesCodes) {
190
		Configuration configuration = (Configuration) Registry.get(RegistreId.CONFIG);
191
		for (int i = 0; i < listesCodes.length ; i++) {
192
			String code = listesCodes[i];
193
			ontologiesEnAttenteDeReception.put(configuration.getListeId(code), code);
194
			mediateur.obtenirListeValeurEtRafraichir(this, code);
195
		}
196
	}
197
 
816 jpm 198
	protected void receptionerListeValeurs(ValeurListe listeValeursReceptionnee) {
813 jpm 199
		mettreAJourOntologieEnAttenteDeReception(listeValeursReceptionnee);
200
		ajouterListeValeursAOntologie(listeValeursReceptionnee);
201
	}
202
 
203
	protected void mettreAJourOntologieEnAttenteDeReception(ValeurListe listeValeursReceptionnee) {
204
		ontologiesEnAttenteDeReception.remove(listeValeursReceptionnee.getId());
205
		if (ontologiesEnAttenteDeReception.size() == 0) {
206
			ontologieChargementOk = true;
207
		}
208
	}
209
 
210
	protected void ajouterListeValeursAOntologie(ValeurListe listeValeursReceptionnee) {
211
		Iterator<String> it = listeValeursReceptionnee.keySet().iterator();
453 jp_milcent 212
		while (it.hasNext()) {
213
			String cle = it.next();
813 jpm 214
			Valeur valeur = listeValeursReceptionnee.get(cle);
453 jp_milcent 215
			if (valeur != null) {
216
				ontologie.put(cle, valeur);
217
			}
218
		}
219
	}
524 gduche 220
 
221
	protected String construireTxtListeOntologie(String chaineAAnalyser) {
222
		ArrayList<String> termes = new ArrayList<String>();
223
		ArrayList<String> autres = new ArrayList<String>();
224
		if ((chaineAAnalyser != null) && (!chaineAAnalyser.trim().equals("")))	{
225
			String[] valeurs = chaineAAnalyser.split(";;");
226
			int nbreValeurs = valeurs.length;
227
			if (nbreValeurs > 0)	{
228
				for (int i = 0; i < nbreValeurs; i++)	{
229
					String id = valeurs[i];
230
					if (id.contains("AUTRE##"))	{
231
						String txt = id.replaceFirst("^AUTRE##", "");
232
						if (!txt.equals("")) {
233
							autres.add(txt);
234
						}
235
					} else if (id.matches("^[0-9]+$"))	{
236
						if (ontologie != null) {
237
							Valeur valeur = ontologie.get(id);
238
							if (valeur != null) {
239
								String termeOntologie = valeur.getNom();
240
								termes.add(termeOntologie);
241
							}
242
						}
243
					}
244
				}
245
			}
246
		}
247
 
248
		String chaineTermes = formaterTableauDeTxt(termes);
249
		String chaineAutres = formaterTableauDeTxt(autres);
250
		String chaineARetourner = chaineTermes+formaterAutre(chaineAutres);
251
 
252
		return chaineARetourner;
253
	}
453 jp_milcent 254
}