Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1195 → Rev 1196

/trunk/src/org/tela_botanica/del/client/vues/pictoflora/resultats/ResultatPictofloraPresenteur.java
New file
0,0 → 1,392
package org.tela_botanica.del.client.vues.pictoflora.resultats;
 
import java.util.List;
 
import org.tela_botanica.del.client.cache.CacheClient;
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
import org.tela_botanica.del.client.modeles.Image;
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
import org.tela_botanica.del.client.modeles.InformationsRecherche;
import org.tela_botanica.del.client.modeles.ModeTri;
import org.tela_botanica.del.client.modeles.Protocole;
import org.tela_botanica.del.client.modeles.ProtocoleServiceResultat;
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.GestionnaireEvenementChangementProtocole;
import org.tela_botanica.del.client.services.rest.ImageService;
import org.tela_botanica.del.client.services.rest.ProtocoleService;
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
import org.tela_botanica.del.client.services.rest.async.ProtocolesCallback;
import org.tela_botanica.del.client.vues.pictoflora.resultats.images.ImagePresenteur;
import org.tela_botanica.del.client.vues.pictoflora.resultats.images.ImageVue;
 
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasChangeHandlers;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.IsWidget;
import com.google.gwt.user.client.ui.ListBox;
 
public class ResultatPictofloraPresenteur {
public interface Vue extends IsWidget {
public void startChargement();
 
public void nettoyer();
 
public void creerPanneauxObservations(int size);
 
public void stopChargement();
 
public List<HasWidgets> getPanneauxImages();
 
public HasWidgets getPanneauPagination();
 
public HasWidgets getPanneauPaginationHaut();
 
public HasClickHandlers getTriParNbVotesAscendant();
 
public HasClickHandlers getTriParNbVotesDescendant();
 
public HasClickHandlers getTriParDateAscendant();
 
public HasClickHandlers getTriParDateDescendant();
public HasClickHandlers getTriParNbTagsAscendant();
 
public HasClickHandlers getTriParNbTagsDescendant();
 
public void afficherElementsAucunResultatTrouve();
 
public void afficherElementsResultatsTrouve();
 
public HTMLPanel getImageTable();
 
public String getNomProtocoleSelectionne();
 
public int getIdProtocoleSelectionne();
 
public void setListeProtocoles(ListBox listeProtocoles);
 
public HasChangeHandlers getListeProtocoles();
public void ajouterProtocoles(List<Protocole> protocoles);
 
public void selectionnerProtocole(int index);
 
public HasClickHandlers getLabelVote();
 
public void masquerVoteAscendant();
 
public void masquerVoteDescendant();
 
public void afficherVoteAscendant();
 
public void afficherVoteDescendant();
 
public HasClickHandlers getLabelDate();
public HasClickHandlers getLabelTag();
 
public void masquerDateAscendant();
 
public void masquerDateDescendant();
 
public void afficherDateAscendant();
 
public void afficherDateDescendant();
 
public void masquerTagAscendant();
 
public void afficherTagDescendant();
 
public void masquerTagDescendant();
 
public void afficherTagAscendant();
 
public void mettreAJourDescriptionProtocoleCourant(
Protocole protocoleCourant);
}
 
private Vue vue;
private ImageService imageService;
private final ProtocoleService protocoleService;
private List<Protocole> protocoles;
private ModeTri triCourantVote = ModeTri.TRI_ASCENDANT;
private ModeTri triCourantDate = ModeTri.TRI_DESCENDANT;
private ModeTri triCourantTag = ModeTri.TRI_DESCENDANT;
 
public ResultatPictofloraPresenteur(ImageService imageService, ProtocoleService protocoleService, Vue vue) {
this.vue = vue;
this.imageService = imageService;
this.protocoleService=protocoleService;
}
 
public void go(HasWidgets composite) {
composite.add(vue.asWidget());
vue.startChargement();
rechercherImagesEtCreerWidgetPagination();
gererEvenements();
chargerProtocoles();
vue.masquerVoteDescendant();
vue.masquerVoteAscendant();
// vue.masquerDateDescendant();
vue.masquerDateAscendant();
vue.masquerTagAscendant();
vue.masquerTagDescendant();
}
 
public void gererEvenements() {
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
surChangementProtocole();
}
});
 
ClickHandler surClicTriVote = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
surClicTriVote();
}
};
 
vue.getLabelVote().addClickHandler(surClicTriVote);
vue.getTriParNbVotesAscendant().addClickHandler(surClicTriVote);
vue.getTriParNbVotesDescendant().addClickHandler(surClicTriVote);
 
ClickHandler surClicTriDate = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
surClicTriDate();
}
};
 
vue.getLabelDate().addClickHandler(surClicTriDate);
vue.getTriParDateAscendant().addClickHandler(surClicTriDate);
vue.getTriParDateDescendant().addClickHandler(surClicTriDate);
ClickHandler surClicTriTag = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
surClicTriTag();
}
};
vue.getLabelTag().addClickHandler(surClicTriTag);
vue.getTriParNbTagsAscendant().addClickHandler(surClicTriTag);
vue.getTriParNbTagsDescendant().addClickHandler(surClicTriTag);
 
BusEvenementiel.getInstance().addHandler(EvenementChangementProtocole.TYPE, new GestionnaireEvenementChangementProtocole() {
@Override
public void onChangementProtocole(EvenementChangementProtocole event) {
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
if (informationsRechercheImages.getTriParNbVotes() != ModeTri.PAS_DE_TRI) {
informationsRechercheImages.setIdProtocoleSelectionne(event.getProtocole().getId() + "");
chargerEtAfficherImagesPageEnCours();
}
}
});
}
 
protected void surClicTriTag() {
vue.masquerDateDescendant();
vue.masquerDateAscendant();
vue.masquerVoteDescendant();
vue.masquerVoteAscendant();
if (triCourantTag == ModeTri.TRI_ASCENDANT) {
triCourantTag = ModeTri.TRI_DESCENDANT;
vue.masquerTagAscendant();
vue.afficherTagDescendant();
} else {
triCourantTag = ModeTri.TRI_ASCENDANT;
vue.masquerTagDescendant();
vue.afficherTagAscendant();
}
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
informationsRechercheImages.setTriParNbTags(triCourantTag);
informationsRechercheImages.setTriParDate(ModeTri.PAS_DE_TRI);
informationsRechercheImages.setTriParNbVotes(ModeTri.PAS_DE_TRI);
chargerEtAfficherImagesPageEnCours();
}
 
public void surClicTriVote() {
vue.masquerDateDescendant();
vue.masquerDateAscendant();
vue.masquerTagAscendant();
vue.masquerTagDescendant();
if (triCourantVote == ModeTri.TRI_ASCENDANT) {
triCourantVote = ModeTri.TRI_DESCENDANT;
vue.masquerVoteAscendant();
vue.afficherVoteDescendant();
} else {
triCourantVote = ModeTri.TRI_ASCENDANT;
vue.masquerVoteDescendant();
vue.afficherVoteAscendant();
}
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
int IdProtocole = CacheClient.getInstance().getProtocoleCourant().getId();
informationsRechercheImages.setTriParNbVotes(triCourantVote);
informationsRechercheImages.setIdProtocoleSelectionne(IdProtocole + "");
informationsRechercheImages.setTriParDate(ModeTri.PAS_DE_TRI);
informationsRechercheImages.setTriParNbTags(ModeTri.PAS_DE_TRI);
chargerEtAfficherImagesPageEnCours();
}
 
public void surClicTriDate() {
vue.masquerVoteDescendant();
vue.masquerVoteAscendant();
if (triCourantDate == ModeTri.TRI_ASCENDANT) {
triCourantDate = ModeTri.TRI_DESCENDANT;
vue.masquerDateAscendant();
vue.afficherDateDescendant();
} else {
triCourantDate = ModeTri.TRI_ASCENDANT;
vue.masquerDateDescendant();
vue.afficherDateAscendant();
}
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
informationsRechercheImages.setTriParDate(triCourantDate);
informationsRechercheImages.setTriParNbVotes(ModeTri.PAS_DE_TRI);
informationsRechercheImages.setTriParNbTags(ModeTri.PAS_DE_TRI);
chargerEtAfficherImagesPageEnCours();
}
 
public void surChangementProtocole() {
Protocole protocoleCourant = null;
for (Protocole protocole : protocoles) {
if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
protocoleCourant = protocole;
}
}
vue.mettreAJourDescriptionProtocoleCourant(protocoleCourant);
CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
BusEvenementiel.getInstance().fireEvent(evenement);
}
 
private void chargerProtocoles() {
// test pour ne pas charger les protocoles déjà chargés
// TODO: faire un systeme de cache gérés par les web service eux même
if (CacheClient.getInstance().getListeProtocoles() == null) {
protocoleService.getProtocoles(new ProtocolesCallback() {
 
@Override
public void surRetour(ProtocoleServiceResultat protocolesRecus) {
protocoles = protocolesRecus.getProtocoles();
remplirListeProtocole(protocoles);
 
}
});
} else {
protocoles = CacheClient.getInstance().getListeProtocoles();
remplirListeProtocole(CacheClient.getInstance().getListeProtocoles());
}
}
 
private void remplirListeProtocole(List<Protocole> protocoles) {
vue.ajouterProtocoles(protocoles);
if (CacheClient.getInstance().getProtocoleCourant() == null) {
vue.selectionnerProtocole(0);
vue.mettreAJourDescriptionProtocoleCourant(protocoles.get(0));
} else {
vue.mettreAJourDescriptionProtocoleCourant(CacheClient.getInstance().getProtocoleCourant());
}
}
 
public void rechercherImagesEtCreerWidgetPagination() {
// appel du service d'image pour avoir le nb total d'elements pour la
// pagination
ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
 
@Override
public void surRetour(ImageServiceResultat imagesRecues) {
creerWidgetPagination(imagesRecues.getNbTotalImagesPourLaRecherche());
afficherImages(imagesRecues);
 
}
 
@Override
public void surErreur(String messageErreur) {
Window.alert(messageErreur);
 
}
};
final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), debut, fin, callback);
}
 
private void chargerEtAfficherImages(final int premier, final int dernier) {
vue.startChargement();
vue.nettoyer();
ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
 
@Override
public void surRetour(ImageServiceResultat imagesRecues) {
afficherImages(imagesRecues);
}
 
@Override
public void surErreur(String messageErreur) {
Window.alert(messageErreur);
}
 
};
imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), premier, dernier, callback);
}
 
public void afficherImages(ImageServiceResultat imageServiceResult) {
List<Image> images = imageServiceResult.getImages();
if (images == null || images.size() == 0) {
vue.afficherElementsAucunResultatTrouve();
} else {
vue.afficherElementsResultatsTrouve();
for (Image image : images) {
ImagePresenteur imagePresenteur = new ImagePresenteur(image, CacheClient.getInstance().getProtocoleCourant(), new ImageVue());
imagePresenteur.go(vue.getImageTable());
}
}
vue.stopChargement();
}
 
private void creerWidgetPagination(int nbImages) {
PaginationPresenteur imagesPaginationPresenteurHaut = creerPresenteurPagination(nbImages);
PaginationPresenteur imagesPaginationPresenteurBas = creerPresenteurPagination(nbImages);
imagesPaginationPresenteurHaut.setGroupePagination("pagination_images");
imagesPaginationPresenteurBas.setGroupePagination("pagination_images");
imagesPaginationPresenteurHaut.go(vue.getPanneauPaginationHaut());
imagesPaginationPresenteurBas.go(vue.getPanneauPagination());
}
 
public PaginationPresenteur creerPresenteurPagination(int nbImages) {
PaginationPresenteur imagesPaginationPresenteur = new PaginationPresenteur(new PaginationVue(), nbImages, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance().getPageCouranteRechercheImage()) {
@Override
public void chargerElements(int debut, int fin) {
chargerEtAfficherImages(debut, fin);
CacheClient.getInstance().setPageCouranteRechercheImages(getPageCourante());
}
 
@Override
public void actualiserPasCache(int pas) {
CacheClient.getInstance().setPasPagination(pas);
}
};
return imagesPaginationPresenteur;
}
 
public void chargerEtAfficherImagesPageEnCours() {
final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
chargerEtAfficherImages(debut, fin);
}
 
public Vue getVue() {
return vue;
}
}