Subversion Repositories eFlore/Applications.del

Rev

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