Subversion Repositories eFlore/Applications.del

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
178 benjamin 1
package org.tela_botanica.del.client.vues.rechercheimages.resultats.images;
2
 
3
import java.util.List;
4
 
250 gduche 5
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
178 benjamin 6
import org.tela_botanica.del.client.modeles.Image;
7
import org.tela_botanica.del.client.modeles.Protocole;
8
import org.tela_botanica.del.client.modeles.VoteProtocole;
9
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
10
import org.tela_botanica.del.client.navigation.evenement.validationobservation.EvenementValidation;
11
import org.tela_botanica.del.client.utils.MockDatasource;
12
import org.tela_botanica.del.client.vues.rechercheimages.resultats.ResultatRechercheImagePresenteur;
13
import org.tela_botanica.del.client.vues.rechercheimages.vote.MoyenneVotePresenteur;
250 gduche 14
import org.tela_botanica.del.client.vues.rechercheobservations.DetailImagePresenteur;
178 benjamin 15
 
16
import com.google.gwt.event.dom.client.ClickEvent;
17
import com.google.gwt.event.dom.client.ClickHandler;
18
import com.google.gwt.user.client.ui.HasWidgets;
19
import com.google.gwt.user.client.ui.Label;
20
import com.google.gwt.user.client.ui.VerticalPanel;
21
 
250 gduche 22
public class ImagePresenteur extends Presenteur {
178 benjamin 23
 
24
	private final MockDatasource validationService = MockDatasource.getInstance();
25
	private final Image image;
26
	private boolean detailsOpen = false;
27
 
28
	private Protocole protocole;
29
 
30
	public ImagePresenteur(Image image, Protocole protocole) {
250 gduche 31
		super(new ImageVue());
178 benjamin 32
		this.image = image;
33
		this.protocole = protocole;
34
	}
35
 
36
	public void go(HasWidgets composite) {
250 gduche 37
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 38
		composite.add(vue);
39
		vue.loadImage(image);
40
		loadValidationData();
250 gduche 41
		gererEvenements();
178 benjamin 42
	}
43
 
44
	private void loadValidationData() {
250 gduche 45
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 46
		List<VoteProtocole> observationValidationDatas = validationService.getVoteByImageAndProtocol(image.getIdImage(), protocole.getNom());
242 gduche 47
		new MoyenneVotePresenteur(observationValidationDatas).go(vue.voter);
178 benjamin 48
	}
49
 
250 gduche 50
	@Override
51
	protected void gererEvenements() {
52
		ImageVue vue = (ImageVue) this.getVue();
53
 
54
		vue.imagePrincipale.addClickHandler(new ClickHandler() {
55
 
56
			@Override
57
			public void onClick(ClickEvent event) {
58
				com.google.gwt.user.client.ui.Image photo = (com.google.gwt.user.client.ui.Image) event.getSource();
59
				ouvrirFenetreModale(new DetailImagePresenteur(photo.getTitle(), photo.getAltText()));
60
			}
61
		});
242 gduche 62
		vue.enSavoirPlus.addClickHandler(new ClickHandler() {
178 benjamin 63
 
64
			@Override
65
			public void onClick(ClickEvent event) {
66
 
67
				if (!detailsOpen) {
68
					afficherDetails();
69
				} else {
70
					cacherDetails();
71
				}
72
			}
73
		});
74
 
242 gduche 75
		vue.ajoutValidation.addClickHandler(new ClickHandler() {
178 benjamin 76
 
77
			@Override
78
			public void onClick(ClickEvent event) {
79
				BusEvenementiel.getInstance().fireEvent(new EvenementValidation(image));
80
			}
81
		});
82
	}
83
 
84
	public void cacherDetails() {
250 gduche 85
		ImageVue vue = (ImageVue) this.getVue();
242 gduche 86
		VerticalPanel zoneCache = vue.zoneCache;
87
		Label enSavoirPlus = vue.enSavoirPlus;
178 benjamin 88
 
89
		zoneCache.setVisible(false);
90
		enSavoirPlus.setStyleName("boutonPlus");
91
 
92
		detailsOpen = false;
93
	}
94
 
95
	public void afficherDetails() {
250 gduche 96
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 97
		ResultatRechercheImagePresenteur.getInstance().fermerTousPanneauxDetailsObservations();
98
 
242 gduche 99
		VerticalPanel zoneCache = vue.zoneCache;
100
		Label enSavoirPlus = vue.enSavoirPlus;
178 benjamin 101
 
102
		zoneCache.setVisible(true);
103
		enSavoirPlus.setStyleName("boutonMoins");
104
 
105
		detailsOpen = true;
106
	}
107
 
108
	public boolean isDetailsOpen() {
109
		return detailsOpen;
110
	}
111
 
112
}