Subversion Repositories eFlore/Applications.coel

Rev

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