| 2 |
aperonnet |
1 |
package org.tela_botanica.client;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.client.image.ImageMediateur;
|
| 12 |
david |
4 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
| 2 |
aperonnet |
5 |
import org.tela_botanica.client.modeles.Utilisateur;
|
| 12 |
david |
6 |
|
| 2 |
aperonnet |
7 |
import org.tela_botanica.client.observation.ObservationMediateur;
|
| 12 |
david |
8 |
import org.tela_botanica.client.vues.EtatConnexionVue;
|
|
|
9 |
import org.tela_botanica.client.vues.FormulaireDeConnexionVue;
|
| 2 |
aperonnet |
10 |
|
| 12 |
david |
11 |
import com.google.gwt.user.client.Window;
|
|
|
12 |
import com.gwtext.client.widgets.Panel;
|
| 53 |
david |
13 |
import com.gwtext.client.widgets.TabPanel;
|
| 27 |
jpm |
14 |
import com.gwtext.client.widgets.layout.FitLayout;
|
| 36 |
jpm |
15 |
import com.gwtext.client.widgets.layout.RowLayout;
|
|
|
16 |
import com.gwtext.client.widgets.layout.RowLayoutData;
|
| 2 |
aperonnet |
17 |
|
| 12 |
david |
18 |
/**
|
|
|
19 |
* Mediateur gérant les interactions entre vues et les echanges de données
|
|
|
20 |
* C'est un singleton.
|
|
|
21 |
* @author david delon
|
|
|
22 |
*
|
|
|
23 |
*/
|
| 7 |
aperonnet |
24 |
|
| 12 |
david |
25 |
public class CarnetEnLigneMediateur implements Rafraichissable {
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* booleen qui verifie l'unicite de l'instance
|
|
|
30 |
*/
|
| 31 |
jpm |
31 |
private static boolean estInstancie = false ;
|
|
|
32 |
|
| 12 |
david |
33 |
/**
|
| 31 |
jpm |
34 |
* pointeur vers le médiateur lui même (pour le pattern singleton)
|
|
|
35 |
*/
|
|
|
36 |
private static CarnetEnLigneMediateur thisMediateur = null ;
|
|
|
37 |
|
|
|
38 |
/**
|
| 12 |
david |
39 |
* modele de données
|
|
|
40 |
*/
|
|
|
41 |
|
|
|
42 |
private CarnetEnLigneModele carnetEnLigneModele=null;
|
| 7 |
aperonnet |
43 |
|
| 12 |
david |
44 |
|
|
|
45 |
/**
|
|
|
46 |
* panneau principal de l'application "Carnet en ligne"
|
|
|
47 |
*/
|
| 2 |
aperonnet |
48 |
|
| 31 |
jpm |
49 |
private Panel panneauPrincipalCarnetEnLigne= null ;
|
| 12 |
david |
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* panneau a onglet pour les observation et les images
|
|
|
55 |
*/
|
|
|
56 |
|
|
|
57 |
|
| 27 |
jpm |
58 |
private com.gwtext.client.widgets.TabPanel ongletsObservationsImages=null;
|
| 12 |
david |
59 |
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Indicateur d'etat de la connexion utilisateur
|
|
|
63 |
*/
|
|
|
64 |
|
|
|
65 |
private EtatConnexionVue etatConnexionVue=null;
|
|
|
66 |
|
| 27 |
jpm |
67 |
|
| 12 |
david |
68 |
/**
|
|
|
69 |
* Texte d'invite connexion
|
|
|
70 |
*/
|
|
|
71 |
private final String texteDeconnexion="Utilisez ce carnet en ligne pour saisir vos observations, <u>identifiez-vous</u> pour les transmettre à Tela Botanica";
|
| 7 |
aperonnet |
72 |
|
| 12 |
david |
73 |
/**
|
|
|
74 |
* Boolean indiquant un essai de connexion
|
|
|
75 |
*/
|
|
|
76 |
|
|
|
77 |
private boolean tentativeConnection=false;
|
|
|
78 |
|
| 7 |
aperonnet |
79 |
|
| 2 |
aperonnet |
80 |
/**
|
| 12 |
david |
81 |
* Formulaire de connexion (lazy instantiation)
|
|
|
82 |
*
|
| 2 |
aperonnet |
83 |
*/
|
| 12 |
david |
84 |
|
|
|
85 |
private FormulaireDeConnexionVue formulaireDeConnexionVue=null;
|
| 7 |
aperonnet |
86 |
|
| 12 |
david |
87 |
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Mediateur Gestion des images
|
|
|
91 |
*/
|
|
|
92 |
|
|
|
93 |
private ImageMediateur imageMediateur=null;
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* Mediateur Gestion des observations
|
|
|
97 |
*/
|
|
|
98 |
|
|
|
99 |
private ObservationMediateur observationMediateur=null;
|
|
|
100 |
|
| 2 |
aperonnet |
101 |
|
| 7 |
aperonnet |
102 |
|
| 12 |
david |
103 |
/**
|
|
|
104 |
* Utilisateur en cours
|
|
|
105 |
*/
|
| 7 |
aperonnet |
106 |
|
| 12 |
david |
107 |
|
|
|
108 |
private Utilisateur utilisateur=null;
|
|
|
109 |
|
| 7 |
aperonnet |
110 |
|
| 12 |
david |
111 |
|
|
|
112 |
public static CarnetEnLigneMediateur Instance()
|
|
|
113 |
{
|
| 31 |
jpm |
114 |
if(!estInstancie || thisMediateur==null)
|
| 12 |
david |
115 |
{
|
|
|
116 |
estInstancie = true ;
|
| 31 |
jpm |
117 |
thisMediateur = new CarnetEnLigneMediateur() ;
|
| 12 |
david |
118 |
}
|
| 31 |
jpm |
119 |
|
|
|
120 |
return thisMediateur ;
|
|
|
121 |
|
| 12 |
david |
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
/**
|
|
|
126 |
* constructeur privé (on accède a la classe par la méthode getInstance
|
|
|
127 |
*/
|
|
|
128 |
|
|
|
129 |
private CarnetEnLigneMediateur() {
|
|
|
130 |
|
|
|
131 |
|
| 31 |
jpm |
132 |
panneauPrincipalCarnetEnLigne = new Panel("Carnet en ligne");
|
|
|
133 |
|
| 12 |
david |
134 |
// Disposition
|
|
|
135 |
|
| 36 |
jpm |
136 |
panneauPrincipalCarnetEnLigne.setLayout(new RowLayout());
|
| 7 |
aperonnet |
137 |
|
| 12 |
david |
138 |
|
|
|
139 |
// On crée un modèle d'acces aux donnnes
|
|
|
140 |
|
|
|
141 |
carnetEnLigneModele=CarnetEnLigneModele.Instance();
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
// La vue affichant le statut de la connexion
|
| 7 |
aperonnet |
145 |
|
| 12 |
david |
146 |
etatConnexionVue=new EtatConnexionVue(this);
|
| 36 |
jpm |
147 |
etatConnexionVue.setLayout(new FitLayout()) ;
|
| 12 |
david |
148 |
|
|
|
149 |
// Le panneau à onglet qui contient les 2 applications Observation et Images
|
|
|
150 |
|
| 53 |
david |
151 |
ongletsObservationsImages = new TabPanel();
|
| 12 |
david |
152 |
|
| 36 |
jpm |
153 |
panneauPrincipalCarnetEnLigne.add(etatConnexionVue,new RowLayoutData(20));
|
| 12 |
david |
154 |
|
|
|
155 |
// on ajoute le panneau a onglet au panneau principal
|
|
|
156 |
|
| 42 |
jpm |
157 |
panneauPrincipalCarnetEnLigne.add(ongletsObservationsImages);
|
| 12 |
david |
158 |
|
|
|
159 |
// On ajoute les applications
|
|
|
160 |
observationMediateur = ObservationMediateur.Instance(this);
|
| 30 |
jpm |
161 |
imageMediateur= ImageMediateur.Instance(this);
|
| 12 |
david |
162 |
|
| 53 |
david |
163 |
//temp dd viewport desactive ajout de cette ligne
|
|
|
164 |
getPanneauPrincipalCarnetEnLigne().setHeight(1200) ;
|
|
|
165 |
//
|
|
|
166 |
|
| 36 |
jpm |
167 |
//panneauPrincipalCarnetEnLigne.setSize(Window.getClientWidth(), Window.getClientHeight() - etatConnexionVue.getHeight()) ;
|
| 42 |
jpm |
168 |
observationMediateur.getPanneauPrincipalObservation().setSize(panneauPrincipalCarnetEnLigne.getWidth(),panneauPrincipalCarnetEnLigne.getHeight() - 20) ;
|
| 31 |
jpm |
169 |
imageMediateur.getPanneauPrincipalImage().setSize(panneauPrincipalCarnetEnLigne.getWidth(),panneauPrincipalCarnetEnLigne.getHeight() - 20) ;
|
| 12 |
david |
170 |
|
| 31 |
jpm |
171 |
// on ajoute les panneaux principaux des applications au panneau à onglets
|
| 37 |
jpm |
172 |
ongletsObservationsImages.add(observationMediateur.getPanneauPrincipalObservation());
|
|
|
173 |
ongletsObservationsImages.add(imageMediateur.getPanneauPrincipalImage());
|
| 31 |
jpm |
174 |
|
| 2 |
aperonnet |
175 |
}
|
| 12 |
david |
176 |
|
|
|
177 |
|
|
|
178 |
public void getEtatUtilisateur() {
|
|
|
179 |
|
|
|
180 |
|
|
|
181 |
carnetEnLigneModele.getEtatUtilisateur(this);
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
}
|
| 2 |
aperonnet |
185 |
|
| 7 |
aperonnet |
186 |
|
| 2 |
aperonnet |
187 |
// Methode publiques
|
| 12 |
david |
188 |
|
|
|
189 |
|
|
|
190 |
|
| 2 |
aperonnet |
191 |
/**
|
|
|
192 |
* Recherche Identifiant utilisateur en cours et etat de connection
|
|
|
193 |
* @return Utilisateur
|
|
|
194 |
*/
|
| 12 |
david |
195 |
|
|
|
196 |
|
| 2 |
aperonnet |
197 |
public Utilisateur getUtilisateur() {
|
|
|
198 |
return utilisateur;
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
/**
|
|
|
202 |
* Deconnecte l'utilisateur passe en parametre
|
|
|
203 |
*/
|
| 12 |
david |
204 |
public void deconnecterUtilisateur() {
|
| 2 |
aperonnet |
205 |
|
| 12 |
david |
206 |
|
|
|
207 |
carnetEnLigneModele.deconnecterUtilisateur(this, utilisateur.getIdentifiant());
|
|
|
208 |
|
|
|
209 |
}
|
| 2 |
aperonnet |
210 |
|
| 12 |
david |
211 |
public void connecterUtilisateur(String login, String password) {
|
|
|
212 |
|
|
|
213 |
tentativeConnection=true;
|
|
|
214 |
carnetEnLigneModele.connecterUtilisateur(this, login, password);
|
|
|
215 |
|
| 2 |
aperonnet |
216 |
}
|
|
|
217 |
|
|
|
218 |
|
| 12 |
david |
219 |
|
|
|
220 |
/**
|
|
|
221 |
* Affichage etat de la connexion
|
|
|
222 |
*/
|
|
|
223 |
|
|
|
224 |
|
|
|
225 |
private void afficheEtatConnexion() {
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
if (!utilisateur.isIdentifie()) {
|
|
|
229 |
etatConnexionVue.setEtat(texteDeconnexion,false);
|
|
|
230 |
}
|
|
|
231 |
else {
|
|
|
232 |
etatConnexionVue.setEtat(utilisateur.getIdentifiant()+ " (deconnexion)",true);
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
}
|
| 7 |
aperonnet |
236 |
|
| 12 |
david |
237 |
|
|
|
238 |
/**
|
|
|
239 |
*
|
|
|
240 |
* Affichage boite de connexion
|
|
|
241 |
*
|
|
|
242 |
*/
|
|
|
243 |
|
|
|
244 |
|
|
|
245 |
public void afficherDialogueConnexion() {
|
|
|
246 |
|
|
|
247 |
if (formulaireDeConnexionVue==null) {
|
|
|
248 |
formulaireDeConnexionVue= new FormulaireDeConnexionVue(this);
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
// Position it roughly in the middle of the screen.
|
|
|
252 |
int left = (Window.getClientWidth() - 512) / 2;
|
|
|
253 |
int top = (Window.getClientHeight() - 256) / 2;
|
|
|
254 |
|
|
|
255 |
|
|
|
256 |
formulaireDeConnexionVue.setPopupPosition(left, top);
|
|
|
257 |
formulaireDeConnexionVue.show();
|
|
|
258 |
|
|
|
259 |
}
|
| 7 |
aperonnet |
260 |
|
| 2 |
aperonnet |
261 |
|
| 12 |
david |
262 |
|
|
|
263 |
|
|
|
264 |
public Panel getPanneauPrincipalCarnetEnLigne() {
|
|
|
265 |
return panneauPrincipalCarnetEnLigne;
|
| 2 |
aperonnet |
266 |
}
|
|
|
267 |
|
| 12 |
david |
268 |
|
|
|
269 |
// TODO : repandre rafraichissement
|
|
|
270 |
|
|
|
271 |
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
|
|
|
272 |
|
|
|
273 |
if (nouvelleDonnees instanceof Utilisateur) {
|
|
|
274 |
|
|
|
275 |
utilisateur = (Utilisateur) nouvelleDonnees;
|
| 38 |
jpm |
276 |
|
|
|
277 |
imageMediateur.connecterUtilisateur() ;
|
| 12 |
david |
278 |
|
|
|
279 |
afficheEtatConnexion();
|
|
|
280 |
|
|
|
281 |
if ((tentativeConnection) && !utilisateur.isIdentifie()) {
|
|
|
282 |
|
| 38 |
jpm |
283 |
//formulaireDeConnexionVue.afficherMessageAlerte();
|
| 12 |
david |
284 |
}
|
|
|
285 |
else {
|
|
|
286 |
if ((tentativeConnection) && utilisateur.isIdentifie()) {
|
|
|
287 |
formulaireDeConnexionVue.hide();
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
// On lance l'affichage des observations
|
|
|
294 |
observationMediateur.obtenirNombreObservation();
|
|
|
295 |
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
}
|