Subversion Repositories eFlore/Applications.del

Rev

Rev 243 | 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
 
6
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
7
import org.tela_botanica.del.client.modeles.Observation;
183 gduche 8
import org.tela_botanica.del.client.modeles.PropositionDetermination;
166 gduche 9
 
200 gduche 10
import com.google.gwt.event.dom.client.ClickEvent;
11
import com.google.gwt.event.dom.client.ClickHandler;
309 aurelien 12
import com.google.gwt.event.dom.client.HasClickHandlers;
13
import com.google.gwt.user.client.ui.FlexTable;
14
import com.google.gwt.user.client.ui.HasText;
166 gduche 15
import com.google.gwt.user.client.ui.HasWidgets;
200 gduche 16
import com.google.gwt.user.client.ui.Image;
309 aurelien 17
import com.google.gwt.user.client.ui.IsWidget;
18
import com.google.gwt.user.client.ui.Label;
19
import com.google.gwt.user.client.ui.Panel;
166 gduche 20
 
21
public class ObservationPresenteur extends Presenteur {
309 aurelien 22
 
23
	public abstract interface Vue extends IsWidget {
24
		public HasText getAuteur();
25
		public HasText getDate();
26
		public HasText getFamille();
27
		public HasText getLocalite();
28
		public HasText getMotsClefs();
29
		public HasText getNomRetenu();
30
		public HasText getNumNomenclatural();
31
		public FlexTable getTableauPropositions();
32
		public HasClickHandlers getPhotoPrincipale();
33
		public HasWidgets getPhotos();
34
		public void setUrlImagePrincipale(String url);
35
		public void setTitreImagePrincipale(String titre);
36
		public void setAltTextImagePrincipale(String altText);
37
		public String getUrlImagePrincipale();
38
		public String getTitreImagePrincipale();
39
		public String getAltTextImagePrincipale();
40
		public void setTexteTableau(int ligne, int colonne, String texte);
41
	}
42
 
43
	private Vue vue;
166 gduche 44
 
45
	private Observation observation;
46
 
309 aurelien 47
	public ObservationPresenteur(Vue vue, Observation observation) {
166 gduche 48
		this.observation = observation;
49
		chargerObservation();
50
	}
51
 
52
	public void chargerObservation() {
309 aurelien 53
		vue.getAuteur().setText(observation.getAuteur());
54
		vue.getDate().setText(observation.getDate());
55
		vue.getFamille().setText(observation.getFamille());
56
		vue.getLocalite().setText(observation.getLocalite());
166 gduche 57
 
58
		List<String> motsCles = observation.getMotsClefs();
59
		Iterator<String> itMotsCles = motsCles.iterator();
60
		String motsClesChaine = "";
61
		while (itMotsCles.hasNext()) {
62
			String motCle = itMotsCles.next();
63
			motsClesChaine += motCle;
64
			if (itMotsCles.hasNext()) {
65
				motsClesChaine += ", ";
66
			}
67
		}
309 aurelien 68
		vue.getMotsClefs().setText(motsClesChaine);
69
		vue.getNomRetenu().setText(observation.getNomRetenu());
70
		vue.getNumNomenclatural().setText(observation.getNumNomenclatural());
166 gduche 71
 
200 gduche 72
		List<org.tela_botanica.del.client.modeles.Image> images = observation.getImages();
183 gduche 73
 
243 gduche 74
		if (images != null && images.size() > 0) {
75
			org.tela_botanica.del.client.modeles.Image imagePrincipale = images.get(0);
309 aurelien 76
			vue.setUrlImagePrincipale(imagePrincipale.getUrl());
77
			vue.setTitreImagePrincipale(imagePrincipale.getUrlFormat("L"));
78
			vue.setAltTextImagePrincipale(observation.getAuteur() + " - " + observation.getNomRetenu());
243 gduche 79
			images.remove(0);
80
		}
200 gduche 81
 
82
		int nbImagesAffichees = 0;
83
		for (org.tela_botanica.del.client.modeles.Image imageCourante : images) {
84
			nbImagesAffichees++;
85
			if (nbImagesAffichees < 5) {
86
				Image photo = new Image();
87
				photo.setUrl(imageCourante.getUrlFormat("CRX2S"));
88
				photo.setTitle(imageCourante.getUrlFormat("L"));
89
				photo.setAltText(observation.getAuteur() + " - " + observation.getNomRetenu());
90
				photo.addClickHandler(new ClickHandler() {
91
 
92
					public void onClick(ClickEvent event) {
93
						Image photo = (Image) event.getSource();
309 aurelien 94
						ouvrirFenetreModale(new DetailImagePresenteur(vue.getTitreImagePrincipale(), vue.getAltTextImagePrincipale(), new DetailImageVue()));
200 gduche 95
					}
96
				});
309 aurelien 97
				vue.getPhotos().add(photo);
200 gduche 98
			}
99
		}
100
 
183 gduche 101
		List<PropositionDetermination> propositions = observation.getPropositionsDetermination();
102
 
309 aurelien 103
		vue.setTexteTableau(0, 0, "Certitude");
104
		vue.setTexteTableau(0, 1, "Commentaires");
105
		vue.setTexteTableau(0, 2, "Nom");
106
		vue.setTexteTableau(0, 3, "Votez");
183 gduche 107
 
108
		int i = 0;
109
		for (PropositionDetermination proposition : propositions) {
110
			i++;
309 aurelien 111
			vue.setTexteTableau(i, 0, String.valueOf(proposition.getVotesDeterminations().size()));
200 gduche 112
			/*
113
			 * List<VoteDetermination> votes =
114
			 * proposition.getVotesDeterminations(); for (VoteDetermination vote
115
			 * : votes) { vote.getVote(); }
116
			 */
309 aurelien 117
			vue.setTexteTableau(i, 1, String.valueOf(proposition.getListeCommentaires().size()));
118
			vue.setTexteTableau(i, 2, proposition.getEspece());
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() {
166 gduche 131
 
200 gduche 132
			public void onClick(ClickEvent event) {
309 aurelien 133
				//FIXME : faire une interface pour les images
134
				//Image photoPrincipale = (Image) event.getSource();
135
				//ouvrirFenetreModale(new DetailImagePresenteur(photoPrincipale.getTitreImagePrincipale(), vue.getAltTextImagePrincipale(), new DetailImageVue()));
200 gduche 136
			}
137
		});
138
 
166 gduche 139
	}
140
}