Subversion Repositories eFlore/Applications.coel

Rev

Rev 936 | Rev 967 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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