Subversion Repositories eFlore/Applications.coel

Rev

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

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