Subversion Repositories eFlore/Applications.del

Rev

Rev 1467 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1467 Rev 1501
1
package org.tela_botanica.del.client.vues.pictoflora.moteur;
1
package org.tela_botanica.del.client.vues.pictoflora.moteur;
2
 
2
 
3
import java.util.List;
3
import java.util.List;
4
 
-
 
5
import javax.validation.Configuration;
-
 
6
 
4
 
7
import org.tela_botanica.del.client.cache.CacheClient;
5
import org.tela_botanica.del.client.cache.CacheClient;
8
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur;
6
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur;
9
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue;
7
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue;
10
import org.tela_botanica.del.client.composants.partageurl.PartageUrlPresenteur;
-
 
11
import org.tela_botanica.del.client.composants.partageurl.PartageUrlVue;
-
 
12
import org.tela_botanica.del.client.config.Config;
-
 
13
import org.tela_botanica.del.client.modeles.ModeRecherche;
8
import org.tela_botanica.del.client.modeles.ModeRecherche;
14
import org.tela_botanica.del.client.modeles.Protocole;
9
import org.tela_botanica.del.client.modeles.Protocole;
15
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
10
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
16
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
11
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
17
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
12
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
18
import org.tela_botanica.del.client.services.rest.ImageServiceConcret;
13
import org.tela_botanica.del.client.services.rest.ImageServiceConcret;
19
import org.tela_botanica.del.client.services.rest.ProtocoleService;
14
import org.tela_botanica.del.client.services.rest.ProtocoleService;
20
import org.tela_botanica.del.client.services.rest.ProtocoleServiceConcret;
15
import org.tela_botanica.del.client.services.rest.ProtocoleServiceConcret;
21
import org.tela_botanica.del.client.services.rest.async.ProtocolesCallback;
16
import org.tela_botanica.del.client.services.rest.async.ProtocolesCallback;
22
import org.tela_botanica.del.client.utils.URLUtils;
-
 
23
import org.tela_botanica.del.client.vues.pictoflora.resultats.ResultatPictofloraPresenteur;
17
import org.tela_botanica.del.client.vues.pictoflora.resultats.ResultatPictofloraPresenteur;
24
import org.tela_botanica.del.client.vues.pictoflora.resultats.ResultatPictofloraVue;
18
import org.tela_botanica.del.client.vues.pictoflora.resultats.ResultatPictofloraVue;
25
 
19
 
26
import com.google.gwt.event.dom.client.ChangeEvent;
20
import com.google.gwt.event.dom.client.ChangeEvent;
27
import com.google.gwt.event.dom.client.ChangeHandler;
21
import com.google.gwt.event.dom.client.ChangeHandler;
28
import com.google.gwt.event.dom.client.ClickEvent;
-
 
29
import com.google.gwt.event.dom.client.ClickHandler;
-
 
30
import com.google.gwt.event.dom.client.HasChangeHandlers;
22
import com.google.gwt.event.dom.client.HasChangeHandlers;
31
import com.google.gwt.event.dom.client.HasClickHandlers;
-
 
32
import com.google.gwt.user.client.Window;
-
 
33
import com.google.gwt.user.client.ui.HasWidgets;
23
import com.google.gwt.user.client.ui.HasWidgets;
34
import com.google.gwt.user.client.ui.IsWidget;
24
import com.google.gwt.user.client.ui.IsWidget;
35
import com.google.gwt.user.client.ui.ListBox;
25
import com.google.gwt.user.client.ui.ListBox;
36
import com.google.gwt.user.client.ui.Panel;
-
 
37
 
26
 
38
public class MoteurPictofloraPresenteur {
27
public class MoteurPictofloraPresenteur {
39
 
28
 
40
	public interface Vue extends IsWidget {
29
	public interface Vue extends IsWidget {
41
		public HasWidgets getZoneResultats();
30
		public HasWidgets getZoneResultats();
42
 
31
 
43
		public HasWidgets getZoneRecherche();
32
		public HasWidgets getZoneRecherche();
44
 
33
 
45
		public void ajouterVue(HasWidgets composite);
34
		public void ajouterVue(HasWidgets composite);
46
 
35
 
47
		public void setListeProtocoles(ListBox listeProtocoles);
36
		public void setListeProtocoles(ListBox listeProtocoles);
48
		
37
		
49
		public HasChangeHandlers getListeProtocoles();
38
		public HasChangeHandlers getListeProtocoles();
50
		
39
		
51
		public void ajouterProtocole(String NomProtocole, String idProtocole);
40
		public void ajouterProtocole(String NomProtocole, String idProtocole);
52
 
41
 
53
		public void selectionnerProtocole(int index);
42
		public void selectionnerProtocole(int index);
54
		
43
		
55
		public void selectionnerProtocoleParProtocole(Protocole protocole);
44
		public void selectionnerProtocoleParProtocole(Protocole protocole);
56
		
45
		
57
		public String getNomProtocoleSelectionne();
46
		public String getNomProtocoleSelectionne();
58
 
47
 
59
		public int getIdProtocoleSelectionne();
48
		public int getIdProtocoleSelectionne();
60
 
49
 
61
		public void ajouterProtocoles(List<Protocole> protocoles);
50
		public void ajouterProtocoles(List<Protocole> protocoles);
62
 
51
 
63
		public void mettreAJourDescriptionProtocoleCourant(Protocole protocoleCourant);
52
		public void mettreAJourDescriptionProtocoleCourant(Protocole protocoleCourant);
64
		
53
		
65
	}
54
	}
66
 
55
 
67
	private Vue vue;
56
	private Vue vue;
68
	private ProtocoleService protocoleService;
57
	private ProtocoleService protocoleService;
69
	private List<Protocole> protocoles;
58
	private List<Protocole> protocoles;
70
 
59
 
71
	/**
60
	/**
72
	 * Constructeur
61
	 * Constructeur
73
	 * */
62
	 * */
74
	public MoteurPictofloraPresenteur(Vue vue, ProtocoleService protocoleService) {
63
	public MoteurPictofloraPresenteur(Vue vue, ProtocoleService protocoleService) {
75
		
64
		
76
		this.vue = vue;
65
		this.vue = vue;
77
		this.protocoleService = protocoleService;
66
		this.protocoleService = protocoleService;
78
		chargerProtocoles();
67
		chargerProtocoles();
79
		
68
		
80
		// TODO: le code ci dessous sert à ne pas recharger les protocoles
69
		// TODO: le code ci dessous sert à ne pas recharger les protocoles
81
		// à chaque fois, voir si on peut le factoriser quelque part
70
		// à chaque fois, voir si on peut le factoriser quelque part
82
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
71
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
83
			if (CacheClient.getInstance().getListeProtocoles() == null) {
72
			if (CacheClient.getInstance().getListeProtocoles() == null) {
84
				protocoleService.getProtocoles(new ProtocolesCallback() {
73
				protocoleService.getProtocoles(new ProtocolesCallback() {
85
 
74
 
86
					@Override
75
					@Override
87
					public void surRetour(ProtocoleServiceResultat protocolesRecus) {
76
					public void surRetour(ProtocoleServiceResultat protocolesRecus) {
88
						CacheClient.getInstance().setListeProtocoles(protocolesRecus.getProtocoles());
77
						CacheClient.getInstance().setListeProtocoles(protocolesRecus.getProtocoles());
89
						if (protocolesRecus.getProtocoles().size() > 0) {
78
						if (protocolesRecus.getProtocoles().size() > 0) {
90
							if(protocoles == null) {
79
							if(protocoles == null) {
91
								protocoles = protocolesRecus.getProtocoles();
80
								protocoles = protocolesRecus.getProtocoles();
92
							}
81
							}
93
							//Vérifier qu'on n'a pas demandé un protocole particulier en paramètre
82
							//Vérifier qu'on n'a pas demandé un protocole particulier en paramètre
94
							String parametre = URLUtils.getURLSpecialParameterValue();
83
							String parametre = CacheClient.getInstance().getIdProtocoleEnAttente();
95
							if (parametre != null) {
84
							if (parametre != null) {
96
								for (Protocole protocoleCourant : protocoles) {
85
								for (Protocole protocoleCourant : protocoles) {
97
										if (parametre.equals(String.valueOf(protocoleCourant.getId()))) {
86
										if (parametre.equals(String.valueOf(protocoleCourant.getId()))) {
98
											CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
87
											CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
99
										}
88
										}
100
								}
89
								}
-
 
90
								CacheClient.getInstance().setIdProtocoleEnAttente(null);
101
							} else {
91
							} else {
102
								CacheClient.getInstance().setProtocoleCourant(protocolesRecus.getProtocoles().get(0));
92
								CacheClient.getInstance().setProtocoleCourant(protocolesRecus.getProtocoles().get(0));
103
							}
93
							}
104
						} else {
94
						} else {
105
							// TODO afficher message indiquant que la liste des
95
							// TODO afficher message indiquant que la liste des
106
							// protocoles de votes n'est pas fourni
96
							// protocoles de votes n'est pas fourni
107
						}
97
						}
108
					}
98
					}
109
				});
99
				});
110
			} else {
100
			} else {
111
				CacheClient.getInstance().setProtocoleCourant(CacheClient.getInstance().getListeProtocoles().get(0));
101
				CacheClient.getInstance().setProtocoleCourant(CacheClient.getInstance().getListeProtocoles().get(0));
112
			}
102
			}
113
		}
103
		}
114
		gererEvenements();
104
		gererEvenements();
115
	}
105
	}
116
	
106
	
117
	private void gererEvenements() {
107
	private void gererEvenements() {
118
		
108
		
119
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
109
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
120
			@Override
110
			@Override
121
			public void onChange(ChangeEvent event) {
111
			public void onChange(ChangeEvent event) {
122
				surChangementProtocole();
112
				surChangementProtocole();
123
			}
113
			}
124
		});
114
		});
125
		
115
		
126
	}
116
	}
127
	
117
	
128
	private void chargerProtocoles() {
118
	private void chargerProtocoles() {
129
		// test pour ne pas charger les protocoles déjà chargés
119
		// test pour ne pas charger les protocoles déjà chargés
130
		// TODO: faire un systeme de cache gérés par les web service eux même
120
		// TODO: faire un systeme de cache gérés par les web service eux même
131
		if (CacheClient.getInstance().getListeProtocoles() == null) {
121
		if (CacheClient.getInstance().getListeProtocoles() == null) {
132
			protocoleService.getProtocoles(new ProtocolesCallback() {
122
			protocoleService.getProtocoles(new ProtocolesCallback() {
133
 
123
 
134
				@Override
124
				@Override
135
				public void surRetour(ProtocoleServiceResultat protocolesRecus) {
125
				public void surRetour(ProtocoleServiceResultat protocolesRecus) {
136
					protocoles = protocolesRecus.getProtocoles();
126
					protocoles = protocolesRecus.getProtocoles();
137
					remplirListeProtocole(protocoles);
127
					remplirListeProtocole(protocoles);
138
					surChangementProtocole();
128
					surChangementProtocole();
139
				}
129
				}
140
			});
130
			});
141
		} else {
131
		} else {
142
			protocoles = CacheClient.getInstance().getListeProtocoles();
132
			protocoles = CacheClient.getInstance().getListeProtocoles();
143
			remplirListeProtocole(CacheClient.getInstance().getListeProtocoles());
133
			remplirListeProtocole(CacheClient.getInstance().getListeProtocoles());
144
		}
134
		}
145
	}
135
	}
146
	
136
	
147
	public void surChangementProtocole() {
137
	public void surChangementProtocole() {
148
		Protocole protocoleCourant = null;
138
		Protocole protocoleCourant = null;
149
		for (Protocole protocole : protocoles) {
139
		for (Protocole protocole : protocoles) {
150
			if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
140
			if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
151
				protocoleCourant = protocole;
141
				protocoleCourant = protocole;
152
			}
142
			}
153
		}
143
		}
154
		vue.mettreAJourDescriptionProtocoleCourant(protocoleCourant);
144
		vue.mettreAJourDescriptionProtocoleCourant(protocoleCourant);
155
		CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
145
		CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
156
		CacheClient.getInstance().mettreAjourUrlCourante();
-
 
157
		EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
146
		EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
158
		BusEvenementiel.getInstance().fireEvent(evenement);
147
		BusEvenementiel.getInstance().fireEvent(evenement);
-
 
148
		CacheClient.getInstance().mettreAjourUrlCourante();
159
	}
149
	}
160
	
150
	
161
	private void remplirListeProtocole(List<Protocole> protocoles) {
151
	private void remplirListeProtocole(List<Protocole> protocoles) {
162
		//si un paramètre est passé dans l'url, on sélectionne un protocole
152
		//si un paramètre est passé dans l'url, on sélectionne un protocole
163
		String parametre = URLUtils.getURLSpecialParameterValue();
153
		String parametre = CacheClient.getInstance().getIdProtocoleEnAttente();
164
		if (parametre != null) {
154
		if (parametre != null) {
165
			for (Protocole protocoleCourant : protocoles) {
155
			for (Protocole protocoleCourant : protocoles) {
166
					if (parametre.equals(String.valueOf(protocoleCourant.getId()))) {
156
				if (parametre.equals(String.valueOf(protocoleCourant.getId()))) {
167
						CacheClient.getInstance().mettreAjourUrlCourante();
-
 
168
						CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
157
					CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
169
					}
158
				}
170
			}
159
			}
171
		}
160
		}
-
 
161
	
172
		vue.ajouterProtocoles(protocoles);
162
		vue.ajouterProtocoles(protocoles);
173
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
163
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
174
			vue.selectionnerProtocole(0);
164
			vue.selectionnerProtocole(0);
175
			vue.mettreAJourDescriptionProtocoleCourant(protocoles.get(0));
165
			vue.mettreAJourDescriptionProtocoleCourant(protocoles.get(0));
176
		} else {
166
		} else {
177
			vue.selectionnerProtocoleParProtocole(CacheClient.getInstance().getProtocoleCourant());
167
			vue.selectionnerProtocoleParProtocole(CacheClient.getInstance().getProtocoleCourant());
178
			vue.mettreAJourDescriptionProtocoleCourant(CacheClient.getInstance().getProtocoleCourant());
168
			vue.mettreAJourDescriptionProtocoleCourant(CacheClient.getInstance().getProtocoleCourant());
179
		}
169
		}
-
 
170
		CacheClient.getInstance().mettreAjourUrlCourante();
180
	}
171
	}
181
 
172
 
182
	public void go(HasWidgets composite) {
173
	public void go(HasWidgets composite) {
183
		vue.ajouterVue(composite);
174
		vue.ajouterVue(composite);
184
		chargerMoteurRechercheAvancee();
175
		chargerMoteurRechercheAvancee();
185
	}
176
	}
186
 
177
 
187
	public void chargerMoteurRechercheAvancee() {
178
	public void chargerMoteurRechercheAvancee() {
188
		MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(""), ModeRecherche.MODE_IMAGE) {
179
		MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(""), ModeRecherche.MODE_IMAGE) {
189
			public void lancerRecherche() {
180
			public void lancerRecherche() {
190
				chercherImages();
181
				chercherImages();
191
			}
182
			}
192
		};
183
		};
193
		presenteurRecherche.go(vue.getZoneRecherche());
184
		presenteurRecherche.go(vue.getZoneRecherche());
194
	}
185
	}
195
 
186
 
196
	public void chercherImages() {
187
	public void chercherImages() {
197
		vue.getZoneResultats().clear();
188
		vue.getZoneResultats().clear();
198
		CacheClient.getInstance().mettreAjourUrlCourante();
189
		CacheClient.getInstance().mettreAjourUrlCourante();
199
		new ResultatPictofloraPresenteur(new ImageServiceConcret(), new ProtocoleServiceConcret(), new ResultatPictofloraVue()).go(vue.getZoneResultats());
190
		new ResultatPictofloraPresenteur(new ImageServiceConcret(), new ProtocoleServiceConcret(), new ResultatPictofloraVue()).go(vue.getZoneResultats());
200
	}
191
	}
201
 
192
 
202
	public HasWidgets getZoneResultats() {
193
	public HasWidgets getZoneResultats() {
203
		return vue.getZoneResultats();
194
		return vue.getZoneResultats();
204
	}
195
	}
205
}
196
}