Subversion Repositories eFlore/Applications.del

Rev

Rev 405 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
148 benjamin 1
package org.tela_botanica.del.client.vues.rechercheimages;
9 benjamin 2
 
3
import java.util.List;
4
 
148 benjamin 5
import org.tela_botanica.del.client.cache.CacheClient;
323 gduche 6
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur;
7
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue;
8
import org.tela_botanica.del.client.i18n.I18n;
178 benjamin 9
import org.tela_botanica.del.client.modeles.Protocole;
148 benjamin 10
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
178 benjamin 11
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
344 aurelien 12
import org.tela_botanica.del.client.services.rest.ImageServiceConcret;
291 benjamin 13
import org.tela_botanica.del.client.services.rest.ProtocoleService;
9 benjamin 14
import org.tela_botanica.del.client.utils.MockDatasource;
335 benjamin 15
import org.tela_botanica.del.client.vues.rechercheimages.resultats.ResultatRechercheImagePresenteur;
379 gduche 16
import org.tela_botanica.del.client.vues.rechercheimages.resultats.ResultatRechercheImageVue;
9 benjamin 17
 
178 benjamin 18
import com.google.gwt.event.dom.client.ChangeEvent;
19
import com.google.gwt.event.dom.client.ChangeHandler;
277 gduche 20
import com.google.gwt.event.dom.client.HasChangeHandlers;
9 benjamin 21
import com.google.gwt.user.client.ui.HasWidgets;
277 gduche 22
import com.google.gwt.user.client.ui.IsWidget;
9 benjamin 23
 
323 gduche 24
public class MoteurRechercheImagePresenteur {
9 benjamin 25
 
277 gduche 26
	public interface Vue extends IsWidget {
335 benjamin 27
 
387 aurelien 28
		public void ajouterProtocole(String protocole);
29
		public void selectionnerProtocole(int index);
30
		public HasChangeHandlers getListeProtocoles();
31
		public HasWidgets getZoneResultats();
32
		public HasWidgets getZoneRecherche();
33
		public String getNomProtocolSelectionne();
405 gduche 34
		public int getIdProtocolSelectionne();
277 gduche 35
	}
335 benjamin 36
 
277 gduche 37
	private Vue vue;
335 benjamin 38
 
311 gduche 39
	// private final ImageService imageService = MockDatasource.getInstance();
291 benjamin 40
	private final ProtocoleService protocoleService = MockDatasource.getInstance();
311 gduche 41
	private List<Protocole> protocoles;
335 benjamin 42
 
43
	// TODO : passer ça en cache
405 gduche 44
	private String protocoleParDefaut = Protocole.ESTHETISME;
335 benjamin 45
 
277 gduche 46
	/**
47
	 * Constructeur
48
	 * */
323 gduche 49
	public MoteurRechercheImagePresenteur(Vue vue) {
277 gduche 50
		this.vue = vue;
178 benjamin 51
		if (CacheClient.getInstance().getProtocoleCourant() == null) {
291 benjamin 52
			CacheClient.getInstance().setProtocoleCourant(protocoleService.getProtocole(protocoleParDefaut));
178 benjamin 53
		}
9 benjamin 54
	}
55
 
56
	public void go(HasWidgets composite) {
277 gduche 57
		composite.add(vue.asWidget());
26 gduche 58
		gererEvenements();
178 benjamin 59
		chargerProtocoles();
323 gduche 60
		chargerMoteurRechercheAvancee();
178 benjamin 61
	}
148 benjamin 62
 
178 benjamin 63
	private void chargerProtocoles() {
291 benjamin 64
		protocoles = protocoleService.getProtocoles();
178 benjamin 65
		for (Protocole protocole : protocoles) {
277 gduche 66
			vue.ajouterProtocole(protocole.getNom());
148 benjamin 67
		}
277 gduche 68
		vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
9 benjamin 69
	}
70
 
26 gduche 71
	public void gererEvenements() {
9 benjamin 72
 
277 gduche 73
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
9 benjamin 74
 
124 gduche 75
			@Override
178 benjamin 76
			public void onChange(ChangeEvent event) {
360 benjamin 77
				Protocole protocoleCourant = null;
78
				for (Protocole protocole : protocoles) {
405 gduche 79
					if (protocole.getId() == vue.getIdProtocolSelectionne()) {
360 benjamin 80
						protocoleCourant = protocole;
81
					}
82
				}
335 benjamin 83
 
360 benjamin 84
				CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
178 benjamin 85
				EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
86
				BusEvenementiel.getInstance().fireEvent(evenement);
124 gduche 87
			}
178 benjamin 88
		});
9 benjamin 89
	}
335 benjamin 90
 
323 gduche 91
	public void chargerMoteurRechercheAvancee() {
406 gduche 92
		MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(""), true, false) {
335 benjamin 93
			public void lancerRecherche() {
94
				chercherImages();
323 gduche 95
			}
96
		};
97
		presenteurRecherche.go(vue.getZoneRecherche());
9 benjamin 98
	}
335 benjamin 99
 
100
	public void chercherImages() {
359 benjamin 101
		vue.getZoneResultats().clear();
379 gduche 102
		new ResultatRechercheImagePresenteur(new ImageServiceConcret(), new ResultatRechercheImageVue()).go(vue.getZoneResultats());
335 benjamin 103
	}
104
 
278 gduche 105
	public HasWidgets getZoneResultats() {
106
		return vue.getZoneResultats();
9 benjamin 107
	}
108
}