Subversion Repositories eFlore/Applications.del

Rev

Rev 242 | Go to most recent revision | Details | Compare with Previous | 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
		boolean etrange = (this == null);
38
		Object ca = this.getVue();
39
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 40
		composite.add(vue);
41
		vue.loadImage(image);
42
		loadValidationData();
250 gduche 43
		gererEvenements();
178 benjamin 44
	}
45
 
46
	private void loadValidationData() {
250 gduche 47
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 48
		List<VoteProtocole> observationValidationDatas = validationService.getVoteByImageAndProtocol(image.getIdImage(), protocole.getNom());
242 gduche 49
		new MoyenneVotePresenteur(observationValidationDatas).go(vue.voter);
178 benjamin 50
	}
51
 
250 gduche 52
	@Override
53
	protected void gererEvenements() {
54
		ImageVue vue = (ImageVue) this.getVue();
55
 
56
		vue.imagePrincipale.addClickHandler(new ClickHandler() {
57
 
58
			@Override
59
			public void onClick(ClickEvent event) {
60
				com.google.gwt.user.client.ui.Image photo = (com.google.gwt.user.client.ui.Image) event.getSource();
61
				ouvrirFenetreModale(new DetailImagePresenteur(photo.getTitle(), photo.getAltText()));
62
			}
63
		});
242 gduche 64
		vue.enSavoirPlus.addClickHandler(new ClickHandler() {
178 benjamin 65
 
66
			@Override
67
			public void onClick(ClickEvent event) {
68
 
69
				if (!detailsOpen) {
70
					afficherDetails();
71
				} else {
72
					cacherDetails();
73
				}
74
			}
75
		});
76
 
242 gduche 77
		vue.ajoutValidation.addClickHandler(new ClickHandler() {
178 benjamin 78
 
79
			@Override
80
			public void onClick(ClickEvent event) {
81
				BusEvenementiel.getInstance().fireEvent(new EvenementValidation(image));
82
			}
83
		});
84
	}
85
 
86
	public void cacherDetails() {
250 gduche 87
		ImageVue vue = (ImageVue) this.getVue();
242 gduche 88
		VerticalPanel zoneCache = vue.zoneCache;
89
		Label enSavoirPlus = vue.enSavoirPlus;
178 benjamin 90
 
91
		zoneCache.setVisible(false);
92
		enSavoirPlus.setStyleName("boutonPlus");
93
 
94
		detailsOpen = false;
95
	}
96
 
97
	public void afficherDetails() {
250 gduche 98
		ImageVue vue = (ImageVue) this.getVue();
178 benjamin 99
		ResultatRechercheImagePresenteur.getInstance().fermerTousPanneauxDetailsObservations();
100
 
242 gduche 101
		VerticalPanel zoneCache = vue.zoneCache;
102
		Label enSavoirPlus = vue.enSavoirPlus;
178 benjamin 103
 
104
		zoneCache.setVisible(true);
105
		enSavoirPlus.setStyleName("boutonMoins");
106
 
107
		detailsOpen = true;
108
	}
109
 
110
	public boolean isDetailsOpen() {
111
		return detailsOpen;
112
	}
113
 
114
}