Subversion Repositories eFlore/Applications.del

Rev

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

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