10,6 → 10,8 |
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.user.client.Timer; |
import com.google.gwt.user.client.Window; |
27,11 → 29,13 |
import com.gwtext.client.data.Store; |
import com.gwtext.client.data.StringFieldDef; |
import com.gwtext.client.widgets.Button; |
import com.gwtext.client.widgets.Panel; |
import com.gwtext.client.widgets.event.ButtonListenerAdapter; |
import com.gwtext.client.widgets.form.ComboBox; |
import com.gwtext.client.widgets.form.Field; |
import com.gwtext.client.widgets.form.FormPanel; |
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter; |
import com.gwtext.client.widgets.layout.FormLayout; |
|
@SuppressWarnings("unchecked") |
public abstract class FormulaireSaisieChampEtendu extends FormPanel implements Rafraichissable { |
60,11 → 64,15 |
Button annulerAjouterChampEtendu; |
String idChamp = null; |
|
Panel conteneurGroupesChampsEtendus; |
final ComboBox groupesChampsEtendus; |
HTML indicationSaisieGroupe; |
|
private static ListeGroupesChampsEtendus cacheGroupes; |
|
private Timer timer = null; |
|
private Map<String, String> cacheClesValeur; |
private static Map<String, String> cacheClesValeur; |
private Record rdSelectionne = null; |
private Record groupeSelectionne = null; |
private String valeurBrute = ""; |
74,14 → 82,14 |
setPaddings(3); |
setBodyBorder(false); |
|
HTML indicationSaisieGroupe = new HTML("Vous pouvez ajouter plusieurs champs à la fois correspondant à un groupe "+ |
"par exemple les champs du projet sauvage de ma rue ou florilèges, ou bien "+ |
"les champs phytosociolgiques "); |
indicationSaisieGroupe = new HTML("Vous pouvez ajouter plusieurs champs à la fois correspondant à un groupe "+ |
"par exemple les champs des projet 'sauvages de ma rue' ou 'florilèges', etc... <br />"+ |
"De nouveaux groupes seront ajoutés régulièrement en fonction des champs les plus utilisés"); |
indicationSaisieGroupe.addStyleName("aideCreerChampEtendu"); |
|
groupesChampsEtendus = new ComboBox(); |
groupesChampsEtendus.setWidth("350px"); |
groupesChampsEtendus.setLabel("Ajouter un groupe de champs"); |
groupesChampsEtendus.setStore(getGroupesChampsEtendusStore()); |
groupesChampsEtendus.setDisplayField("label") ; |
groupesChampsEtendus.setValueField("valeur"); |
groupesChampsEtendus.setEditable(false); |
90,14 → 98,25 |
groupesChampsEtendus.setCls("champ-separation"); |
groupesChampsEtendus.setValue(""); |
|
if(groupesChampsEtendusSontDefinis()) { |
add(indicationSaisieGroupe); |
add(groupesChampsEtendus); |
conteneurGroupesChampsEtendus = new Panel(); |
conteneurGroupesChampsEtendus.setBorder(false); |
conteneurGroupesChampsEtendus.setPaddings(0); |
conteneurGroupesChampsEtendus.setMargins(0); |
conteneurGroupesChampsEtendus.setLayout(new FormLayout()); |
conteneurGroupesChampsEtendus.setWidth("100%"); |
|
add(conteneurGroupesChampsEtendus); |
|
if(cacheGroupes == null) { |
ListeReferentielChampsEtendusDAO lrceDao = new ListeReferentielChampsEtendusDAO(null); |
lrceDao.obtenirGroupesChampsEtendus(this); |
} else { |
this.rafraichir(cacheGroupes, false); |
} |
|
|
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 valeur déjà saisies pour ce champ par les autres utilisateurs"); |
"sur les valeurs déjà saisies pour ce champ par les autres utilisateurs"); |
indicationSaisie.addStyleName("aideCreerChampEtendu"); |
add(indicationSaisie); |
|
126,7 → 145,7 |
nChamp.setLoadingText("Recherche..."); |
nChamp.setHideTrigger(true); |
nChamp.setValidateOnBlur(false); |
nChamp.setWidth("250px"); |
nChamp.setWidth("350px"); |
nChamp.focus(); |
|
ajouterListeners(); |
275,7 → 294,7 |
|
private List<ChampSaisieEtendu> renvoyerListeChampsEtendus(String groupe) { |
List<ChampSaisieEtendu> champsDuGroupe = new ArrayList<ChampSaisieEtendu>(); |
HashMap<String, String> listeChampsEtendus = Configuration.getGroupesChampsEtendus().get(groupe); |
HashMap<String, String> listeChampsEtendus = cacheGroupes.get(groupe); |
for (Iterator<String> iterator = listeChampsEtendus.keySet().iterator(); iterator.hasNext();) { |
String cle = iterator.next(); |
String label = listeChampsEtendus.get(cle); |
315,44 → 334,51 |
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++; |
if(nouvelleDonnees instanceof ListeChampsEtendus) { |
int i = 0; |
|
ListeChampsEtendus clesLabels = (ListeChampsEtendus)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(); |
} |
|
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(); |
if(nouvelleDonnees instanceof ListeGroupesChampsEtendus) { |
cacheGroupes = (ListeGroupesChampsEtendus)nouvelleDonnees; |
groupesChampsEtendus.setStore(getGroupesChampsEtendusStore(cacheGroupes)); |
if(cacheGroupes.size() > 0) { |
conteneurGroupesChampsEtendus.add(indicationSaisieGroupe); |
conteneurGroupesChampsEtendus.add(groupesChampsEtendus); |
doLayout(); |
} |
} |
} |
|
private boolean groupesChampsEtendusSontDefinis() { |
return Configuration.getGroupesChampsEtendus().size() > 0; |
} |
|
private Store getGroupesChampsEtendusStore() { |
int i = 1; |
|
Map<String, HashMap<String, String>> listeGroupesChampsEtendus = Configuration.getGroupesChampsEtendus(); |
private Store getGroupesChampsEtendusStore(ListeGroupesChampsEtendus listeGroupesChampsEtendus) { |
int i = 1; |
Object[][] valeurs = new Object[listeGroupesChampsEtendus.size()+1][2]; |
|
valeurs[0][0] = "..."; |