Subversion Repositories eFlore/Applications.coel

Rev

Rev 935 | Rev 961 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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