1,9 → 1,8 |
package org.tela_botanica.del.client.composants.moteurrecherche; |
|
import java.util.HashMap; |
|
import org.tela_botanica.del.client.cache.CacheClient; |
import org.tela_botanica.del.client.composants.presenteur.Presenteur; |
import org.tela_botanica.del.client.i18n.I18n; |
import org.tela_botanica.del.client.modeles.InformationsRecherche; |
|
import com.google.gwt.event.dom.client.ClickEvent; |
import com.google.gwt.event.dom.client.ClickHandler; |
12,36 → 11,68 |
import com.google.gwt.event.dom.client.KeyCodes; |
import com.google.gwt.event.dom.client.KeyPressEvent; |
import com.google.gwt.event.dom.client.KeyPressHandler; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.HasText; |
import com.google.gwt.user.client.ui.HasWidgets; |
import com.google.gwt.user.client.ui.IsWidget; |
|
public abstract class MoteurRecherchePresenteur extends Presenteur { |
|
|
public abstract interface Vue extends IsWidget { |
|
public abstract HasClickHandlers getLienRechercheAvancee(); |
|
public abstract void basculerAffichageZoneCache(); |
|
public abstract HasClickHandlers getBoutonRechercheSimple(); |
|
public abstract HasClickHandlers getBoutonRechercheAvancee(); |
|
public abstract HasKeyPressHandlers getChampSaisie(); |
|
public abstract HasClickHandlers getChampSaisieCliquable(); |
|
public abstract String getValeurRechercheSimple(); |
|
public void setValeurRechercheSimple(String valeurRecherche); |
|
public String getLabelRecherche(); |
public abstract HashMap<String, String> collecterFormulaire(); |
public String getChaineRecherche(); |
public abstract void setRecherchePrecedente(); |
|
public HasText getRecherchePrincipale(); |
|
public HasText getDepartement(); |
|
public HasText getCommune(); |
|
public HasText getTaxon(); |
|
public HasText getFamille(); |
|
public HasText getGenre(); |
|
public HasText getTag(); |
|
public HasText getMotCle(); |
|
public HasText getAuteur(); |
|
public HasText getDate(); |
|
public void chargerValeursRecherchePrecedente(InformationsRecherche informationsRecherche); |
} |
|
private Vue vue; |
|
public MoteurRecherchePresenteur(Vue vue) { |
private final Vue vue; |
private final boolean pourRechercheImages, pourRechercheObservations; |
|
public MoteurRecherchePresenteur(Vue vue, boolean pourRechercheImages, boolean pourRechercheObservations) { |
this.vue = vue; |
this.pourRechercheImages = pourRechercheImages; |
this.pourRechercheObservations = pourRechercheObservations; |
gererEvenements(); |
} |
|
|
@Override |
public void go(HasWidgets composite) { |
afficherRequeteEtLancerRecherche(); |
composite.add(vue.asWidget()); |
} |
|
52,33 → 83,34 |
vue.basculerAffichageZoneCache(); |
} |
}); |
|
|
vue.getBoutonRechercheSimple().addClickHandler(new ClickHandler() { |
public void onClick(ClickEvent event) { |
afficherInfoRecherche(); |
lancerRecherche(vue.getChaineRecherche()); |
collecterInfosRecherche(); |
afficherRequeteEtLancerRecherche(); |
} |
}); |
|
|
vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() { |
public void onClick(ClickEvent event) { |
afficherInfoRecherche(); |
lancerRecherche(vue.getChaineRecherche()); |
collecterInfosRecherche(); |
vue.basculerAffichageZoneCache(); |
afficherRequeteEtLancerRecherche(); |
} |
}); |
|
|
vue.getChampSaisie().addKeyPressHandler(new KeyPressHandler() { |
|
|
public void onKeyPress(KeyPressEvent event) { |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { |
afficherInfoRecherche(); |
lancerRecherche(vue.getChaineRecherche()); |
collecterInfosRecherche(); |
afficherRequeteEtLancerRecherche(); |
} |
} |
}); |
|
|
vue.getChampSaisieCliquable().addClickHandler(new ClickHandler() { |
|
|
@Override |
public void onClick(ClickEvent event) { |
if (vue.getValeurRechercheSimple().equals(vue.getLabelRecherche())) { |
86,12 → 118,52 |
} |
} |
}); |
|
} |
|
private void afficherInfoRecherche() { |
vue.setRecherchePrecedente(); |
|
private void collecterInfosRecherche() { |
InformationsRecherche informationRecherche = new InformationsRecherche(); |
informationRecherche.setAuteur(vue.getAuteur().getText()); |
informationRecherche.setCommune(vue.getCommune().getText()); |
informationRecherche.setDate(vue.getDate().getText()); |
informationRecherche.setDepartement(vue.getDepartement().getText()); |
informationRecherche.setFamille(vue.getFamille().getText()); |
informationRecherche.setGenre(vue.getGenre().getText()); |
informationRecherche.setMotClef(vue.getMotCle().getText()); |
|
if (!vue.getRecherchePrincipale().getText().equals(vue.getLabelRecherche())) { |
informationRecherche.setRechercheLibre(vue.getRecherchePrincipale().getText()); |
} |
if (isPourRechercheImages()) { |
CacheClient.getInstance().setInformationsRechercheImage(informationRecherche); |
} else if (isPourRechercheObservations()) { |
CacheClient.getInstance().setInformationsRechercheObservation(informationRecherche); |
} |
} |
|
public abstract void lancerRecherche(String termeRecherche); |
|
private InformationsRecherche getInformationsRechercheEnCache() { |
if (isPourRechercheImages()) { |
return CacheClient.getInstance().getInformationsRechercheImage(); |
} else if (isPourRechercheObservations()) { |
return CacheClient.getInstance().getInformationsRechercheObservation(); |
} |
return null; |
} |
|
public void afficherRequeteEtLancerRecherche() { |
InformationsRecherche informationsRecherche = getInformationsRechercheEnCache(); |
if (informationsRecherche != null) { |
vue.chargerValeursRecherchePrecedente(informationsRecherche); |
} |
lancerRecherche(); |
} |
|
public abstract void lancerRecherche(); |
|
public boolean isPourRechercheImages() { |
return pourRechercheImages; |
} |
|
public boolean isPourRechercheObservations() { |
return pourRechercheObservations; |
} |
} |