Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 2391 → Rev 2392

/trunk/src/org/tela_botanica/client/util/FormulaireSaisieChampEtendu.java
1,7 → 1,6
package org.tela_botanica.client.util;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
9,10 → 8,10
 
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.ListeChampsEtendus;
import org.tela_botanica.client.modeles.objets.ListeGroupesChampsEtendus;
 
import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
19,6 → 18,7
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Ext;
import com.gwtext.client.core.ListenerConfig;
import com.gwtext.client.data.ArrayReader;
import com.gwtext.client.data.FieldDef;
58,7 → 58,7
private final int KEY_UP = 38;
final ComboBox nChamp;
final String resultTplRefPerso = "<div class=\"search-item-ref\">{label}</div>";
final String resultTplRefPerso = "<div class=\"search-item-ref\">{label_fmt}</div>";
Button ajouterChampsEtenduEtFermer;
Button ajouterChampsEtendu;
Button annulerAjouterChampEtendu;
73,6 → 73,8
private Timer timer = null;
private static Map<String, String> cacheClesValeur;
private HTML descriptionChamp = null;
private Record rdSelectionne = null;
private Record groupeSelectionne = null;
private String valeurBrute = "";
91,7 → 93,7
groupesChampsEtendus.setWidth("350px");
groupesChampsEtendus.setLabel("Ajouter un groupe de champs");
groupesChampsEtendus.setDisplayField("label") ;
groupesChampsEtendus.setValueField("valeur");
groupesChampsEtendus.setValueField("cle");
groupesChampsEtendus.setEditable(false);
groupesChampsEtendus.setHideTrigger(false);
groupesChampsEtendus.setForceSelection(true);
116,7 → 118,9
HTML indicationSaisie = new HTML("Saisissez un nom de champ ou choisisez un nom proposé par l'autocomplétion "+
"Si vous choissisez un nom de champ existant vous pourrez profiter d'une autocomplétion "+
"sur les valeurs déjà saisies pour ce champ par les autres utilisateurs");
"sur les valeurs déjà saisies pour ce champ par les autres utilisateurs.<br /> "+
"Les champs de la forme 'label (clé)' sont des champs 'standards' ayant un rôle et une description " +
"bien définie");
indicationSaisie.addStyleName("aideCreerChampEtendu");
add(indicationSaisie);
124,8 → 128,23
hp.setBorderWidth(0);
nChamp = new ComboBox("Nom du champ", "nom_champ_etendu");
nChamp.setWidth("350px");
nChamp.setTpl(resultTplRefPerso);
nChamp.setMode(ComboBox.REMOTE);
nChamp.setItemSelector("div.search-item-ref");
nChamp.setTypeAhead(false);
nChamp.setLoadingText("Recherche...");
nChamp.setHideTrigger(true);
nChamp.setValidateOnBlur(false);
Store store = initStoreChampsEtendusVide();
store.load();
nChamp.setStore(store);
add(nChamp);
descriptionChamp = new HTML();
descriptionChamp.addStyleName("aideWikiChampEtendu");
add(descriptionChamp);
ajouterChampsEtenduEtFermer = new Button("Ajouter et fermer");
ajouterChampsEtenduEtFermer.setTooltip("Ajouter un champ étendu ou un groupe de champs et fermer la fenêtre");
ajouterChampsEtendu = new Button("Ajouter");
137,16 → 156,6
hp.add(ajouterChampsEtendu);
hp.add(annulerAjouterChampEtendu);
add(hp);
nChamp.setTpl(resultTplRefPerso);
nChamp.setMode(ComboBox.REMOTE);
nChamp.setItemSelector("div.search-item-ref");
nChamp.setTypeAhead(false);
nChamp.setLoadingText("Recherche...");
nChamp.setHideTrigger(true);
nChamp.setValidateOnBlur(false);
nChamp.setWidth("350px");
nChamp.focus();
ajouterListeners();
}
179,9 → 188,8
case KEY_ENTER:
if(rdSelectionne != null) {
nChamp.setValue(rdSelectionne.getAsString("label"));
idChamp = rdSelectionne.getAsString("cle");
valeurBrute = rdSelectionne.getAsString("label");
nChamp.setValue(rdSelectionne.getAsString("label"));
valeurBrute = rdSelectionne.getAsString("cle");
}
break;
207,25 → 215,29
}
};
timer.schedule(300);
valeurBrute = nChamp.getValueAsString();
nChamp.setValue(valeurBrute);
valeurBrute = nChamp.getRawValue();
nChamp.setRawValue(valeurBrute);
}
}
},listenerConfigAutocompletion);
// Listener completion
nChamp.addListener(new ComboBoxListenerAdapter() {
@Override
public void onSelect(ComboBox comboBox, Record record, int index) {
public void onSelect(ComboBox comboBox, Record record, int index) {
rdSelectionne = record;
telechargerEtAfficherDescriptionChamps(rdSelectionne.getAsString("cle"));
nChamp.setRawValue(rdSelectionne.getAsString("label"));
valeurBrute = rdSelectionne.getAsString("cle");
}
@Override
public void onBlur(Field field) {
nChamp.setRawValue(valeurBrute);
nChamp.collapse();
 
@Override
public void onBlur(Field field) {
if(rdSelectionne != null && !rdSelectionne.getAsString("cle").equals(valeurBrute)) {
nChamp.setRawValue(valeurBrute);
}
telechargerEtAfficherDescriptionChamps(valeurBrute);
}
});
});
groupesChampsEtendus.addListener(new ComboBoxListenerAdapter() {
@Override
238,7 → 250,7
@Override
public void onClick(Button button, EventObject e) {
if(doitAjouterGroupe()) {
surValidationMultiple(renvoyerListeChampsEtendus(groupeSelectionne.getAsString("valeur")));
surValidationMultiple(renvoyerListeChampsEtendus(groupeSelectionne.getAsString("cle")));
} else {
if(champEtenduEstValide()) {
surValidation(validerEtRenvoyerChampEtendu());
276,19 → 288,13
nChamp.focus();
}
private ChampSaisieEtendu validerEtRenvoyerChampEtendu() {
String valeurChamp = nChamp.getValueAsString();
String idNouveauChamp = "";
if(!estUnChampSelectionne(valeurChamp)) {
Date date = new Date();
// affectation d'un id temporaire qui sera remplacé par l'id auto généré à partir
// du label
idNouveauChamp = "tempid_"+date.getTime();
} else {
idNouveauChamp = idChamp;
}
ChampSaisieEtendu retour = new ChampSaisieEtendu(valeurChamp, idNouveauChamp);
retour.setId(idNouveauChamp);
private ChampSaisieEtendu validerEtRenvoyerChampEtendu() {
String valeurChamp = nChamp.getRawValue();
// Valeur contient soit la clé, soit le label s'il existe
// valeur brute contient toujours la clé
// TODO: utiliser les champs de google et pas ceux de GWT-EXT qui puent du cul
ChampSaisieEtendu retour = new ChampSaisieEtendu(valeurChamp, valeurBrute);
retour.setId(valeurBrute);
return retour;
}
306,11 → 312,11
}
private boolean doitAjouterGroupe() {
return groupeSelectionne != null && !groupeSelectionne.getAsString("valeur").equals("");
return groupeSelectionne != null && !groupeSelectionne.getAsString("cle").equals("");
}
private boolean champEtenduEstValide() {
String valeurChamp = nChamp.getValueAsString();
String valeurChamp = nChamp.getRawValue();
return (valeurChamp != null && !valeurChamp.isEmpty());
}
319,7 → 325,7
}
private void obtenirListeValeurs() {
obtenirListeValeurs(nChamp.getValueAsString());
obtenirListeValeurs(nChamp.getRawValue());
}
private void obtenirListeValeurs(String valeur) {
340,20 → 346,28
ListeChampsEtendus clesLabels = (ListeChampsEtendus)nouvelleDonnees;
cacheClesValeur = clesLabels;
Object[][] refData = new Object[clesLabels.keySet().size()][2];
Object[][] refData = new Object[clesLabels.keySet().size()][3];
for (Iterator<String> it = clesLabels.keySet().iterator(); it.hasNext();)
{
String cle = it.next();
String label= clesLabels.get(cle);
String label = clesLabels.get(cle);
refData[i][0]= cle;
refData[i][1]= label;
if(cle.equals(label.toLowerCase())) {
refData[i][2]= label;
} else {
refData[i][2]= label+" ("+cle+")";
}
 
i++;
}
FieldDef defCle = new StringFieldDef("cle");
FieldDef defLabel = new StringFieldDef("label");
FieldDef[] defTab = {defCle, defLabel};
FieldDef defLabelFmt = new StringFieldDef("label_fmt");
FieldDef[] defTab = {defCle, defLabel, defLabelFmt};
RecordDef rd = new RecordDef(defTab);
377,6 → 391,38
}
}
private void telechargerEtAfficherDescriptionChamps(final String cle) {
ListeReferentielChampsEtendusDAO.telechargerDescriptionWikini(cle, new Callback<String, String>() {
@Override
public void onSuccess(String description) {
afficherDescriptionEtLienWikiChampEtendu(cle, description);
}
@Override
public void onFailure(String reason) {
// rien
}
});
}
private void afficherDescriptionEtLienWikiChampEtendu(final String cle, String description) {
if(description.trim().isEmpty()) {
String urlDesc = ListeReferentielChampsEtendusDAO.obtenirUrlEditionDescriptionWiki(cle);
descriptionChamp.setHTML("<span> Aucune description n'existe pour ce champ.<br />" +
"Vous pouvez la remplir sur cette page :" +
"<a id=\"lien_description_wiki_ce_"+cle+"\" href="+urlDesc+" target=\"_blank\">"+cle+"</span></span>");
Ext.get("lien_description_wiki_ce_"+cle).addListener("click", new EventCallback() {
@Override
public void execute(EventObject e) {
ListeReferentielChampsEtendusDAO.creerPageWikini(cle);
}
});
} else {
descriptionChamp.setHTML("<span class=\"descriptionChampEtenduTitre\">Description :</span> "+description);
}
}
private Store getGroupesChampsEtendusStore(ListeGroupesChampsEtendus listeGroupesChampsEtendus) {
int i = 1;
Object[][] valeurs = new Object[listeGroupesChampsEtendus.size()+1][2];
392,8 → 438,25
i++;
}
}
SimpleStore store = new SimpleStore(new String[] {"label","valeur"},valeurs);
SimpleStore store = new SimpleStore(new String[] {"label","cle"},valeurs);
store.load();
return store;
}
private Store initStoreChampsEtendusVide() {
Object[][] refData = new Object[0][1];
FieldDef defLabel = new StringFieldDef("label");
FieldDef defCle = new StringFieldDef("cle");
FieldDef[] defTab = {defLabel, defCle};
RecordDef rd = new RecordDef(defTab);
final MemoryProxy dataProxy = new MemoryProxy(refData);
final ArrayReader reader = new ArrayReader(rd);
Store store = new Store(dataProxy,reader);
return store;
}
}
/trunk/src/org/tela_botanica/client/util/ChampSaisieEtendu.java
3,11 → 3,11
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
import org.tela_botanica.client.modeles.objets.Configuration;
 
import com.google.gwt.core.client.Callback;
import com.google.gwt.user.client.Timer;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
21,7 → 21,7
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
import com.gwtext.client.widgets.ToolTip;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.Field;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
59,9 → 59,11
private Record rdSelectionne = null;
private String valeurBrute = "";
private String description = null;
private ToolTip tpDesc = null;
public ChampSaisieEtendu(String label, String cle) {
// Accesskey pour debugging
 
super(label,cle);
 
this.cle =cle;
152,14 → 154,53
}
});
this.addListener(new ComponentListenerAdapter() {
// A activer pour télécharger la description
// si jamais on le décide
addListener(new ComboBoxListenerAdapter() {
@Override
public void onRender(Component component) {
setLargeurChamp();
ChampSaisieEtendu.this.getEl().addListener("mouseover", new EventCallback() {
@Override
public void execute(EventObject e) {
if(description == null) {
telechargerEtAfficherDescriptionDistante();
} else {
afficherDescription(description);
}
}
});
}
});
}
 
private void telechargerEtAfficherDescriptionDistante() {
ListeReferentielChampsEtendusDAO.telechargerDescriptionWikini(cle, new Callback<String, String>() {
@Override
public void onSuccess(String description) {
ChampSaisieEtendu.this.description = description;
afficherDescription(description);
}
@Override
public void onFailure(String description) {
afficherDescription(description);
}
});
}
private void afficherDescription(String description) {
if(!description.trim().isEmpty()) {
if(tpDesc == null) {
tpDesc = new ToolTip(description);
tpDesc.applyTo(this.getElement());
tpDesc.showAt(ChampSaisieEtendu.this.getEl().getX(), ChampSaisieEtendu.this.getEl().getY());
} else {
tpDesc.show();
}
}
}
@Override
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
/trunk/src/org/tela_botanica/client/util/Util.java
1,13 → 1,16
package org.tela_botanica.client.util;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
 
import org.tela_botanica.client.modeles.objets.ChampEtendu;
import org.tela_botanica.client.modeles.objets.Observation;
 
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
28,7 → 31,7
for (int i = 0; i < tabJo.size(); i++) {
JSONObject champJson = tabJo.get(i).isObject();
String cle = champJson.get("cle").isString().stringValue();
String label = champJson.get("label").isString().stringValue();
String label = cle;
String valeur = champJson.get("valeur").isString().stringValue();
ChampEtendu champ = new ChampEtendu(cle, label, valeur);
mapValeurs.put(cle, champ);
319,4 → 322,82
public static String tronquerNombrePourAffichage(String nombre, int decimales) {
return tronquerNombrePourAffichage(nombre, decimales, '.');
}
// Adapté de http://www.programcreek.com/2011/03/java-method-for-spliting-a-camelcase-string/
public static String formaterCleChampsEtenduPourAffichage(String s) {
char[] cArray = s.toCharArray();
Vector<Integer> al = new Vector<Integer>();
al.add(0);
// get all upper case letter index positions
for (int i = 1; i < cArray.length; i++) {
char c = cArray[i];
//add more interested index beyond upper case letter
if (c >= 65 && c <= 90) {
al.add(i);
}
}
Vector<String> strl = new Vector<String>();
// this handles the all lower letter case
if (al.size() == 1) {
strl.add(s);
return depilerChaineListee(strl, " ");
}
int prev = 0;
int curr = 0;
int begin = 0;
for (int k = 1; k < al.size(); k++) {
curr = al.get(k);
if(curr == s.length() - 1){
}
if (curr == prev + 1 && curr != s.length() - 1) {
prev = curr;
} else if(curr == prev + 1 && curr == s.length() - 1){
strl.add(s.substring(begin, curr+1));
}else {
strl.add(s.substring(prev, curr));
prev = curr;
begin = curr;
if (k == al.size() - 1) {
strl.add(s.substring(curr, s.length()));
}
}
}
return depilerChaineListee(strl, " ");
}
private static String depilerChaineListee(Vector<String> strl, String separateur) {
String s = "";
for(int i = 0; i < strl.size(); i++) {
s += strl.get(i);
if(i != strl.size() - 1) {
s += separateur;
}
}
return s;
}
public static Map<String, ChampEtendu> trierListeChampsEtendus(Map<String, ChampEtendu> listeChampsEtendus) {
List<String> tmp = new ArrayList<String>(listeChampsEtendus.keySet());
Collections.sort(tmp, new Comparator<String>() {
@Override
public int compare(String arg0, String arg1) {
return arg0.compareTo(arg1);
}
});
return listeChampsEtendus;
}
}
/trunk/src/org/tela_botanica/client/vues/observation/FormulaireSaisieObservationVue.java
10,6 → 10,7
 
import org.tela_botanica.client.CarnetEnLigneMediateur;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
import org.tela_botanica.client.modeles.objets.ChampEtendu;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
321,7 → 322,7
this.setPaddings(5) ;
 
// Accesskey pour debugging
commune=new ComboBox("Commune","commune\" accesskey=\"1");
commune = new ComboBox("Commune","commune\" accesskey=\"1");
 
final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
commune.setTpl(resultTplCommune);
632,6 → 633,11
});
if(Configuration.saisieChampsEtendusActivee()) {
// Chargement du cache des correspondances cles/labels du catalogue
ListeReferentielChampsEtendusDAO lrceDao = new ListeReferentielChampsEtendusDAO(null);
lrceDao.obtenirGroupesChampsEtendus(this);
lrceDao.obtenirCatalogueChampsEtendus(this);
lienAjouterChampsEtendus = new HTML("Ajouter un champ étendu");
lienAjouterChampsEtendus.addStyleName("lienAjouterChampEtendu");
lienAjouterChampsEtendus.setVisible(true);
1793,6 → 1799,7
}
 
private void afficherChampsEtendus(Map<String, ChampEtendu> champsEtendus, ChampEtendu champsAFocus) {
champsEtendus = Util.trierListeChampsEtendus(champsEtendus);
viderChampsEtendus();
 
FormLayout flmd = new FormLayout();
1819,18 → 1826,29
if(champsEtendus != null && champsEtendus.size() > 0) {
lienAfficherChampsEtendus.setVisible(true);
listeChampsEtendus = new HashMap<String, ChampSaisieEtendu>(champsEtendus.size());
HashMap<String, String> correspondancesClesLabel = ListeReferentielChampsEtendusDAO.cacheClesLabels;
boolean gauche = true;
for (Iterator<String> iterator = champsEtendus.keySet().iterator(); iterator.hasNext();) {
String id = iterator.next();
ChampEtendu champ = champsEtendus.get(id);
String valeur = champ.getValeur();
String label = champ.getLabel();
String label = id;
// Si le champ possède un clé déjà définie par le catalogue, elle lui sera affectée
// sinon on la formate en la "déchamotant" et en ajoutant des espaces
if(correspondancesClesLabel.containsKey(id)) {
label = correspondancesClesLabel.get(id);
} else {
label = Util.formaterCleChampsEtenduPourAffichage(label);
}
 
ChampSaisieEtendu champTexteEtendu = new ChampSaisieEtendu(label, id);
if(champ.equals(champsAFocus)) {
champTexteEtendu.focus();
}
champTexteEtendu.setLabel(label);
champTexteEtendu.setId(id);
champTexteEtendu.setValue(valeur);
if(gauche) {
2177,7 → 2195,6
// Test idiot qui permet de savoir si l'on utilise la valeur saisie directement ou bien la valeur
// selectionnee car lors du setValue sur le keypress, gwtext ne prends pas en compte le dernier
// caractère
 
if(valeurChampBrute.trim().length() == 0) {
valeurChamp = "";
} else {
/trunk/src/org/tela_botanica/client/cel2.java
5,7 → 5,9
import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.gwtext.client.core.Ext;
import com.gwtext.client.widgets.Viewport;
 
20,10 → 22,10
@Override
public void onModuleLoad() {
/*
// A décommenter + compiler en detailed dans le cas d'une erreur
// survernant uniquement sur le serveur
/*GWT.setUncaughtExceptionHandler(null);
GWT.setUncaughtExceptionHandler(null);
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
@Override
public void onUncaughtException(Throwable e) {
32,8 → 34,8
Window.alert(s);
e.printStackTrace();
}
});*/
});
*/
// TODO: config devrait être un singleton
Configuration config = new Configuration();
90,5 → 92,11
}
}
return log;
}*/
}*/
public static native void LogVersFirebug(Object o) /*-{
if (!!($wnd.console && $wnd.console.log)) {
console.log(o);
}
}-*/;
}
/trunk/src/org/tela_botanica/client/modeles/dao/ListeReferentielChampsEtendusDAO.java
4,6 → 4,7
import java.util.HashMap;
import java.util.Iterator;
 
import org.tela_botanica.client.cel2;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.objets.Configuration;
import org.tela_botanica.client.modeles.objets.ListeChampsEtendus;
11,6 → 12,7
import org.tela_botanica.client.modeles.objets.ListeReferentielPerso;
import org.tela_botanica.client.observation.ObservationModele;
 
import com.google.gwt.core.client.Callback;
import com.google.gwt.http.client.Request;
import org.tela_botanica.client.util.RequestBuilderWithCredentials;
import com.google.gwt.http.client.RequestCallback;
21,15 → 23,17
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
 
public class ListeReferentielChampsEtendusDAO {
/**
* Cache
*
*/
private HashMap<String,ListeReferentielPerso> cache = new HashMap();
public static ListeGroupesChampsEtendus cacheGroupes;
public static HashMap<String, String> cacheClesLabels;
public static HashMap<String, String> cacheDescription = new HashMap<String, String>();
public static String prefixePageChampEtendu = "CE";
public ListeReferentielChampsEtendusDAO(ObservationModele obs) {
}
38,12 → 42,10
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/NomsChampsEtendus/cle"+
"?recherche="+URL.encode(recherche));
"?recherche="+URL.encode(recherche));
try {
rb.sendRequest(null, new RequestCallback() {
 
@Override
public void onResponseReceived(final Request request,
final Response response) {
54,10 → 56,8
 
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
75,7 → 75,6
try {
rb.sendRequest(null, new RequestCallback() {
 
@Override
public void onResponseReceived(final Request request,
final Response response) {
97,9 → 96,7
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
}
});
} catch (RequestException e) {
109,25 → 106,143
}
public void obtenirGroupesChampsEtendus(final Rafraichissable r) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/GroupesChampsEtendus/");
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
ListeGroupesChampsEtendus valeurs = new ListeGroupesChampsEtendus(response.getText());
r.rafraichir(valeurs, true);
if(cacheGroupes == null) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/CatalogueChampsEtendus/groupes");
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
ListeGroupesChampsEtendus valeurs = new ListeGroupesChampsEtendus(response.getText());
cacheGroupes = valeurs;
r.rafraichir(valeurs, true);
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
e.printStackTrace();
}
} else {
r.rafraichir(cacheGroupes, true);
}
}
public void obtenirCatalogueChampsEtendus(final Rafraichissable r) {
if(cacheClesLabels == null) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET, Configuration.getServiceBaseUrl() +
"/CatalogueChampsEtendus/champs");
try {
rb.sendRequest(null, new RequestCallback() {
@Override
public void onResponseReceived(final Request request,
final Response response) {
try {
JSONValue champsJson = JSONParser.parseStrict(response.getText());
JSONArray champs = champsJson.isArray();
cacheClesLabels = new HashMap<String, String>(champs.size());
for (int i = 0; i < champs.size(); i++) {
JSONObject champ = champs.get(i).isObject();
String cle = champ.get("cle").isString().stringValue();
String label = champ.get("label").isString().stringValue();
cacheClesLabels.put(cle, label);
 
r.rafraichir(cacheClesLabels, true);
}
} catch (Exception e) {
// TODO: handle exception
}
}
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
@Override
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
e.printStackTrace();
}
} else {
r.rafraichir(cacheClesLabels, true);
}
}
public static void telechargerDescriptionWikini(final String champ, final Callback<String, String> callback) {
String url = Configuration.getWikiDescriptionChampsEtendusRestUrl()+prefixePageChampEtendu+champ+"?";
String options = Configuration.getWikiDescriptionChampsEtendusUrlOptions();
 
if(cacheDescription.containsKey(champ)) {
callback.onSuccess(cacheDescription.get(champ));
}
} catch (RequestException e) {
RequestBuilderWithCredentials rb = new RequestBuilderWithCredentials(RequestBuilderWithCredentials.GET,
url + options);
try {
rb.sendRequest(null, new RequestCallback() {
 
@Override
public void onResponseReceived(final Request request,
final Response response) {
final JSONValue responseValue = JSONParser.parse(response.getText());
String description = "";
JSONObject reponse = responseValue.isObject();
if(reponse != null && reponse.get("texte") != null && reponse.get("texte").isString() != null) {
description = reponse.get("texte").isString().stringValue();
}
cacheDescription.put(champ, description);
callback.onSuccess(description);
}
 
@Override
public void onError(Request request, Throwable exception) {
cacheDescription.put(champ, "");
callback.onFailure("");
}
});
} catch (RequestException e) {
e.printStackTrace();
}
}
// Pour obliger la page wiki a avoir été créée avant de rediriger, on utilise une requete synchrone
private static native String effectuerRequeteSynchrone(String url, String contenu, String typeRequete)/*-{
// tant pis pour les vieux navigateurs, ie6 etc...
// tous ceux que l'on supporte connaissent XMLHttpRequest
var xhReq = new XMLHttpRequest();
xhReq.open(typeRequete, url, false);
if(typeRequete == "POST") xhReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xhReq.send(contenu);
var serverResponse = xhReq.status + xhReq.responseText;
return serverResponse;
}-*/;
public static void creerPageWikini(final String champ) {
String url = Configuration.getWikiDescriptionChampsEtendusRestUrl()+prefixePageChampEtendu+champ+"?";
String options = Configuration.getWikiDescriptionChampsEtendusUrlOptions();
String pageTpl = Configuration.getWikiDescriptionChampsEtendusUrlOptionsPageTpl();
effectuerRequeteSynchrone(url + options + pageTpl, "", "GET");
}
public static String obtenirUrlEditionDescriptionWiki(String cle) {
String url = Configuration.getWikiDescriptionChampsEtendusPageUrl()+prefixePageChampEtendu+cle+"/edit";
return url;
}
}
/trunk/src/org/tela_botanica/client/modeles/objets/Configuration.java
66,6 → 66,14
private static List<InfosReferentielNom> referentielsDispos;
private static String activerSaisieChampsEtendus = "0";
private static String wikiDescriptionChampsEtendusPageUrl = "";
private static String wikiDescriptionChampsEtendusRestUrl = "";
private static String wikiDescriptionChampsEtendusRestUrlOptions = "";
private static String wikiDescriptionChampsEtendusUrlOptionsPageTpl = "";
 
/**
* Constructeur sans argument
129,6 → 137,18
activerSaisieChampsEtendus = Dictionary.getDictionary("configuration").get(
"activerSaisieChampsEtendus");
wikiDescriptionChampsEtendusPageUrl = Dictionary.getDictionary("configuration").get(
"wikiDescriptionChampsEtendusPageUrl");
wikiDescriptionChampsEtendusRestUrl = Dictionary.getDictionary("configuration").get(
"wikiDescriptionChampsEtendusRestUrl");
wikiDescriptionChampsEtendusRestUrlOptions = Dictionary.getDictionary("configuration").get(
"wikiDescriptionChampsEtendusRestUrlOptions");
wikiDescriptionChampsEtendusUrlOptionsPageTpl = Dictionary.getDictionary("configuration").get(
"wikiDescriptionChampsEtendusUrlOptionsPageTpl");
// Pour test, l'activation de l'ajout des champs étendus est activable ou désactivable par
// l'url
if(Location.getParameter("activerSaisieChampsEtendus") != null) {
265,4 → 285,20
public static boolean saisieChampsEtendusActivee() {
return activerSaisieChampsEtendus.equals("1");
}
public static String getWikiDescriptionChampsEtendusPageUrl() {
return wikiDescriptionChampsEtendusPageUrl;
}
public static String getWikiDescriptionChampsEtendusRestUrl() {
return wikiDescriptionChampsEtendusRestUrl;
}
public static String getWikiDescriptionChampsEtendusUrlOptions() {
return wikiDescriptionChampsEtendusRestUrlOptions;
}
public static String getWikiDescriptionChampsEtendusUrlOptionsPageTpl() {
return wikiDescriptionChampsEtendusUrlOptionsPageTpl;
}
}
/trunk/src/org/tela_botanica/client/modeles/objets/ListeGroupesChampsEtendus.java
3,6 → 3,9
import java.util.HashMap;
import java.util.Iterator;
 
import org.tela_botanica.client.cel2;
 
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONValue;
9,26 → 12,40
 
public class ListeGroupesChampsEtendus extends HashMap<String,HashMap<String, String>> {
public HashMap<String, String> correspondancesClesLabels ;
public ListeGroupesChampsEtendus(String groupeChampsEtendusJson) {
super();
try {
JSONValue groupesJson = JSONParser.parse(groupeChampsEtendusJson);
JSONObject groupes = groupesJson.isObject();
correspondancesClesLabels = new HashMap<String, String>();
JSONValue groupesJson = JSONParser.parseStrict(groupeChampsEtendusJson);
JSONArray groupes = groupesJson.isArray();
for (Iterator<String> iterator = groupes.keySet().iterator(); iterator.hasNext();) {
String groupe = iterator.next();
JSONValue listeClesLabelsJson = groupes.get(groupe);
JSONObject listeClesLabels = listeClesLabelsJson.isObject();
for (int i = 0; i < groupes.size(); i++) {
JSONObject groupe = groupes.get(i).isObject();
String nomGroupe = groupe.get("nom").isString().stringValue();
JSONArray listeClesLabels = groupe.get("champs").isArray();
HashMap<String, String> groupesClesLabel = new HashMap<String, String>();
for (Iterator<String> itCleLabels = listeClesLabels.keySet().iterator(); itCleLabels.hasNext();) {
String cle = itCleLabels.next();
String label = listeClesLabels.get(cle).isString().stringValue();
for (int j = 0; j < listeClesLabels.size(); j++) {
JSONObject champ = listeClesLabels.get(j).isObject();
String cle = champ.get("cle").isString().stringValue();
String label = champ.get("label").isString().stringValue();
groupesClesLabel.put(cle, label);
correspondancesClesLabels.put(cle, label);
}
this.put(groupe, groupesClesLabel);
this.put(nomGroupe, groupesClesLabel);
}
} catch (Exception e) {
// TODO: handle exception
}
}
public HashMap<String, String> getCorrespondancesClesLabel() {
return correspondancesClesLabels;
}
}