Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1939 → Rev 1940

/trunk/src/org/tela_botanica/client/modeles/objets/Configuration.java
57,6 → 57,8
private static String tailleMaxUpload;
private static List<InfosReferentielNom> referentielsDispos;
private static String activerSaisieChampsEtendus = "0";
 
/**
* Constructeur sans argument
113,6 → 115,9
referentielsDispos = parserReferentielsDispos(Dictionary.getDictionary("configuration").get(
"referentielsDispos"));
activerSaisieChampsEtendus = Dictionary.getDictionary("configuration").get(
"activerSaisieChampsEtendus");
}
private List<InfosReferentielNom> parserReferentielsDispos(String chaineListeReferentiels) {
227,4 → 232,8
public static List<InfosReferentielNom> getReferentielsDispos() {
return referentielsDispos;
}
public static boolean saisieChampsEtendusActivee() {
return activerSaisieChampsEtendus.equals("1");
}
}
/trunk/src/org/tela_botanica/client/modeles/objets/InfosReferentielNom.java
1,7 → 1,5
package org.tela_botanica.client.modeles.objets;
 
import com.google.gwt.user.client.Window;
 
public class InfosReferentielNom {
private String code = null;
/trunk/src/org/tela_botanica/client/util/AutoCompletionRefComboBox.java
131,7 → 131,7
int i = 0;
Object[][] refData = new Object[referentielPerso.size()][1];
for (Iterator it = referentielPerso.keySet().iterator(); it.hasNext();)
for (Iterator<String> it = referentielPerso.keySet().iterator(); it.hasNext();)
{
String ref= referentielPerso.get(it.next());
refData[i][0]= ref;
/trunk/src/org/tela_botanica/client/util/ChampSaisieEtendu.java
New file
0,0 → 1,189
package org.tela_botanica.client.util;
 
import java.util.ArrayList;
import java.util.Iterator;
 
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
 
import com.google.gwt.user.client.Timer;
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;
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.Component;
import com.gwtext.client.widgets.event.ComponentListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
 
public class ChampSaisieEtendu 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 boolean selectionValeur = false;
private boolean estModifie = false;
private String cle = null;
private String label = null;
private Timer timer = null;
final String resultTplRefPerso = "<div class=\"search-item-ref\">{valeur}</div>";
public ChampSaisieEtendu(String label, String cle) {
// Accesskey pour debugging
super(label,cle);
 
this.cle =cle;
this.label = label;
setTpl(resultTplRefPerso);
setMode(ComboBox.REMOTE);
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() {
 
@Override
public void execute(EventObject e) {
 
switch(e.getKey()) {
case KEY_ALT:
case KEY_CTRL:
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_DOWN:
if(getValueAsString().isEmpty() && !isExpanded()) {
obtenirListeValeurs("*");
}
break;
default:
if(timer != null) {
timer.cancel();
}
timer = new Timer() {
@Override
public void run() {
obtenirListeValeurs();
}
};
timer.schedule(300);
}
}
},listenerConfigAutocompletion);
// Listener completion
addListener(new ComboBoxListenerAdapter() {
@Override
public void onSelect(ComboBox comboBox, Record record, int index) {
setValue(record.getAsString("valeur"));
selectionValeur=true;
collapse();
}
});
this.addListener(new ComponentListenerAdapter() {
@Override
public void onRender(Component component) {
setLargeurChamp();
}
});
}
 
@Override
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
@SuppressWarnings("unchecked")
ArrayList<String> valeurs = (ArrayList<String>)nouvelleDonnees;
int i = 0;
Object[][] refData = new Object[valeurs.size()][1];
for (Iterator<String> it = valeurs.iterator(); it.hasNext();)
{
refData[i][0]= it.next();
i++;
}
FieldDef defValeur = new StringFieldDef("valeur");
FieldDef[] defTab = {defValeur};
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 obtenirListeValeurs() {
String valeurChamp = getValue();
obtenirListeValeurs(valeurChamp);
}
private void obtenirListeValeurs(String valeurChamp) {
if(valeurChamp == null) {
valeurChamp = "";
} else {
valeurChamp += "*";
}
ListeReferentielChampsEtendusDAO lrceDao = new ListeReferentielChampsEtendusDAO(null);
lrceDao.obtenirListeValeursChampEtendu(this, cle, valeurChamp);
}
public void setLargeurChamp() {
// Correction un peu moche pour améliorer l'affichage du champ
String idElementEnfant = Ext.get(("x-form-el-"+cle)).getFirstChild().getId();
Ext.get(idElementEnfant).setWidth("90%", false);
Ext.get(cle).setWidth("100%", false);
}
}
/trunk/src/org/tela_botanica/client/util/FormulaireSaisieChampEtendu.java
New file
0,0 → 1,237
package org.tela_botanica.client.util;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
 
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO;
 
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
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.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.Button;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
 
@SuppressWarnings("unchecked")
public abstract class FormulaireSaisieChampEtendu extends FormPanel implements Rafraichissable {
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;
final ComboBox nChamp;
String resultTplRefPerso = "<div class=\"search-item-ref\">{label}</div>";
final Button ajouterChampsEtendu;
final Button annulerAjouterChampEtendu;
String idChamp = null;
private Timer timer = null;
private Map<String, String> cacheClesValeur;
public FormulaireSaisieChampEtendu() {
super();
setPaddings(3);
setBodyBorder(false);
HorizontalPanel hp = new HorizontalPanel();
hp.setBorderWidth(0);
nChamp = new ComboBox("Nom du champ", "nom_champ_etendu");
add(nChamp);
ajouterChampsEtendu = new Button("Ajouter");
annulerAjouterChampEtendu = new Button("Annuler");
hp.add(ajouterChampsEtendu);
hp.add(annulerAjouterChampEtendu);
add(hp);
nChamp.setTpl(resultTplRefPerso);
nChamp.setMode(ComboBox.REMOTE);
nChamp.setItemSelector("div.search-item-ref");
nChamp.setTypeAhead(true);
nChamp.setLoadingText("Recherche...");
nChamp.setHideTrigger(true);
nChamp.setWidth("250px");
nChamp.setValue("");
nChamp.focus();
ajouterListeners();
}
 
private void ajouterListeners() {
ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
listenerConfigAutocompletion.setDelay(200);
listenerConfigAutocompletion.setStopPropagation(false);
listenerConfigAutocompletion.setStopEvent(true);
nChamp.addKeyPressListener(new EventCallback() {
 
@Override
public void execute(EventObject e) {
 
switch(e.getKey()) {
case KEY_ALT:
case KEY_CTRL:
case KEY_ENTER:
case KEY_END:
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_DOWN:
if(nChamp.getValueAsString().isEmpty() && !nChamp.isExpanded()) {
obtenirReferentiel("*");
}
break;
case KEY_ESCAPE:
surAnnulation();
break;
default:
if(timer != null) {
timer.cancel();
}
timer = new Timer() {
@Override
public void run() {
obtenirReferentiel();
}
};
timer.schedule(300);
}
}
},listenerConfigAutocompletion);
// Listener completion
nChamp.addListener(new ComboBoxListenerAdapter() {
@Override
public void onSelect(ComboBox comboBox, Record record, int index) {
nChamp.setValue(record.getAsString("label"));
idChamp = record.getAsString("cle");
nChamp.collapse();
}
});
ajouterChampsEtendu.addListener(new ButtonListenerAdapter() {
@Override
public void onClick(Button button, EventObject e) {
validerChampEtendu();
}
});
annulerAjouterChampEtendu.addListener(new ButtonListenerAdapter() {
@Override
public void onClick(Button button, EventObject e) {
surAnnulation();
}
});
}
private void validerChampEtendu() {
String valeurChamp = nChamp.getValueAsString();
if(valeurChamp != null && !valeurChamp.isEmpty()) {
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);
surValidation(retour);
} else {
Window.alert("Le nom du champ étendu ne peut pas être vide");
}
}
private boolean estUnChampSelectionne(String valeur) {
return cacheClesValeur.containsValue(valeur);
}
private void obtenirReferentiel() {
obtenirReferentiel(nChamp.getValueAsString());
}
private void obtenirReferentiel(String valeur) {
ListeReferentielChampsEtendusDAO lrce = new ListeReferentielChampsEtendusDAO(null);
lrce.obtenirListeNomsChampsEtendus(this, valeur+"*");
}
public abstract void surValidation(ChampSaisieEtendu champ);
public abstract void surAnnulation();
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
int i = 0;
HashMap<String, String> clesLabels = (HashMap<String, String>)nouvelleDonnees;
cacheClesValeur = clesLabels;
Object[][] refData = new Object[clesLabels.keySet().size()][2];
for (Iterator<String> it = clesLabels.keySet().iterator(); it.hasNext();)
{
String cle = it.next();
String label= clesLabels.get(cle);
refData[i][0]= cle;
refData[i][1]= label;
i++;
}
FieldDef defCle = new StringFieldDef("cle");
FieldDef defLabel = new StringFieldDef("label");
FieldDef[] defTab = {defCle, defLabel};
RecordDef rd = new RecordDef(defTab);
final MemoryProxy dataProxy = new MemoryProxy(refData);
final ArrayReader reader = new ArrayReader(rd);
Store store=new Store(dataProxy,reader);
nChamp.setStore(store);
store.load();
}
}
/trunk/src/org/tela_botanica/client/vues/observation/FormulaireSaisieObservationVue.java
22,8 → 22,11
import org.tela_botanica.client.modeles.objets.ListeReferentielPerso.TypesReferentiels;
import org.tela_botanica.client.observation.ObservationMediateur;
import org.tela_botanica.client.util.AutoCompletionRefComboBox;
import org.tela_botanica.client.util.ChampSaisieEtendu;
import org.tela_botanica.client.util.FormulaireSaisieChampEtendu;
import org.tela_botanica.client.util.Util;
 
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.maps.client.geom.LatLng;
30,6 → 33,8
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.PopupPanel;
import com.gwtext.client.core.EventCallback;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Ext;
257,14 → 262,18
private boolean selectionMultiple = false;
 
private HTML lienAfficherChampsEtendus = null;
private HTML lienAjouterChampsEtendus = null;
 
Panel conteneurChampEtenduGauche = null;
Panel conteneurChampEtenduDroite = null;
 
private boolean afficherChampsEtendus = false;
private boolean afficherLienAjoutChampsEtendus = false;
private boolean premierAffichage = true;
 
private Map<String, TextField> listeChampsEtendus;
private PopupPanel popUpAjoutChampEtendu = new PopupPanel();
private Map<String, ChampSaisieEtendu> listeChampsEtendus;
 
/**
* Constructeur sans argument (privé car ne doit pas être utilisé)
561,7 → 570,7
}
 
panneauFormulaire.add(panneauIntermediaire);
 
if (Ext.isIE()) {
panneauPremierColonne.setButtonAlign(Position.RIGHT);
panneauPremierColonne.addButton(boutonOK);
624,6 → 633,15
}
}
});
if(Configuration.saisieChampsEtendusActivee()) {
lienAjouterChampsEtendus = new HTML("Ajouter un champ étendu");
lienAjouterChampsEtendus.addStyleName("lienAjouterChampEtendu");
lienAjouterChampsEtendus.setVisible(true);
panneauPremierColonne.add(lienAjouterChampsEtendus);
gererLienAjoutChampsEtendus();
}
panneauPremierColonne.add(lienAfficherChampsEtendus);
panneauPremierColonne.addListener(new PanelListenerAdapter() {
@Override
639,7 → 657,42
ajouterToolTipsBoutons();
saisieTabindex();
}
private void gererLienAjoutChampsEtendus() {
popUpAjoutChampEtendu.setStylePrimaryName("popup_champ_etendu");
lienAjouterChampsEtendus.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
FormulaireSaisieChampEtendu formChamp = new FormulaireSaisieChampEtendu() {
@Override
public void surValidation(ChampSaisieEtendu champ) {
ajouterChampEtenduAuFormulaire(champ);
popUpAjoutChampEtendu.clear();
popUpAjoutChampEtendu.hide();
}
 
@Override
public void surAnnulation() {
popUpAjoutChampEtendu.clear();
popUpAjoutChampEtendu.hide();
}
};
popUpAjoutChampEtendu.add(formChamp);
popUpAjoutChampEtendu.center();
popUpAjoutChampEtendu.setTitle("Ajout d'un champ étendu");
popUpAjoutChampEtendu.show();
}
});
}
private void ajouterChampEtenduAuFormulaire(ChampSaisieEtendu nChamp) {
ChampEtendu chet = new ChampEtendu(nChamp.getName(), nChamp.getFieldLabel(), "");
Map<String, ChampEtendu> champsEt = getValeursChampsEtendus();
champsEt.put(chet.getCle(), chet);
afficherChampsEtendus = true;
afficherChampsEtendus(champsEt, chet);
}
 
private void ajouterToolTipsBoutons() {
boutonOK.setTitle("Crée une nouvelle observation à partir des champs saisis dans le formulaire");
boutonModifier.setTitle("Modifie la ou les observations sélectionnées");
1289,11 → 1342,11
}
 
public void obtenirListeReferentielNom() {
String esp=espece.getText().replaceAll(" ","/*");
esp=esp.replaceAll("%","");
String referentiel = this.referentielTaxo;
 
observationMediateur.obtenirListeReferentielNom(this,referentiel ,esp);
String esp=espece.getText().replaceAll(" ","/*");
esp=esp.replaceAll("%","");
String referentiel = this.referentielTaxo;
observationMediateur.obtenirListeReferentielNom(this,referentiel ,esp);
}
 
protected void obtenirReferentielStation() {
1679,7 → 1732,7
selecteurReferentielTaxo.setRawValue(VALEURS_MULTIPLES);
}
 
afficherChampsEtendus(obs);
afficherChampsEtendus(obs.getChampsEtendus(), null);
}
 
private boolean doitAfficherLatLon(Observation obs) {
1709,7 → 1762,7
}
}
 
private void afficherChampsEtendus(Observation obs) {
private void afficherChampsEtendus(Map<String, ChampEtendu> champsEtendus, ChampEtendu champsAFocus) {
viderChampsEtendus();
 
FormLayout flmd = new FormLayout();
1731,22 → 1784,23
conteneurChampEtenduDroite.setBodyBorder(false);
 
// pour corriger le décalage sur le panneau induit par le lien d'affichage
conteneurChampEtenduDroite.setPaddings(25, 0, 0, 0);
conteneurChampEtenduDroite.setPaddings(42, 0, 0, 0);
 
if(obs.getChampsEtendus() != null && obs.getChampsEtendus().size() > 0) {
if(champsEtendus != null && champsEtendus.size() > 0) {
lienAfficherChampsEtendus.setVisible(true);
listeChampsEtendus = new HashMap<String, TextField>(obs.getChampsEtendus().size());
listeChampsEtendus = new HashMap<String, ChampSaisieEtendu>(champsEtendus.size());
boolean gauche = true;
for (Iterator<String> iterator = obs.getChampsEtendus().keySet().iterator(); iterator.hasNext();) {
for (Iterator<String> iterator = champsEtendus.keySet().iterator(); iterator.hasNext();) {
String id = iterator.next();
ChampEtendu champ = obs.getChampsEtendus().get(id);
ChampEtendu champ = champsEtendus.get(id);
String valeur = champ.getValeur();
String label = champ.getLabel();
 
TextField champTexteEtendu = new TextField();
champTexteEtendu.setWidth("90%");
ChampSaisieEtendu champTexteEtendu = new ChampSaisieEtendu(label, id);
if(champ.equals(champsAFocus)) {
champTexteEtendu.focus();
}
champTexteEtendu.setLabel(label);
champTexteEtendu.setTitle(label);
champTexteEtendu.setId(id);
champTexteEtendu.setValue(valeur);
if(gauche) {