8,57 → 8,31 |
|
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.dao.ListeReferentielChampsEtendusDAO; |
import org.tela_botanica.client.modeles.objets.ListeChampsEtendus; |
import org.tela_botanica.client.modeles.objets.ListeGroupesChampsEtendus; |
import org.tela_botanica.client.util.autocompletion.AutoCompletionComboBox; |
|
import com.google.gwt.core.client.Callback; |
import com.google.gwt.user.client.Timer; |
import com.google.gwt.event.dom.client.ChangeEvent; |
import com.google.gwt.event.dom.client.ChangeHandler; |
import com.google.gwt.http.client.Response; |
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.Label; |
import com.google.gwt.user.client.ui.ListBox; |
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.SimpleStore; |
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 { |
|
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; |
final String resultTplRefPerso = "<div class=\"search-item-ref\">{label_fmt}</div>"; |
final AutoCompletionComboBox nChamp; |
Button ajouterChampsEtenduEtFermer; |
Button ajouterChampsEtendu; |
Button annulerAjouterChampEtendu; |
65,20 → 39,16 |
String idChamp = null; |
|
Panel conteneurGroupesChampsEtendus; |
final ComboBox groupesChampsEtendus; |
Panel conteneurlabelGroupe; |
ListBox listeGroupeChampsEtendus; |
HTML indicationSaisieGroupe; |
|
private static ListeGroupesChampsEtendus cacheGroupes; |
private static Map<String, String> cacheLabelsCle; |
|
private Timer timer = null; |
|
private static Map<String, String> cacheClesValeur; |
private HTML descriptionChamp = null; |
private String groupeSelectionne = null; |
|
private Record rdSelectionne = null; |
private Record groupeSelectionne = null; |
private String valeurBrute = ""; |
|
public FormulaireSaisieChampEtendu() { |
super(); |
setPaddings(3); |
89,16 → 59,15 |
"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.setDisplayField("label") ; |
groupesChampsEtendus.setValueField("cle"); |
groupesChampsEtendus.setEditable(false); |
groupesChampsEtendus.setHideTrigger(false); |
groupesChampsEtendus.setForceSelection(true); |
groupesChampsEtendus.setCls("champ-separation"); |
groupesChampsEtendus.setValue(""); |
conteneurlabelGroupe = new Panel(); |
conteneurlabelGroupe.setStyleName("panneauEnLigne"); |
conteneurlabelGroupe.addStyleName("selecteurGroupeEtendus"); |
conteneurlabelGroupe.setBorder(false); |
Label labelGroupeChampsEtendus = new Label("Ajouter un groupe de champs :"); |
listeGroupeChampsEtendus = new ListBox(); |
listeGroupeChampsEtendus.setWidth("315px"); |
conteneurlabelGroupe.add(labelGroupeChampsEtendus); |
conteneurlabelGroupe.add(listeGroupeChampsEtendus); |
|
conteneurGroupesChampsEtendus = new Panel(); |
conteneurGroupesChampsEtendus.setBorder(false); |
126,19 → 95,38 |
|
HorizontalPanel hp = new HorizontalPanel(); |
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); |
|
|
nChamp = new AutoCompletionComboBox("Nom du champ", ListeReferentielChampsEtendusDAO.getUrlRequeteNomsChampsEtendus()) { |
@Override |
protected Map<String, String> parserResultatRequete( |
Response response) { |
Map<String, String> clesLabels = ListeReferentielChampsEtendusDAO.parserRetourListeNomsChampsEtendus(response); |
cacheLabelsCle = new HashMap<String, String>(); |
for(Map.Entry<String, String> entry : clesLabels.entrySet()){ |
cacheLabelsCle.put(entry.getValue(), entry.getKey()); |
} |
return clesLabels; |
} |
|
@Override |
protected void onSelectionValeur() { |
telechargerEtAfficherDescriptionChamps(cacheLabelsCle.get(nChamp.getRawValue())); |
} |
|
@Override |
protected void onValidationSaisie() { |
// rien à faire ici |
} |
|
@Override |
protected void onModificationValeur() { |
// rien à faire ici non plus |
} |
|
}; |
|
nChamp.addStyleName("panneauEnLigne"); |
add(nChamp); |
|
descriptionChamp = new HTML(); |
161,96 → 149,19 |
} |
|
private void ajouterListeners() { |
ListenerConfig listenerConfigAutocompletion=new ListenerConfig(); |
listenerConfigAutocompletion.setDelay(200); |
listenerConfigAutocompletion.setStopPropagation(false); |
listenerConfigAutocompletion.setStopEvent(true); |
|
nChamp.addKeyPressListener(new EventCallback() { |
|
|
listeGroupeChampsEtendus.addChangeHandler(new ChangeHandler() { |
@Override |
public void execute(EventObject e) { |
|
switch(e.getKey()) { |
|
case KEY_ALT: |
case KEY_CTRL: |
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_ENTER: |
if(rdSelectionne != null) { |
nChamp.setValue(rdSelectionne.getAsString("label")); |
valeurBrute = rdSelectionne.getAsString("cle"); |
} |
break; |
|
case KEY_DOWN: |
if(nChamp.getValueAsString().isEmpty() && !nChamp.isExpanded()) { |
obtenirListeValeurs("*"); |
} |
break; |
|
case KEY_ESCAPE: |
surAnnulation(); |
break; |
|
default: |
if(timer != null) { |
timer.cancel(); |
} |
timer = new Timer() { |
|
@Override |
public void run() { |
obtenirListeValeurs(); |
} |
}; |
timer.schedule(300); |
valeurBrute = nChamp.getRawValue(); |
nChamp.setRawValue(valeurBrute); |
} |
public void onChange(ChangeEvent event) { |
groupeSelectionne = listeGroupeChampsEtendus.getValue(listeGroupeChampsEtendus.getSelectedIndex()); |
} |
},listenerConfigAutocompletion); |
|
nChamp.addListener(new ComboBoxListenerAdapter() { |
@Override |
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) { |
if(rdSelectionne != null && !rdSelectionne.getAsString("cle").equals(valeurBrute)) { |
nChamp.setRawValue(valeurBrute); |
} |
telechargerEtAfficherDescriptionChamps(valeurBrute); |
} |
}); |
}); |
|
groupesChampsEtendus.addListener(new ComboBoxListenerAdapter() { |
@Override |
public void onSelect(ComboBox comboBox, Record record, int index) { |
groupeSelectionne = record; |
} |
}); |
|
ajouterChampsEtenduEtFermer.addListener(new ButtonListenerAdapter() { |
@Override |
public void onClick(Button button, EventObject e) { |
if(doitAjouterGroupe()) { |
surValidationMultiple(renvoyerListeChampsEtendus(groupeSelectionne.getAsString("cle"))); |
surValidationMultiple(renvoyerListeChampsEtendus(groupeSelectionne)); |
} else { |
if(champEtenduEstValide()) { |
surValidation(validerEtRenvoyerChampEtendu()); |
282,19 → 193,16 |
} |
|
private void raz() { |
timer = null; |
idChamp = null; |
nChamp.clearValue(); |
nChamp.reset(); |
nChamp.focus(); |
} |
|
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); |
String labelChamp = nChamp.getRawValue(); |
String cleChamp = cacheLabelsCle.containsKey(labelChamp) ? cacheLabelsCle.get(labelChamp) : labelChamp; |
ChampSaisieEtendu retour = new ChampSaisieEtendu(labelChamp, cleChamp, ListeReferentielChampsEtendusDAO.getUrlRequeteValeursChampEtendu(cleChamp)); |
retour.setId(cleChamp); |
return retour; |
} |
|
304,7 → 212,7 |
for (Iterator<String> iterator = listeChampsEtendus.keySet().iterator(); iterator.hasNext();) { |
String cle = iterator.next(); |
String label = listeChampsEtendus.get(cle); |
ChampSaisieEtendu champ = new ChampSaisieEtendu(label, cle); |
ChampSaisieEtendu champ = new ChampSaisieEtendu(label, cle, ListeReferentielChampsEtendusDAO.getUrlRequeteValeursChampEtendu(cle)); |
champsDuGroupe.add(champ); |
} |
|
312,7 → 220,7 |
} |
|
private boolean doitAjouterGroupe() { |
return groupeSelectionne != null && !groupeSelectionne.getAsString("cle").equals(""); |
return groupeSelectionne != null && !groupeSelectionne.equals(""); |
} |
|
private boolean champEtenduEstValide() { |
320,19 → 228,6 |
return (valeurChamp != null && !valeurChamp.isEmpty()); |
} |
|
private boolean estUnChampSelectionne(String valeur) { |
return cacheClesValeur.containsValue(valeur); |
} |
|
private void obtenirListeValeurs() { |
obtenirListeValeurs(nChamp.getRawValue()); |
} |
|
private void obtenirListeValeurs(String valeur) { |
ListeReferentielChampsEtendusDAO lrce = new ListeReferentielChampsEtendusDAO(null); |
lrce.obtenirListeNomsChampsEtendus(this, valeur+"*"); |
} |
|
public abstract void surAjout(ChampSaisieEtendu champ); |
public abstract void surAjoutMultiple(List<ChampSaisieEtendu> champs); |
public abstract void surValidation(ChampSaisieEtendu champ); |
339,53 → 234,17 |
public abstract void surValidationMultiple(List<ChampSaisieEtendu> champs); |
public abstract void surAnnulation(); |
|
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) { |
|
if(nouvelleDonnees instanceof ListeChampsEtendus) { |
int i = 0; |
|
ListeChampsEtendus clesLabels = (ListeChampsEtendus)nouvelleDonnees; |
cacheClesValeur = clesLabels; |
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); |
|
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 defLabelFmt = new StringFieldDef("label_fmt"); |
FieldDef[] defTab = {defCle, defLabel, defLabelFmt}; |
|
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(); |
} |
|
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) { |
if(nouvelleDonnees instanceof ListeGroupesChampsEtendus) { |
cacheGroupes = (ListeGroupesChampsEtendus)nouvelleDonnees; |
groupesChampsEtendus.setStore(getGroupesChampsEtendusStore(cacheGroupes)); |
listeGroupeChampsEtendus.addItem("..."); |
for (Iterator<String> iterator = cacheGroupes.keySet().iterator(); iterator.hasNext();) { |
listeGroupeChampsEtendus.addItem(iterator.next()); |
} |
|
if(cacheGroupes.size() > 0) { |
conteneurGroupesChampsEtendus.add(indicationSaisieGroupe); |
conteneurGroupesChampsEtendus.add(groupesChampsEtendus); |
conteneurGroupesChampsEtendus.add(conteneurlabelGroupe); |
doLayout(); |
} |
} |
422,41 → 281,4 |
descriptionChamp.setHTML("<span class=\"descriptionChampEtenduTitre\">Description :</span> "+description); |
} |
} |
|
private Store getGroupesChampsEtendusStore(ListeGroupesChampsEtendus listeGroupesChampsEtendus) { |
int i = 1; |
Object[][] valeurs = new Object[listeGroupesChampsEtendus.size()+1][2]; |
|
valeurs[0][0] = "..."; |
valeurs[0][1] = ""; |
if(listeGroupesChampsEtendus.size() > 0) { |
for (Iterator<String> it = listeGroupesChampsEtendus.keySet().iterator(); it.hasNext();) |
{ |
String cle = it.next(); |
valeurs[i][0]= cle; |
valeurs[i][1]= cle; |
i++; |
} |
} |
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; |
} |
} |