New file |
0,0 → 1,542 |
package org.tela_botanica.client.vues; |
|
|
|
import java.util.Iterator; |
|
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.ListeReferentielCommune; |
import org.tela_botanica.client.modeles.ListeReferentielNom; |
import org.tela_botanica.client.modeles.Observation; |
import org.tela_botanica.client.modeles.ReferentielCommune; |
import org.tela_botanica.client.modeles.ReferentielNom; |
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.core.Position; |
import com.gwtext.client.data.ArrayReader; |
import com.gwtext.client.data.FieldDef; |
import com.gwtext.client.data.MemoryProxy; |
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.Panel; |
import com.gwtext.client.widgets.event.ButtonListenerAdapter; |
import com.gwtext.client.widgets.form.ComboBox; |
import com.gwtext.client.widgets.form.DateField; |
import com.gwtext.client.widgets.form.FormPanel; |
import com.gwtext.client.widgets.form.TextField; |
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter; |
import com.gwtext.client.widgets.layout.ColumnLayout; |
import com.gwtext.client.widgets.layout.ColumnLayoutData; |
import com.gwtext.client.widgets.layout.FormLayout; |
import com.gwtext.client.data.Record; |
|
/** |
* Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable |
* @author aurelien |
* |
*/ |
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable { |
|
|
/** |
* Le médiateur associé à la vue |
*/ |
private ObservationMediateur observationMediateur = null; |
|
|
|
private DateField date = null; |
private TextField lieudit = null; |
private TextField station = null; |
private TextField milieu = null; |
private TextField comment = null; |
private ComboBox commune = null; |
private String departement = null; |
private ComboBox espece = null; |
private String numeroNom = null; |
|
private Button boutonOK = new Button("Ok"); |
private Button boutonAnnuler = new Button("Annuler"); |
|
private boolean selectionCommune=false; |
private boolean selectionEspece=false; |
|
|
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; |
|
|
|
|
/** |
* Booleen d'instanciation |
*/ |
boolean estInstancie = false ; |
|
/** |
* Constructeur sans argument (privé car ne doit pas être utilisé) |
*/ |
private FormulaireSaisieObservationVue() |
{ |
super() ; |
} |
|
/** |
* Constructeur avec argument |
* @param im |
*/ |
public FormulaireSaisieObservationVue(ObservationMediateur obs) |
{ |
|
|
// on associe le médiateur |
observationMediateur = obs ; |
|
this.setHeader(true); |
this.setTitle("Saisie"); |
|
|
this.setCollapsible(true) ; |
|
FormPanel panneauFormulaire = new FormPanel(Position.RIGHT); |
panneauFormulaire.setBorder(false); |
|
// Panneau intermediaire qui contient deux colonnes de formulaire |
|
Panel panneauIntermediaire = new Panel(); |
panneauIntermediaire.setLayout(new ColumnLayout()); |
panneauIntermediaire.setBorder(false); |
|
//create first panel and add fields to it |
Panel panneauPremierColonne = new Panel(); |
panneauPremierColonne.setLayout(new FormLayout()); |
panneauPremierColonne.setBorder(false); |
|
//create second panel and add fields to it |
Panel panneauSecondeColonne = new Panel(); |
panneauSecondeColonne.setLayout(new FormLayout()); |
panneauSecondeColonne.setBorder(false); |
|
this.setPaddings(5) ; |
|
|
|
commune=new ComboBox("Commune","commune",275 ); |
|
|
final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>"; |
|
|
commune.setTpl(resultTplCommune); |
commune.setMode(ComboBox.REMOTE); |
// commune.setPageSize(10); // Ne fonctionne pas |
commune.setItemSelector("div.search-item-commune"); |
commune.setTypeAhead(true); |
commune.setLoadingText("Recherche..."); |
|
commune.setHideTrigger(true); |
|
|
|
|
|
panneauPremierColonne.add(commune); |
|
|
|
station = new TextField("Station", "station", 275); |
station.setAllowBlank(true); |
panneauPremierColonne.add(station); |
|
date = new DateField("Date", "date", 100); |
date.setAllowBlank(true); |
date.setFormat("d/m/Y") ; |
panneauPremierColonne.add(date); |
|
|
espece=new ComboBox("Espèce","nom",275 ); |
|
|
final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>"; |
|
|
espece.setTpl(resultTplEspece); |
espece.setMode(ComboBox.REMOTE); |
// commune.setPageSize(10); // Ne fonctionne pas |
espece.setItemSelector("div.search-item-espece"); |
espece.setTypeAhead(true); |
espece.setLoadingText("Recherche..."); |
|
espece.setHideTrigger(true); |
|
|
|
panneauPremierColonne.add(espece); |
|
comment = new TextField("Notes", "comment", 275); |
comment.setAllowBlank(true); |
panneauPremierColonne.add(comment); |
|
|
lieudit = new TextField("Lieu-dit", "lieudit", 275); |
lieudit.setAllowBlank(true); |
panneauSecondeColonne.add(lieudit); |
|
|
milieu = new TextField("Milieu", "milieu", 275); |
milieu.setAllowBlank(true); |
panneauSecondeColonne.add(milieu); |
|
|
|
panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5)); |
panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5)); |
|
panneauFormulaire.add(panneauIntermediaire); |
|
|
panneauFormulaire.addButton(boutonOK); |
|
|
panneauFormulaire.addButton(boutonAnnuler); |
|
|
this.add(panneauFormulaire) ; |
|
|
this.setAutoHeight(true); |
|
|
// on ajoute les listeners |
ajouterListeners() ; |
|
|
|
} |
|
private void ajouterListeners() |
{ |
|
|
// Listener completion communne |
|
commune.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
commune.setValue(record.getAsString("commune")); |
departement=record.getAsString("departement"); |
selectionCommune=true; |
} |
}); |
|
|
ListenerConfig listenerConfigCommune=new ListenerConfig(); |
listenerConfigCommune.setDelay(10); |
listenerConfigCommune.setStopPropagation(false); |
listenerConfigCommune.setStopEvent(false); |
|
|
|
commune.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 (selectionCommune) { |
selectionCommune=false; |
} |
else { |
// lancer mise a jour |
} |
|
|
break; |
|
default: |
|
obtenirListeReferentielCommune(); |
|
break; |
} |
|
|
|
} |
|
}, listenerConfigCommune |
|
); |
|
// Listener completion espece |
|
|
espece.addListener(new ComboBoxListenerAdapter() { |
public void onSelect(ComboBox comboBox, Record record, int index) { |
espece.setValue(record.getAsString("nom")); |
numeroNom=record.getAsString("numeroNom"); |
selectionEspece=true; |
} |
}); |
|
|
ListenerConfig listenerConfigEspece=new ListenerConfig(); |
listenerConfigEspece.setDelay(10); |
listenerConfigEspece.setStopPropagation(false); |
listenerConfigEspece.setStopEvent(false); |
|
|
espece.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 (selectionEspece) { |
selectionEspece=false; |
} |
else { |
// lancer mise a jour |
} |
|
|
break; |
|
default: |
|
obtenirListeReferentielNom(); |
|
break; |
} |
|
|
|
} |
|
}, listenerConfigEspece |
|
); |
|
|
|
|
boutonOK.addListener(new ButtonListenerAdapter() { |
|
public void onClick(Button button, EventObject e) { |
|
ajouterObservation(); |
|
} |
|
|
}); |
|
// on ajoute un écouteur |
/*validerInfo.addListener(new ButtonListenerAdapter() { |
|
// gestion du clic |
|
public void onClick(Button button, EventObject e) { |
|
// lors du clic sur le bouton valider on met à jour les commentaires et la date |
// getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ; |
|
} |
}); |
*/ |
|
|
} |
|
/** |
* Desactive visuellement ce panneau |
*/ |
public void desactiverPanneau() |
{ |
this.setDisabled(true) ; |
} |
|
/** |
* Active visuellement ce panneau |
*/ |
public void activerPanneau() |
{ |
this.setDisabled(false) ; |
} |
|
public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) { |
|
// si l'on a reçu une liste du referentiel commune (completion referentiel commune) |
if(nouvelleDonnees instanceof ListeReferentielCommune) |
{ |
|
ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ; |
Object[][] communeData = new Object[data.size()][2]; |
int i = 0 ; |
|
// on la parse et on récupère les informations quiç nous interessent |
for (Iterator it = data.keySet().iterator(); it.hasNext();) |
{ |
|
ReferentielCommune ref=(ReferentielCommune) data.get(it.next()); |
|
communeData[i][0]= ref.getCommune(); |
communeData[i][1]= ref.getDepartement(); |
|
|
i++ ; |
} |
|
// creation du store |
FieldDef defCommune = new StringFieldDef("commune"); |
FieldDef defDepartement = new StringFieldDef("departement"); |
|
|
FieldDef[] defTab = { defCommune, defDepartement}; |
|
RecordDef rd = new RecordDef(defTab); |
|
final MemoryProxy dataProxy = new MemoryProxy(communeData); |
final ArrayReader reader = new ArrayReader(rd); |
|
Store store=new Store(dataProxy,reader); |
store.load() ; |
|
commune.setStore(store); |
|
} |
|
// si l'on a reçu une liste du referentiel nom (complétion referentiel nom) |
|
if(nouvelleDonnees instanceof ListeReferentielNom) |
{ |
|
ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ; |
Object[][] nomData = new Object[data.size()][2]; |
int i = 0 ; |
|
// on la parse et on récupère les informations quiç nous interessent |
for (Iterator it = data.keySet().iterator(); it.hasNext();) |
{ |
|
ReferentielNom ref=(ReferentielNom) data.get(it.next()); |
|
nomData[i][0]= ref.getNom(); |
nomData[i][1]= ref.getNumeroNom(); |
|
|
i++ ; |
} |
|
// creation du store |
FieldDef defNom = new StringFieldDef("nom"); |
FieldDef defNumeroNom = new StringFieldDef("numeroNom"); |
|
|
FieldDef[] defTab = { defNom, defNumeroNom}; |
|
RecordDef rd = new RecordDef(defTab); |
|
final MemoryProxy dataProxy = new MemoryProxy(nomData); |
final ArrayReader reader = new ArrayReader(rd); |
|
Store store=new Store(dataProxy,reader); |
store.load() ; |
|
espece.setStore(store); |
|
|
|
} |
|
|
|
} |
|
|
public void obtenirListeReferentielCommune() { |
String com=commune.getText().replaceAll(" ","/"); |
com=com.replaceAll("%",""); |
|
observationMediateur.obtenirListeReferentielCommune(this,com); |
|
} |
|
|
public void obtenirListeReferentielNom() { |
|
String esp=espece.getText().replaceAll(" ","/"); |
esp=esp.replaceAll("%",""); |
|
observationMediateur.obtenirListeReferentielNom(this,esp); |
|
} |
|
|
public void ajouterObservation() { |
|
Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText()); |
observationMediateur.ajouterObservation(obs); |
} |
|
|
} |