New file |
0,0 → 1,103 |
package org.tela_botanica.del.client.vues.rechercheimages; |
|
import java.util.List; |
|
import org.tela_botanica.del.client.cache.CacheClient; |
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur; |
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue; |
import org.tela_botanica.del.client.i18n.I18n; |
import org.tela_botanica.del.client.modeles.Protocole; |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel; |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.EvenementAjoutDetermination; |
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole; |
import org.tela_botanica.del.client.navigation.evenement.rechercheimage.EvenementRechercheImage; |
import org.tela_botanica.del.client.services.rest.ProtocoleService; |
import org.tela_botanica.del.client.utils.MockDatasource; |
|
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.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.HasWidgets; |
import com.google.gwt.user.client.ui.IsWidget; |
|
public class MoteurRechercheImagePresenteur { |
|
public interface Vue extends IsWidget { |
|
public abstract void ajouterProtocole(String protocole); |
public abstract void selectionnerProtocole(int index); |
public abstract HasChangeHandlers getListeProtocoles(); |
public abstract HasWidgets getZoneResultats(); |
public abstract HasWidgets getZoneRecherche(); |
} |
|
private Vue vue; |
|
// private final ImageService imageService = MockDatasource.getInstance(); |
private final ProtocoleService protocoleService = MockDatasource.getInstance(); |
private List<Protocole> protocoles; |
|
//TODO : passer ça en cache |
private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE; |
|
/** |
* Constructeur |
* */ |
public MoteurRechercheImagePresenteur(Vue vue) { |
this.vue = vue; |
|
if (CacheClient.getInstance().getProtocoleCourant() == null) { |
CacheClient.getInstance().setProtocoleCourant(protocoleService.getProtocole(protocoleParDefaut)); |
} |
} |
|
public void go(HasWidgets composite) { |
composite.add(vue.asWidget()); |
gererEvenements(); |
chargerProtocoles(); |
chargerMoteurRechercheAvancee(); |
} |
|
private void chargerProtocoles() { |
protocoles = protocoleService.getProtocoles(); |
for (Protocole protocole : protocoles) { |
vue.ajouterProtocole(protocole.getNom()); |
} |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant())); |
} |
|
public void gererEvenements() { |
|
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() { |
|
@Override |
public void onChange(ChangeEvent event) { |
|
Protocole protocoleCourant = (Protocole) event.getSource(); |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant); |
BusEvenementiel.getInstance().fireEvent(evenement); |
} |
}); |
} |
|
public void chargerMoteurRechercheAvancee() { |
MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(I18n.getVocabulary().rechercherImage())) { |
public void lancerRecherche(String termeRecherche) { |
CacheClient.getInstance().setEspeceRecherche(termeRecherche); |
BusEvenementiel.getInstance().fireEvent(new EvenementRechercheImage(getZoneResultats())); |
} |
}; |
presenteurRecherche.go(vue.getZoneRecherche()); |
} |
|
public HasWidgets getZoneResultats() { |
return vue.getZoneResultats(); |
} |
} |