Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
166 gduche 1
package org.tela_botanica.del.client.vues.rechercheobservations;
2
 
3
import java.util.Iterator;
4
import java.util.List;
5
 
332 gduche 6
import org.tela_botanica.del.client.cache.CacheClient;
166 gduche 7
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
337 gduche 8
import org.tela_botanica.del.client.i18n.I18n;
332 gduche 9
import org.tela_botanica.del.client.modeles.Image;
166 gduche 10
import org.tela_botanica.del.client.modeles.Observation;
183 gduche 11
import org.tela_botanica.del.client.modeles.PropositionDetermination;
332 gduche 12
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
13
import org.tela_botanica.del.client.navigation.evenement.validationobservation.EvenementValidation;
334 gduche 14
import org.tela_botanica.del.client.vues.rechercheobservations.detail.DetailVoteObservationPresenteur;
15
import org.tela_botanica.del.client.vues.rechercheobservations.detail.DetailVoteObservationVue;
166 gduche 16
 
200 gduche 17
import com.google.gwt.event.dom.client.ClickEvent;
18
import com.google.gwt.event.dom.client.ClickHandler;
309 aurelien 19
import com.google.gwt.event.dom.client.HasClickHandlers;
334 gduche 20
import com.google.gwt.user.client.ui.HTMLPanel;
309 aurelien 21
import com.google.gwt.user.client.ui.HasText;
166 gduche 22
import com.google.gwt.user.client.ui.HasWidgets;
309 aurelien 23
import com.google.gwt.user.client.ui.IsWidget;
166 gduche 24
 
25
public class ObservationPresenteur extends Presenteur {
309 aurelien 26
 
27
	public abstract interface Vue extends IsWidget {
316 aurelien 28
		public void ajouterPhoto(String url, String titre, String alText, ClickHandler GestionnaireClic);
309 aurelien 29
		public HasText getAuteur();
30
		public HasText getDate();
31
		public HasText getFamille();
32
		public HasText getLocalite();
33
		public HasText getMotsClefs();
34
		public HasText getNomRetenu();
35
		public HasText getNumNomenclatural();
36
		public HasClickHandlers getPhotoPrincipale();
37
		public HasWidgets getPhotos();
38
		public void setUrlImagePrincipale(String url);
39
		public void setTitreImagePrincipale(String titre);
40
		public void setAltTextImagePrincipale(String altText);
41
		public String getUrlImagePrincipale();
42
		public String getTitreImagePrincipale();
43
		public String getAltTextImagePrincipale();
44
		public void setTexteTableau(int ligne, int colonne, String texte);
334 gduche 45
		public void setElementTableau(int ligne, int colonne, IsWidget element);
332 gduche 46
		public HasClickHandlers getLienDeterminer();
309 aurelien 47
	}
48
 
49
	private Vue vue;
166 gduche 50
 
51
	private Observation observation;
52
 
309 aurelien 53
	public ObservationPresenteur(Vue vue, Observation observation) {
166 gduche 54
		this.observation = observation;
314 gduche 55
		this.vue = vue;
166 gduche 56
		chargerObservation();
57
	}
58
 
59
	public void chargerObservation() {
314 gduche 60
		HasText auteur = vue.getAuteur();
61
		auteur.setText(observation.getAuteur());
309 aurelien 62
		vue.getDate().setText(observation.getDate());
63
		vue.getFamille().setText(observation.getFamille());
64
		vue.getLocalite().setText(observation.getLocalite());
166 gduche 65
 
66
		List<String> motsCles = observation.getMotsClefs();
67
		Iterator<String> itMotsCles = motsCles.iterator();
68
		String motsClesChaine = "";
69
		while (itMotsCles.hasNext()) {
70
			String motCle = itMotsCles.next();
71
			motsClesChaine += motCle;
72
			if (itMotsCles.hasNext()) {
73
				motsClesChaine += ", ";
74
			}
75
		}
309 aurelien 76
		vue.getMotsClefs().setText(motsClesChaine);
77
		vue.getNomRetenu().setText(observation.getNomRetenu());
78
		vue.getNumNomenclatural().setText(observation.getNumNomenclatural());
166 gduche 79
 
200 gduche 80
		List<org.tela_botanica.del.client.modeles.Image> images = observation.getImages();
183 gduche 81
 
243 gduche 82
		if (images != null && images.size() > 0) {
83
			org.tela_botanica.del.client.modeles.Image imagePrincipale = images.get(0);
309 aurelien 84
			vue.setUrlImagePrincipale(imagePrincipale.getUrl());
85
			vue.setTitreImagePrincipale(imagePrincipale.getUrlFormat("L"));
86
			vue.setAltTextImagePrincipale(observation.getAuteur() + " - " + observation.getNomRetenu());
243 gduche 87
			images.remove(0);
88
		}
200 gduche 89
 
90
		int nbImagesAffichees = 0;
91
		for (org.tela_botanica.del.client.modeles.Image imageCourante : images) {
92
			nbImagesAffichees++;
93
			if (nbImagesAffichees < 5) {
316 aurelien 94
				ClickHandler gestionnaireClic = new ClickHandler() {
200 gduche 95
					public void onClick(ClickEvent event) {
316 aurelien 96
						IsWidget image = (IsWidget)event.getSource();
97
						ouvrirFenetreModale(new DetailImagePresenteur(image, new DetailImageVue()));
200 gduche 98
					}
316 aurelien 99
				};
100
				vue.ajouterPhoto(imageCourante.getUrlFormat("CRX2S"),
101
								 imageCourante.getUrlFormat("L"),
102
								 observation.getAuteur() + " - " + observation.getNomRetenu(),
103
								 gestionnaireClic);
200 gduche 104
			}
105
		}
106
 
183 gduche 107
		List<PropositionDetermination> propositions = observation.getPropositionsDetermination();
108
 
109
 
110
		int i = 0;
111
		for (PropositionDetermination proposition : propositions) {
337 gduche 112
 
334 gduche 113
			HTMLPanel panneau = new HTMLPanel("");
114
			DetailVoteObservationPresenteur presenteurVote = new DetailVoteObservationPresenteur(new DetailVoteObservationVue(), proposition);
115
			presenteurVote.go(panneau);
116
			vue.setElementTableau(i, 0, panneau);
337 gduche 117
			vue.setTexteTableau(i, 1, String.valueOf(proposition.getListeCommentaires().size()) + " " +I18n.getVocabulary().commentaires());
118
			i++;
183 gduche 119
		}
120
 
220 gduche 121
		gererEvenements();
183 gduche 122
		// vue.propositions.setText(ch);
166 gduche 123
	}
124
 
125
	public void go(HasWidgets composite) {
309 aurelien 126
		composite.add(vue.asWidget());
166 gduche 127
	}
128
 
220 gduche 129
	protected void gererEvenements() {
309 aurelien 130
		vue.getPhotoPrincipale().addClickHandler(new ClickHandler() {
200 gduche 131
			public void onClick(ClickEvent event) {
309 aurelien 132
				//FIXME : faire une interface pour les images
316 aurelien 133
				IsWidget image = (IsWidget)event.getSource();
134
				ouvrirFenetreModale(new DetailImagePresenteur(image, new DetailImageVue()));
200 gduche 135
			}
136
		});
332 gduche 137
 
138
		vue.getLienDeterminer().addClickHandler(new ClickHandler() {
139
 
140
			public void onClick(ClickEvent event) {
141
				List<Image> images = observation.getImages();
142
				if (images.size() > 0) {
143
					CacheClient.getInstance().setImageCourante(images.get(0));
144
				} else {
145
					CacheClient.getInstance().setImageCourante(null);
146
				}
147
				BusEvenementiel.getInstance().fireEvent(new EvenementValidation(observation));
148
			}
149
		});
166 gduche 150
	}
151
}