Subversion Repositories eFlore/Applications.coel

Rev

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

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