/trunk/src/org/tela_botanica/client/util/AutoCompletionRefComboBox.java |
---|
New file |
0,0 → 1,167 |
package org.tela_botanica.client.util; |
import java.util.Iterator; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.ListeReferentielPerso; |
import org.tela_botanica.client.modeles.ListeReferentielPerso.TypesReferentiels; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import com.gwtext.client.core.EventCallback; |
import com.gwtext.client.core.EventObject; |
import com.gwtext.client.core.ListenerConfig; |
import com.gwtext.client.data.ArrayReader; |
import com.gwtext.client.data.FieldDef; |
import com.gwtext.client.data.MemoryProxy; |
import com.gwtext.client.data.Record; |
import com.gwtext.client.data.RecordDef; |
import com.gwtext.client.data.Store; |
import com.gwtext.client.data.StringFieldDef; |
import com.gwtext.client.widgets.form.ComboBox; |
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter; |
public abstract class AutoCompletionRefComboBox extends ComboBox implements Rafraichissable { |
// TODO: faire un enum |
private final int KEY_ALT = 18; |
private final int KEY_BACKSPACE = 8; |
private final int KEY_CTRL = 17; |
private final int KEY_DELETE = 46; |
private final int KEY_DOWN = 40; |
private final int KEY_END = 35; |
private final int KEY_ENTER = 13; |
private final int KEY_ESCAPE = 27; |
private final int KEY_HOME = 36; |
private final int KEY_LEFT = 37; |
private final int KEY_PAGEDOWN = 34; |
private final int KEY_PAGEUP = 33; |
private final int KEY_RIGHT = 39; |
private final int KEY_SHIFT = 16; |
private final int KEY_TAB = 9; |
private final int KEY_UP = 38; |
private ObservationMediateur oMediateur = null; |
private TypesReferentiels typeRef = null; |
private boolean selectionValeur = false; |
private boolean estModifie = false; |
final String resultTplRefPerso = "<div class=\"search-item-ref\">{element_referentiel}</div>"; |
public AutoCompletionRefComboBox(String label, String nom, ObservationMediateur oMediateur, TypesReferentiels typeRef) { |
// Accesskey pour debugging |
super(label,nom); |
this.oMediateur = oMediateur; |
this.typeRef = typeRef; |
setTpl(resultTplRefPerso); |
setMode(ComboBox.REMOTE); |
// commune.setPageSize(10); // Ne fonctionne pas |
setItemSelector("div.search-item-ref"); |
setTypeAhead(true); |
setLoadingText("Recherche..."); |
setHideTrigger(true); |
ListenerConfig listenerConfigAutocompletion=new ListenerConfig(); |
listenerConfigAutocompletion.setDelay(200); |
listenerConfigAutocompletion.setStopPropagation(false); |
listenerConfigAutocompletion.setStopEvent(false); |
addKeyPressListener(new EventCallback() { |
public void execute(EventObject e) { |
switch(e.getKey()) { |
case KEY_ALT: |
case KEY_CTRL: |
case KEY_DOWN: |
case KEY_END: |
case KEY_ESCAPE: |
case KEY_HOME: |
case KEY_LEFT: |
case KEY_PAGEDOWN: |
case KEY_PAGEUP: |
case KEY_RIGHT: |
case KEY_SHIFT: |
case KEY_TAB: |
case KEY_UP: |
break; |
case KEY_ENTER: |
if (selectionValeur) { |
estModifie= true; |
selectionValeur=false; |
onModificationValeur(); |
} |
else { |
onValidationSaisie(); |
} |
break; |
default: |
estModifie = true; |
obtenirReferentiel(); |
} |
} |
},listenerConfigAutocompletion); |
// Listener completion |
addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
setValue(record.getAsString("element_referentiel")); |
selectionValeur=true; |
collapse(); |
} |
}); |
} |
public void rafraichir(Object nouvelleDonnees, |
boolean repandreRaffraichissement) { |
ListeReferentielPerso referentielPerso = (ListeReferentielPerso)nouvelleDonnees; |
int i = 0; |
Object[][] refData = new Object[referentielPerso.size()][1]; |
for (Iterator it = referentielPerso.keySet().iterator(); it.hasNext();) |
{ |
String ref= referentielPerso.get(it.next()); |
refData[i][0]= ref; |
i++; |
} |
FieldDef defStation = new StringFieldDef("element_referentiel"); |
FieldDef[] defTab = {defStation}; |
RecordDef rd = new RecordDef(defTab); |
final MemoryProxy dataProxy = new MemoryProxy(refData); |
final ArrayReader reader = new ArrayReader(rd); |
Store store=new Store(dataProxy,reader); |
setStore(store); |
store.load(); |
} |
private void obtenirReferentiel() { |
String valeurChamp = getValue(); |
if(valeurChamp == null) { |
valeurChamp = ""; |
} |
oMediateur.obtenirListeReferentielPerso(this, typeRef, valeurChamp); |
} |
public abstract void onValidationSaisie(); |
public abstract void onModificationValeur(); |
} |
/trunk/src/org/tela_botanica/client/image/ImageMediateur.java |
---|
275,7 → 275,6 |
// on crée un modèle |
iModele = ImageModele.Instance(this); |
// et on demande l'arbre des mots clés |
// on gère la mise en page du panneau principal |
572,12 → 571,13 |
if (li.getCount() <= 0) { |
aucuneSelection(); |
if (ongletsImage.getActiveTab().getId() == getZoomImage().getId()) { |
ongletsImage.activate(0); |
} |
} else { |
selection(); |
} |
} |
if (r != getGalerieImage()) { |
getGalerieImage().rafraichir(o, false); |
} |
588,9 → 588,10 |
getListeImage().rafraichir(o, false); |
} |
aucuneSelection(); |
demasquerChargement(); |
} |
} |
public void obtenirPhotoGalerie() { |
1004,7 → 1005,6 |
getZoomImage().desactiverPanneau(); |
setSelection(false); |
} |
} |
/** |
1631,6 → 1631,7 |
setIdentifiant(cMediateur.getUtilisateur().getIdentifiant()); |
getIModele().initialiserArbreMotsCles(); |
filtres.getArbreDateRecherche().initialiser(); |
obtenirPhotoGalerie(getGalerieImage()); |
} |
else |
1641,6 → 1642,7 |
{ |
setIdentifiant(cMediateur.getUtilisateur().getIdentifiant()); |
getIModele().initialiserArbreMotsCles(); |
filtres.getArbreDateRecherche().initialiser(); |
obtenirPhotoGalerie(getGalerieImage()); |
panneauPrincipalImage.purgeListeners() ; |
} |
/trunk/src/org/tela_botanica/client/vues/observation/FormulaireSaisieObservationVue.java |
---|
18,6 → 18,7 |
import org.tela_botanica.client.modeles.ReferentielNom; |
import org.tela_botanica.client.modeles.ListeReferentielPerso.TypesReferentiels; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import org.tela_botanica.client.util.AutoCompletionRefComboBox; |
import org.tela_botanica.client.util.Util; |
import com.google.gwt.core.client.GWT; |
148,9 → 149,6 |
private Button boutonAnnuler = new Button("Réinitialiser"); |
private boolean selectionCommune=false; |
private boolean selectionStation=false; |
private boolean selectionLieuDit=false; |
private boolean selectionMilieu=false; |
private boolean selectionEspece=false; |
private boolean modification = false ; |
319,16 → 317,16 |
panneauPremierColonne.add(htmlCommunePanel); |
station = new ComboBox("Station", "station"); |
station.setTpl(resultTplRefPerso); |
station.setMode(ComboBox.REMOTE); |
// commune.setPageSize(10); // Ne fonctionne pas |
station.setItemSelector("div.search-item-commune"); |
station.setTypeAhead(true); |
station.setLoadingText("Recherche..."); |
station.setHideTrigger(true); |
station.setAllowBlank(true); |
station = new AutoCompletionRefComboBox("Station", "station", observationMediateur, TypesReferentiels.REFERENTIEL_STATION) { |
public void onModificationValeur() { |
stationModifiee = true; |
} |
public void onValidationSaisie() { |
validerSaisie(Champs.STATION); |
} |
}; |
panneauPremierColonne.add(station, new AnchorLayoutData("95%")); |
latitude = new TextField("Lat", "x"); |
467,25 → 465,29 |
panneauPremierColonne.add(espece, new AnchorLayoutData("95%")); |
lieudit = new ComboBox("Lieu-dit", "lieudit"); |
lieudit.setTpl(resultTplRefPerso); |
lieudit.setMode(ComboBox.REMOTE); |
lieudit.setItemSelector("div.search-item-commune"); |
lieudit.setTypeAhead(true); |
lieudit.setLoadingText("Recherche..."); |
lieudit.setHideTrigger(true); |
lieudit.setAllowBlank(true); |
lieudit = new AutoCompletionRefComboBox("Lieu-dit", "lieudit",observationMediateur,TypesReferentiels.REFERENTIEL_LIEU_DIT) { |
public void onModificationValeur() { |
lieuDitModifie = true; |
} |
public void onValidationSaisie() { |
validerSaisie(Champs.LIEUDIT); |
} |
}; |
panneauSecondeColonne.add(lieudit, new AnchorLayoutData("95%")); |
milieu = new AutoCompletionRefComboBox("Milieu","milieu",observationMediateur,TypesReferentiels.REFERENTIEL_MILIEU) { |
milieu = new ComboBox("Milieu", "milieu"); |
milieu.setTpl(resultTplRefPerso); |
milieu.setMode(ComboBox.REMOTE); |
milieu.setItemSelector("div.search-item-commune"); |
milieu.setTypeAhead(true); |
milieu.setLoadingText("Recherche..."); |
milieu.setHideTrigger(true); |
milieu.setAllowBlank(true); |
public void onModificationValeur() { |
milieuModifie = true; |
} |
public void onValidationSaisie() { |
validerSaisie(Champs.MILIEU); |
} |
}; |
panneauSecondeColonne.add(milieu, new AnchorLayoutData("95%")); |
comment = new TextArea("Notes", "comment"); |
698,58 → 700,7 |
listenerConfigAutocompletion.setStopPropagation(false); |
listenerConfigAutocompletion.setStopEvent(false); |
station.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
station.setValue(record.getAsString("element_referentiel")); |
selectionStation=true; |
station.collapse(); |
} |
public void onExpand(ComboBox comboBox) { |
comboBox.focus(); |
} |
}); |
station.addKeyPressListener(new EventCallback() { |
public void execute(EventObject e) { |
// TODO Auto-generated method stub |
switch(e.getKey()) { |
case KEY_ALT: |
case KEY_CTRL: |
case KEY_DOWN: |
case KEY_END: |
case KEY_ESCAPE: |
case KEY_HOME: |
case KEY_LEFT: |
case KEY_PAGEDOWN: |
case KEY_PAGEUP: |
case KEY_RIGHT: |
case KEY_SHIFT: |
case KEY_TAB: |
case KEY_UP: |
break; |
case KEY_ENTER: |
if (selectionStation) { |
stationModifiee= true; |
selectionStation=false; |
} |
else { |
validerSaisie(Champs.STATION); |
} |
break; |
default: |
obtenirReferentielStation(); |
stationModifiee = true; |
} |
} |
},listenerConfigAutocompletion); |
// Listener completion espece |
espece.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
820,102 → 771,6 |
); |
// Listener completion lieudit |
lieudit.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
lieudit.setValue(record.getAsString("element_referentiel")); |
selectionLieuDit=true; |
lieudit.collapse(); |
} |
}); |
lieudit.addKeyPressListener(new EventCallback() { |
public void execute(EventObject e) { |
// TODO Auto-generated method stub |
switch(e.getKey()) { |
case KEY_ALT: |
case KEY_CTRL: |
case KEY_DOWN: |
case KEY_END: |
case KEY_ESCAPE: |
case KEY_HOME: |
case KEY_LEFT: |
case KEY_PAGEDOWN: |
case KEY_PAGEUP: |
case KEY_RIGHT: |
case KEY_SHIFT: |
case KEY_TAB: |
case KEY_UP: |
break; |
case KEY_ENTER: |
if (selectionLieuDit) { |
lieuDitModifie= true; |
selectionLieuDit=false; |
} |
else { |
validerSaisie(Champs.LIEUDIT); |
} |
break; |
default: |
lieuDitModifie = true; |
obtenirReferentielLieuDit(); |
} |
} |
},listenerConfigAutocompletion); |
// Listener completion lieudit |
milieu.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
milieu.setValue(record.getAsString("element_referentiel")); |
selectionMilieu=true; |
milieu.collapse(); |
} |
}); |
milieu.addKeyPressListener(new EventCallback() { |
public void execute(EventObject e) { |
// TODO Auto-generated method stub |
switch(e.getKey()) { |
case KEY_ALT: |
case KEY_CTRL: |
case KEY_DOWN: |
case KEY_END: |
case KEY_ESCAPE: |
case KEY_HOME: |
case KEY_LEFT: |
case KEY_PAGEDOWN: |
case KEY_PAGEUP: |
case KEY_RIGHT: |
case KEY_SHIFT: |
case KEY_TAB: |
case KEY_UP: |
break; |
case KEY_ENTER: |
if (selectionMilieu) { |
milieuModifie= true; |
selectionMilieu=false; |
} |
else { |
validerSaisie(Champs.MILIEU); |
} |
break; |
default: |
milieuModifie = true; |
obtenirListeReferentielMilieu(); |
} |
} |
},listenerConfigAutocompletion); |
comment.addKeyPressListener(new EventCallback() { |
public void execute(EventObject e) { |
1188,58 → 1043,6 |
} |
if(nouvelleDonnees instanceof ListeReferentielPerso) |
{ |
ListeReferentielPerso referentielPerso = (ListeReferentielPerso)nouvelleDonnees; |
int i = 0; |
Object[][] refData = new Object[referentielPerso.size()][1]; |
// on la parse et on récupère les informations quiç nous interessent |
for (Iterator it = referentielPerso.keySet().iterator(); it.hasNext();) |
{ |
String ref= referentielPerso.get(it.next()); |
refData[i][0]= ref; |
i++; |
} |
//creation du store |
FieldDef defStation = new StringFieldDef("element_referentiel"); |
FieldDef[] defTab = {defStation}; |
RecordDef rd = new RecordDef(defTab); |
final MemoryProxy dataProxy = new MemoryProxy(refData); |
final ArrayReader reader = new ArrayReader(rd); |
Store store=new Store(dataProxy,reader); |
switch (referentielPerso.getTypeReferentiel()) { |
case REFERENTIEL_STATION: |
station.setStore(store); |
store.load(); |
break; |
case REFERENTIEL_LIEU_DIT: |
lieudit.setStore(store); |
store.load(); |
break; |
case REFERENTIEL_MILIEU: |
milieu.setStore(store); |
store.load(); |
break; |
default: |
break; |
} |
} |
// On recoit une observation dont on veut afficher le detail |
if(nouvelleDonnees instanceof Observation) |
/trunk/src/org/tela_botanica/client/modeles/ListeReferentielPersoAsynchroneDAO.java |
---|
New file |
0,0 → 1,132 |
package org.tela_botanica.client.modeles; |
import java.util.HashMap; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.ListeReferentielPerso.TypesReferentiels; |
import org.tela_botanica.client.observation.ObservationModele; |
import com.google.gwt.http.client.Request; |
import com.google.gwt.http.client.RequestBuilder; |
import com.google.gwt.http.client.RequestCallback; |
import com.google.gwt.http.client.RequestException; |
import com.google.gwt.http.client.Response; |
import com.google.gwt.http.client.URL; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
import com.google.gwt.json.client.JSONValue; |
public class ListeReferentielPersoAsynchroneDAO { |
/** |
* Cache |
* |
*/ |
private HashMap<String,ListeReferentielPerso> cache = new HashMap(); |
private TypesReferentiels refDemande = null; |
public ListeReferentielPersoAsynchroneDAO(ObservationModele obs) { |
} |
public void setRefDemande(TypesReferentiels refDemande) { |
this.refDemande = refDemande; |
} |
public void obtenirListeDonnees(final Rafraichissable r, String utilisateur, final String critere) { |
switch (refDemande) { |
case REFERENTIEL_STATION: |
break; |
default: |
break; |
} |
ListeReferentielPerso referentielPersoDataFromCache=null; |
// En cache ? |
if ((referentielPersoDataFromCache=getFromCache(critere))!=null) { |
r.rafraichir(referentielPersoDataFromCache,true); |
} |
else { |
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + |
"/SelfRefList/"+ |
utilisateur+"/"+ |
refDemande.toString()+ |
"?start=0&limit=50&recherche="+URL.encode(critere)); |
try { |
rb.sendRequest(null, new RequestCallback() { |
public void onError(final Request request, final Throwable exception) { |
// TODO Auto-generated method stub |
} |
public void onResponseReceived(final Request request, |
final Response response) { |
final ListeReferentielPerso referentielData; |
final JSONValue responseValue = JSONParser.parse(response.getText()); |
JSONArray reponse = null; |
// si c'est un tableau |
if ((reponse = responseValue.isArray()) != null) { |
JSONString elementsRef; |
final int taillemax = reponse.size(); |
referentielData = new ListeReferentielPerso(taillemax, refDemande); |
for (int i = 0; i < taillemax; i++) { |
if ((elementsRef = reponse.get(i).isString()) != null) { |
String valeur = elementsRef.stringValue(); |
referentielData.put(i+"", valeur); |
} |
} |
} else { |
referentielData = new ListeReferentielPerso(0, refDemande); |
} |
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est |
// le premier à les recevoir |
addToCache(critere, referentielData); |
r.rafraichir(referentielData, true); |
} |
}); |
} catch (RequestException e) { |
e.printStackTrace(); |
} |
} // Fin else si pas de cache |
} |
private void addToCache(String query, ListeReferentielPerso result) { |
cache.put(query.toLowerCase(),result); |
} |
private ListeReferentielPerso getFromCache (String query) { |
return (ListeReferentielPerso) cache.get(query.toLowerCase()); |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/ListeReferentielPerso.java |
---|
New file |
0,0 → 1,73 |
package org.tela_botanica.client.modeles; |
import java.util.HashMap; |
public class ListeReferentielPerso extends HashMap<String, String> { |
public static enum TypesReferentiels { |
REFERENTIEL_LIEU_DIT { |
public String toString() { |
return "lieudit"; |
} |
}, |
REFERENTIEL_STATION { |
public String toString() { |
return "station"; |
} |
}, |
REFERENTIEL_MILIEU { |
public String toString() { |
return "milieu"; |
} |
} |
} |
/** |
* |
*/ |
private static final long serialVersionUID = 2159394354752556196L; |
private TypesReferentiels typeReferentiel = null; |
/** |
* Constructeur sans paramètres |
*/ |
public ListeReferentielPerso(TypesReferentiels typeReferentiel) |
{ |
super(); |
this.typeReferentiel = typeReferentiel; |
} |
/** |
* Constructeur avec paramètre |
* @param taille la taille de la table de hachage |
*/ |
public ListeReferentielPerso(int taille,TypesReferentiels typeReferentiel) |
{ |
super(); |
this.typeReferentiel = typeReferentiel; |
} |
/** |
* Constructeur avec paramètre |
* @param ic un tableau de strings |
*/ |
public ListeReferentielPerso(TypesReferentiels typeReferentiel, String[] nom) |
{ |
super() ; |
this.typeReferentiel = typeReferentiel; |
for (int i = 0; i < nom.length; i++) |
{ |
if(nom[i] != null && nom[i].equals("00null")) |
{ |
this.put(i+"",nom[i]); |
} |
} |
} |
public TypesReferentiels getTypeReferentiel() { |
return typeReferentiel; |
} |
} |