Rev 73 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.del.client.vues.rechercheobservations;
import java.util.List;
import org.tela_botanica.del.client.modeles.Observation;
import org.tela_botanica.del.client.modeles.ObservationValidation;
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
import org.tela_botanica.del.client.navigation.evenement.validationobservation.EvenementValidation;
import org.tela_botanica.del.client.utils.MockDatasource;
import org.tela_botanica.del.client.vues.rechercheobservations.vote.MoyenneVotePresenteur;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
public class ObservationPresenteur {
private final MockDatasource validationService = MockDatasource.getInstance();
private ObservationVue vue = new ObservationVue();
private final Observation observation;
private boolean detailsOpen = false;
public ObservationPresenteur(Observation observation) {
this.observation = observation;
}
public void go(HasWidgets composite) {
composite.add(vue);
vue.loadImage(observation);
loadValidationData();
handleEvents();
}
private void loadValidationData() {
List<ObservationValidation> observationValidationDatas = validationService.getValidationData(observation.getIdImage());
observation.setImageCelValidationDatas(observationValidationDatas);
new MoyenneVotePresenteur(observationValidationDatas).go(vue.getVoter());
vue.showValidationData(observationValidationDatas);
}
private void handleEvents() {
vue.getEnSavoirPlus().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (!detailsOpen) {
afficherDetails();
} else {
cacherDetails();
}
}
});
vue.getImagePrincipale().addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
BusEvenementiel.getInstance().fireEvent(new EvenementValidation(observation));
}
});
}
public void cacherDetails() {
VerticalPanel zoneCache = vue.getZoneCache();
Label enSavoirPlus = vue.getEnSavoirPlus();
zoneCache.setVisible(false);
enSavoirPlus.setStyleName("boutonPlus");
detailsOpen=false;
}
public void afficherDetails() {
ObservationRecherchePresenteur.getInstance().fermerTousPanneauxDetailsObservations();
VerticalPanel zoneCache = vue.getZoneCache();
Label enSavoirPlus = vue.getEnSavoirPlus();
zoneCache.setVisible(true);
enSavoirPlus.setStyleName("boutonMoins");
detailsOpen=true;
}
public boolean isDetailsOpen() {
return detailsOpen;
}
public ObservationVue getVue() {
return vue;
}
}