10,10 → 10,17 |
|
import com.google.gwt.event.dom.client.ClickEvent; |
import com.google.gwt.event.dom.client.ClickHandler; |
import com.google.gwt.event.dom.client.HasClickHandlers; |
import com.google.gwt.event.dom.client.HasKeyPressHandlers; |
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.ui.Button; |
import com.google.gwt.user.client.ui.HasText; |
import com.google.gwt.user.client.ui.HasVisibility; |
import com.google.gwt.user.client.ui.HasWidgets; |
import com.google.gwt.user.client.ui.IsWidget; |
import com.google.gwt.user.client.ui.Label; |
import com.google.gwt.user.client.ui.Panel; |
import com.google.gwt.user.client.ui.RootPanel; |
import com.google.gwt.user.client.ui.TextBox; |
20,10 → 27,34 |
|
public class RechercheObservationsPresenteur extends Presenteur { |
|
public abstract interface Vue extends IsWidget { |
public HasClickHandlers getRecherchePrincipaleHasClickHandler(); |
public HasKeyPressHandlers getRecherchePrincipaleHasKeyPressHandlers(); |
public HasText getRecherchePrincipaleHasText(); |
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 HasClickHandlers getBoutonRecherche(); |
public HasClickHandlers getBoutonRechercheAvancee(); |
public HasClickHandlers getLienRechercheAvancee(); |
public HasText getRecherchePrecedente(); |
public HasWidgets getRechercheAvanceeHasWidget(); |
public HasVisibility getRechercheAvanceeHasVisibility(); |
public HasWidgets getZoneObservations(); |
public HasWidgets getZonePagination(); |
} |
private Vue vue; |
|
private List<Observation> observations; |
|
public RechercheObservationsPresenteur() { |
super(new RechercheObservationsVue()); |
public RechercheObservationsPresenteur(Vue vue) { |
this.vue = vue; |
} |
|
public void go(HasWidgets composite) { |
30,7 → 61,7 |
if (composite == null) { |
composite = RootPanel.get(); |
} |
composite.add(this.getVue()); |
composite.add(vue.asWidget()); |
gererEvenements(); |
|
// On commence par afficher la totalité des observations |
40,13 → 71,11 |
|
protected void gererEvenements() { |
|
RechercheObservationsVue vue = (RechercheObservationsVue) getVue(); |
|
// Gestion du clic dans la zone de saisie |
vue.recherchePrincipale.addClickHandler(new ClickHandler() { |
vue.getRecherchePrincipaleHasClickHandler().addClickHandler(new ClickHandler() { |
|
public void onClick(ClickEvent event) { |
TextBox recherchePrincipale = (TextBox) event.getSource(); |
HasText recherchePrincipale = (HasText) event.getSource(); |
if (recherchePrincipale.getText().equals("Recherche libre")) { |
recherchePrincipale.setText(""); |
} |
54,10 → 83,10 |
}); |
|
// Gestion de l'affichage de la recherche Avancée |
vue.lienRechercheAvancee.addClickHandler(new ClickHandler() { |
vue.getLienRechercheAvancee().addClickHandler(new ClickHandler() { |
|
public void onClick(ClickEvent event) { |
Panel rechercheAvancee = ((RechercheObservationsVue) getVue()).rechercheAvancee; |
HasVisibility rechercheAvancee = vue.getRechercheAvanceeHasVisibility(); |
rechercheAvancee.setVisible(!rechercheAvancee.isVisible()); |
} |
}); |
64,7 → 93,7 |
|
// Gestion de l'évènement recherche sur le clic ou sur l'appui de la |
// touche Entrée |
vue.boutonRecherche.addClickHandler(new ClickHandler() { |
vue.getBoutonRecherche().addClickHandler(new ClickHandler() { |
|
public void onClick(ClickEvent event) { |
chercherObservations(collecterFormulaire()); |
72,7 → 101,7 |
} |
}); |
|
vue.boutonRechercheAvancee.addClickHandler(new ClickHandler() { |
vue.getBoutonRechercheAvancee().addClickHandler(new ClickHandler() { |
public void onClick(ClickEvent event) { |
chercherObservations(collecterFormulaire()); |
afficherObservations(); |
79,7 → 108,7 |
} |
}); |
|
vue.recherchePrincipale.addKeyPressHandler(new KeyPressHandler() { |
vue.getRecherchePrincipaleHasKeyPressHandlers().addKeyPressHandler(new KeyPressHandler() { |
|
public void onKeyPress(KeyPressEvent event) { |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) { |
92,39 → 121,38 |
|
// Gestion de la recherche d'observations : |
public HashMap<String, String> collecterFormulaire() { |
RechercheObservationsVue vue = (RechercheObservationsVue) getVue(); |
|
HashMap<String, String> champsRecherche = new HashMap<String, String>(); |
|
if (!vue.recherchePrincipale.getText().equals("")) { |
champsRecherche.put("search", vue.recherchePrincipale.getText()); |
if (!vue.getRecherchePrincipaleHasText().getText().equals("")) { |
champsRecherche.put("search", vue.getRecherchePrincipaleHasText().getText()); |
} |
if (!vue.departement.getText().equals("")) { |
champsRecherche.put("dept", vue.departement.getText()); |
if (!vue.getDepartement().getText().equals("")) { |
champsRecherche.put("dept", vue.getDepartement().getText()); |
} |
if (!vue.commune.getText().equals("")) { |
champsRecherche.put("com", vue.commune.getText()); |
if (!vue.getCommune().getText().equals("")) { |
champsRecherche.put("com", vue.getCommune().getText()); |
} |
if (!vue.taxon.getText().equals("")) { |
champsRecherche.put("taxon", vue.taxon.getText()); |
if (!vue.getTaxon().getText().equals("")) { |
champsRecherche.put("taxon", vue.getTaxon().getText()); |
} |
if (!vue.famille.getText().equals("")) { |
champsRecherche.put("fam", vue.famille.getText()); |
if (!vue.getFamille().getText().equals("")) { |
champsRecherche.put("fam", vue.getFamille().getText()); |
} |
if (!vue.genre.getText().equals("")) { |
champsRecherche.put("gen", vue.genre.getText()); |
if (!vue.getGenre().getText().equals("")) { |
champsRecherche.put("gen", vue.getGenre().getText()); |
} |
if (!vue.tag.getText().equals("")) { |
champsRecherche.put("tag", vue.tag.getText()); |
if (!vue.getTag().getText().equals("")) { |
champsRecherche.put("tag", vue.getTag().getText()); |
} |
if (!vue.motCle.getText().equals("")) { |
champsRecherche.put("motCle", vue.motCle.getText()); |
if (!vue.getMotCle().getText().equals("")) { |
champsRecherche.put("motCle", vue.getMotCle().getText()); |
} |
if (!vue.auteur.getText().equals("")) { |
champsRecherche.put("auteur", vue.auteur.getText()); |
if (!vue.getAuteur().getText().equals("")) { |
champsRecherche.put("auteur", vue.getAuteur().getText()); |
} |
if (!vue.date.getText().equals("")) { |
champsRecherche.put("date", vue.date.getText()); |
if (!vue.getDate().getText().equals("")) { |
champsRecherche.put("date", vue.getDate().getText()); |
} |
return champsRecherche; |
} |
131,19 → 159,17 |
|
public void chercherObservations(HashMap<String, String> champsRecherche) { |
|
RechercheObservationsVue vue = (RechercheObservationsVue) getVue(); |
vue.rechercheAvancee.setVisible(false); |
vue.getRechercheAvanceeHasVisibility().setVisible(false); |
this.observations = MockDatasource.getInstance().getObservations(champsRecherche); |
vue.recherchePrecedente.setText(getChaineRecherche(champsRecherche)); |
vue.getRecherchePrecedente().setText(getChaineRecherche(champsRecherche)); |
} |
|
public void afficherObservations() { |
RechercheObservationsVue vue = (RechercheObservationsVue) getVue(); |
|
vue.zoneObservations.clear(); |
vue.getZoneObservations().clear(); |
for (Observation observation : observations) { |
ObservationPresenteur presenteur = new ObservationPresenteur(observation); |
presenteur.go(vue.zoneObservations); |
ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation); |
presenteur.go(vue.getZoneObservations()); |
} |
} |
|