1,12 → 1,9 |
package org.tela_botanica.client.vues; |
|
import java.util.ArrayList; |
import java.util.Arrays; |
import java.util.Iterator; |
import java.util.List; |
import java.util.Map; |
|
import org.tela_botanica.client.ComposantId; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.Modele; |
import org.tela_botanica.client.RegistreId; |
17,24 → 14,24 |
import org.tela_botanica.client.modeles.InterneValeur; |
import org.tela_botanica.client.modeles.InterneValeurListe; |
import org.tela_botanica.client.modeles.Personne; |
import org.tela_botanica.client.modeles.PersonneListe; |
import org.tela_botanica.client.modeles.Structure; |
import org.tela_botanica.client.modeles.StructureAPersonne; |
import org.tela_botanica.client.modeles.StructureAPersonneListe; |
import org.tela_botanica.client.modeles.StructureConservation; |
import org.tela_botanica.client.modeles.StructureListe; |
import org.tela_botanica.client.modeles.StructureValorisation; |
import org.tela_botanica.client.modeles.Valeur; |
import org.tela_botanica.client.modeles.ValeurListe; |
import org.tela_botanica.client.util.UtilArray; |
|
import com.extjs.gxt.ui.client.Events; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.HorizontalAlignment; |
import com.extjs.gxt.ui.client.Style.Scroll; |
import com.extjs.gxt.ui.client.Style.SelectionMode; |
import com.extjs.gxt.ui.client.event.BaseEvent; |
import com.extjs.gxt.ui.client.data.BaseModelData; |
import com.extjs.gxt.ui.client.event.ComponentEvent; |
import com.extjs.gxt.ui.client.event.EditorEvent; |
import com.extjs.gxt.ui.client.event.GridEvent; |
import com.extjs.gxt.ui.client.event.KeyListener; |
import com.extjs.gxt.ui.client.event.Listener; |
import com.extjs.gxt.ui.client.event.SelectionChangedEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedListener; |
41,8 → 38,6 |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.event.ToolBarEvent; |
import com.extjs.gxt.ui.client.store.ListStore; |
import com.extjs.gxt.ui.client.store.Record; |
import com.extjs.gxt.ui.client.store.Store; |
import com.extjs.gxt.ui.client.widget.Component; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
49,8 → 44,6 |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
import com.extjs.gxt.ui.client.widget.TabItem; |
import com.extjs.gxt.ui.client.widget.TabPanel; |
import com.extjs.gxt.ui.client.widget.VerticalPanel; |
import com.extjs.gxt.ui.client.widget.WidgetComponent; |
import com.extjs.gxt.ui.client.widget.button.Button; |
import com.extjs.gxt.ui.client.widget.form.CheckBox; |
import com.extjs.gxt.ui.client.widget.form.CheckBoxGroup; |
69,7 → 62,6 |
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction; |
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign; |
import com.extjs.gxt.ui.client.widget.grid.CellEditor; |
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel; |
import com.extjs.gxt.ui.client.widget.grid.CheckColumnConfig; |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel; |
83,6 → 75,7 |
import com.extjs.gxt.ui.client.widget.layout.FormData; |
import com.extjs.gxt.ui.client.widget.layout.FormLayout; |
import com.extjs.gxt.ui.client.widget.tips.ToolTipConfig; |
import com.extjs.gxt.ui.client.widget.toolbar.AdapterToolItem; |
import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem; |
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem; |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
89,11 → 82,7 |
import com.google.gwt.core.client.GWT; |
import com.google.gwt.i18n.client.DateTimeFormat; |
import com.google.gwt.i18n.client.NumberFormat; |
import com.google.gwt.user.client.Event; |
import com.google.gwt.user.client.Random; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.HTML; |
import com.google.gwt.user.client.ui.Widget; |
|
public class FormStructureVue extends LayoutContainer implements Rafraichissable { |
|
103,7 → 92,6 |
|
private String mode = "AJOUT"; |
private FormPanel structureFormPanneau = null; |
private int tabIndex = 100; |
private TabPanel onglets = null; |
|
private TabItem identificationOnglet = null; |
215,6 → 203,8 |
private RadioGroup avecMotifAccesMarkRGrpChp; |
private TextField<String> publicationChp; |
private ContentPanel materielConservationCp; |
private ListStore<Personne> personneExistanteMagazin; |
private ComboBox<Personne> personneExistanteCombo; |
|
|
public FormStructureVue() { |
293,32 → 283,70 |
} |
|
private void soumettreFormulaire() { |
GWT.log("Soumission du formulaire", null); |
Structure structure = collecterStructureIdentification(); |
StructureConservation conservation = collecterStructureConservation(); |
StructureValorisation valorisation = collecterStructureValorisation(); |
collecterStructurePersonnel(); |
// Vérification de la validité des champs du formulaire |
if (verifierFormulaire()) { |
GWT.log("Soumission du formulaire", null); |
// Collecte des données du formulaire |
Structure structure = collecterStructureIdentification(); |
StructureConservation conservation = collecterStructureConservation(); |
StructureValorisation valorisation = collecterStructureValorisation(); |
collecterStructurePersonnel(); |
|
if (mode.equals("AJOUT")) { |
// Ajout des informations sur la Structure |
//mediateur.ajouterStructure(this, structure); |
// L'ajout des relations StructureAPersonne se fait quand la structure a été ajoutée |
// Voir la méthode rafraichir(). |
} else if (mode.equals("MODIF")) { |
// Modification des informations sur la Structure |
mediateur.modifierStructure(this, structure, conservation, valorisation); |
// Modification des relations StructureAPersonne |
GWT.log("Personnel modifié :"+personnelModifie.size(), null); |
mediateur.modifierStructureAPersonne(this, personnelModifie); |
// Ajout des relations StructureAPersonne |
GWT.log("Personnel ajouté :"+personnelAjoute.size(), null); |
mediateur.ajouterStructureAPersonne(this, identification.getId(), personnelAjoute); |
// Suppression des relations StructureAPersonne |
GWT.log("Personnel supprimé :"+personnelSupprime.size(), null); |
mediateur.supprimerStructureAPersonne(this, personnelSupprime); |
// Nous rechargeons la liste du Personnel |
rafraichirPersonnel(); |
} |
} |
} |
|
private Boolean verifierFormulaire() { |
ArrayList<String> messages = new ArrayList<String>(); |
|
if (mode.equals("AJOUT")) { |
// Ajout des informations sur la Structure |
//mediateur.ajouterStructure(this, structure); |
// L'ajout des relations StructureAPersonne se fait quand la structure a été ajoutée |
// Voir la méthode rafraichir(). |
} else if (mode.equals("MODIF")) { |
// Modification des informations sur la Structure |
mediateur.modifierStructure(this, structure, conservation, valorisation); |
// Modification des relations StructureAPersonne |
GWT.log("Personnel modifié :"+personnelModifie.size(), null); |
mediateur.modifierStructureAPersonne(this, personnelModifie); |
// Ajout des relations StructureAPersonne |
GWT.log("Personnel ajouté :"+personnelAjoute.size(), null); |
mediateur.ajouterStructureAPersonne(this, identification.getId(), personnelAjoute); |
// Suppression des relations StructureAPersonne |
GWT.log("Personnel supprimé :"+personnelSupprime.size(), null); |
mediateur.supprimerStructureAPersonne(this, personnelSupprime); |
// Nous rechargeons la liste |
mediateur.selectionnerStructureAPersonne(this, identification.getId(), StructureAPersonne.ROLE_EQUIPE); |
// Vérification des infos sur la structure |
if ( (identificationOnglet.getData("acces").equals(true) && (nomStructureChp.getValue() == null || nomStructureChp.getValue().equals(""))) || |
(identificationOnglet.getData("acces").equals(false) && identification.getNom().equals(""))) { |
messages.add("Veuillez indiquez un nom à l'institution."); |
} |
|
// Vérification du Personnel |
if (personnelOnglet.getData("acces").equals(true)) { |
String personnelNumero = ""; |
int nbrePersonne = personnelGrilleMagazin.getCount(); |
for (int i = 0; i < nbrePersonne; i++) { |
StructureAPersonne personne = personnelGrilleMagazin.getAt(i); |
if (personne.getNom().equals("") || personne.getPrenom().equals("")) { |
personnelNumero += (i != 0 ? ", " : "")+(i+1); |
} |
} |
if (!personnelNumero.equals("")) { |
messages.add("Veuillez indiquez un prénom et un nom au personnel numéro : "+personnelNumero); |
} |
} |
|
// Affichage des messages d'alerte |
if (messages.size() != 0) { |
String[] a = {}; |
a = messages.toArray(a); |
Window.alert(UtilArray.implode(a, "\n\n")); |
return false; |
} |
return true; |
} |
|
private StructureValorisation collecterStructureValorisation() { |
383,7 → 411,7 |
} |
|
private void peuplerStructureValorisation() { |
if (valorisation != null) { |
if (valorisation != null && valorisationOnglet.getData("acces").equals(false)) { |
// ACTION |
actionMarkRGrpChp.get((valorisation.getAction().equals("1") ? 0 : 1)).setValue(true); |
|
420,6 → 448,9 |
avecMotifAccesChp.setValue(valorisation.getVisiteAvecMotifInfo()); |
|
valorisationOnglet.layout(); |
|
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
valorisationOnglet.setData("acces", true); |
} |
} |
|
519,7 → 550,7 |
} |
|
private void peuplerStructureConservation() { |
if (conservation != null) { |
if (conservation != null && conservationOnglet.getData("acces").equals(false)) { |
// FORMATION |
// Bouton oui, à toujours l'index 0 donc on teste en fonction... |
formationMarkRGrpChp.get((conservation.getFormation().equals("1") ? 0 : 1)).setValue(true); |
576,6 → 607,9 |
peuplerCasesACocher(conservation.getAcquisitionTraitementInsecte(), insecteTraitementTrukCacGrpChp, insecteTraitementAutreChp); |
|
conservationOnglet.layout(); |
|
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
conservationOnglet.setData("acces", true); |
} |
} |
|
632,7 → 666,7 |
} |
|
private void peuplerStructureIdentification() { |
if (identification != null) { |
if (identification != null && identificationOnglet.getData("acces").equals(false)) { |
idStructureChp.setValue(identification.getId()); |
nomStructureChp.setValue(identification.getNom()); |
if (!identification.getIdAlternatif().isEmpty()) { |
676,6 → 710,9 |
nbreTotalPersonneStructureChp.setValue(identification.getNbrePersonne()); |
|
identificationOnglet.layout(); |
|
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
identificationOnglet.setData("acces", true); |
} |
} |
|
687,8 → 724,6 |
valorisationOnglet.setData("acces", false); // Permet de savoir si l'onblet a été accédé par l'utilisateur |
valorisationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() { |
public void handleEvent(ComponentEvent be) { |
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
valorisationOnglet.setData("acces", true); |
peuplerStructureValorisation(); |
} |
}); |
764,9 → 799,7 |
conservationOnglet.setLayout(creerFormLayout(650, LabelAlign.TOP, null)); |
conservationOnglet.setData("acces", false); |
conservationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() { |
public void handleEvent(ComponentEvent be) { |
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
conservationOnglet.setData("acces", true); |
public void handleEvent(ComponentEvent be) { |
peuplerStructureConservation(); |
} |
}); |
967,9 → 1000,11 |
String index = it.next(); |
|
// Gestion de la fonction |
if (magazinLiFonction != null && ((String) personnel.get(index).getFonction()).matches("^[0-9]+$")) { |
if (magazinLiFonction != null && !((String) personnel.get(index).getFonction()).startsWith("AUTRE##")) { |
GWT.log(personnel.get(index).getFonction(), null); |
personnel.get(index).set("fonction", magazinLiFonction.findModel("id_valeur", personnel.get(index).getFonction()).getNom()); |
if (magazinLiFonction.findModel("id_valeur", personnel.get(index).getFonction()) != null) { |
personnel.get(index).set("fonction", magazinLiFonction.findModel("id_valeur", personnel.get(index).getFonction()).getNom()); |
} |
} else { |
personnel.get(index).set("fonction", personnel.get(index).getFonction().replaceFirst("AUTRE##", "")); |
} |
979,7 → 1014,6 |
|
// Gestion du statut |
if (magazinLiStatut != null && ((String) personnel.get(index).getStatut()).matches("^[0-9]+$")) { |
GWT.log(personnel.get(index).getStatut(), null); |
personnel.get(index).set("statut", magazinLiStatut.findModel("id_valeur", personnel.get(index).getStatut()).getNom()); |
} else { |
personnel.get(index).set("statut", personnel.get(index).getStatut().replaceFirst("AUTRE##", "")); |
1011,11 → 1045,6 |
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
personnelOnglet.setData("acces", true); |
|
// Création des objets de la grille |
personnelModifie = new StructureAPersonneListe(); |
personnelAjoute = new StructureAPersonneListe(); |
personnelSupprime = new StructureAPersonneListe(); |
|
// Peuplement du formulaire |
peuplerStructurePersonnel(); |
} |
1060,16 → 1089,16 |
@Override |
public Object preProcessValue(Object valeur) { |
if (valeur == null) { |
GWT.log("pre null :"+this.getValue()+"-"+this.row, null); |
//GWT.log("pre null :"+this.getValue()+"-"+this.row, null); |
return null; |
} |
GWT.log("pre : "+valeur.toString(), null); |
//GWT.log("pre : "+valeur.toString(), null); |
Object retour = null; |
if (((String) valeur).matches("^[0-9]+$")) { |
Valeur valeurRecherche = comboLiFonction.getStore().findModel("id_valeur", (String) valeur); |
if (valeurRecherche != null) { |
retour = valeurRecherche; |
GWT.log("pre - retour valeur par chiffre : \n"+retour.toString(), null); |
//GWT.log("pre - retour valeur par chiffre : \n"+retour.toString(), null); |
} else { |
this.getField().setRawValue((String) valeur); |
retour = null; |
1079,7 → 1108,7 |
retour = new Valeur("", (String) valeur, "", ""); |
} else { |
retour = comboLiFonction.getStore().findModel("nom", (String) valeur); |
GWT.log("pre - retour valeur par chaine : \n"+retour.toString(), null); |
//GWT.log("pre - retour valeur par chaine : \n"+retour.toString(), null); |
} |
|
return retour; |
1089,10 → 1118,10 |
public Object postProcessValue(Object valeur) { |
if (valeur == null) { |
// Si la combobox n'a pas été utilisé, nous renvoyons la valeur brute saisie par l'utilisateur |
GWT.log("post raw : \n"+this.getField().getRawValue(), null); |
//GWT.log("post raw : \n"+this.getField().getRawValue(), null); |
String retour = this.getField().getRawValue(); |
if (retour.matches("^[0-9]+$")) { |
GWT.log("ici", null); |
//GWT.log("ici", null); |
Valeur valeurRecherche = comboLiFonction.getStore().findModel("id_valeur", (String) retour); |
if (valeurRecherche != null) { |
retour = valeurRecherche.getNom(); |
1100,11 → 1129,11 |
} |
return retour; |
} else { |
GWT.log("post : \n"+valeur.toString(), null); |
//GWT.log("post : \n"+valeur.toString(), null); |
String nom = ""; |
if (valeur instanceof Valeur) { |
nom = (((Valeur) valeur).getNom()); |
GWT.log("la "+nom, null); |
//GWT.log("la "+nom, null); |
} |
|
return nom; |
1114,10 → 1143,7 |
column.setEditor(fonctionEditor); |
configs.add(column); |
|
column = new ColumnConfig(); |
column.setId("prenom"); |
column.setHeader("Prénom"); |
column.setWidth(100); |
column = new ColumnConfig("prenom", "Prénom", 100); |
TextField<String> prenomChp = new TextField<String>(); |
prenomChp.setAllowBlank(false); |
prenomChp.getMessages().setBlankText("Ce champ est obligatoire."); |
1125,10 → 1151,7 |
column.setEditor(new CellEditor(prenomChp)); |
configs.add(column); |
|
column = new ColumnConfig(); |
column.setId("nom"); |
column.setHeader("Nom"); |
column.setWidth(100); |
column = new ColumnConfig("nom", "Nom", 100); |
TextField<String> nomChp = new TextField<String>(); |
nomChp.setAllowBlank(false); |
nomChp.getMessages().setBlankText("Ce champ est obligatoire."); |
1221,7 → 1244,9 |
} |
}); |
toolBar.add(ajouterPersonnelBtn); |
|
toolBar.add(new SeparatorToolItem()); |
|
TextToolItem supprimerPersonnelBtn = new TextToolItem("Supprimer", "icone-vcard-supprimer"); |
supprimerPersonnelBtn.addSelectionListener(new SelectionListener<ToolBarEvent>() { |
@Override |
1229,7 → 1254,7 |
StructureAPersonne personne = grillePersonnel.getSelectionModel().getSelectedItem(); |
if (personne != null) { |
// Ajout de la personne supprimée à la liste |
if (personne.getIdPersonne() != null) { |
if (personne.getIdPersonne() != null && !personne.getIdPersonne().equals("")) { |
personnelSupprime.put(personne.getId(), personne); |
} |
|
1243,7 → 1268,69 |
} |
} |
}); |
toolBar.add(supprimerPersonnelBtn); |
toolBar.add(supprimerPersonnelBtn); |
|
toolBar.add(new SeparatorToolItem()); |
|
TextToolItem rafraichirPersonnelBtn = new TextToolItem("Rafraichir", "icone-rafraichir"); |
rafraichirPersonnelBtn.addSelectionListener(new SelectionListener<ToolBarEvent>() { |
@Override |
public void componentSelected(ToolBarEvent ce) { |
rafraichirPersonnel(); |
} |
}); |
toolBar.add(rafraichirPersonnelBtn); |
|
toolBar.add(new SeparatorToolItem()); |
|
personneExistanteMagazin = new ListStore<Personne>(); |
personneExistanteMagazin.add(new ArrayList<Personne>()); |
|
personneExistanteCombo = new ComboBox<Personne>(); |
personneExistanteCombo.setWidth(200); |
personneExistanteCombo.setEmptyText("Chercher une personne existante..."); |
personneExistanteCombo.setTriggerAction(TriggerAction.ALL); |
personneExistanteCombo.setEditable(true); |
personneExistanteCombo.setDisplayField("fmt_nom_complet"); |
personneExistanteCombo.setStore(personneExistanteMagazin); |
personneExistanteCombo.addKeyListener(new KeyListener() { |
|
public void componentKeyUp(ComponentEvent ce) { |
if (!ce.isNavKeyPress() && personneExistanteCombo.getRawValue() != null && personneExistanteCombo.getRawValue().length() > 0) { |
rafraichirPersonneExistante(personneExistanteCombo.getRawValue()); |
} |
} |
|
}); |
|
// TODO : dans GXT 2.0 plus besoin de l'adaptateur, on peut ajouter la combobox directement sur la toolbar |
toolBar.add(new AdapterToolItem(personneExistanteCombo)); |
|
TextToolItem ajouterPersonneExistanteBtn = new TextToolItem("Ajouter"); |
ajouterPersonneExistanteBtn.addSelectionListener(new SelectionListener<ToolBarEvent>() { |
@Override |
public void componentSelected(ToolBarEvent ce) { |
Personne personneExistante = personneExistanteCombo.getValue(); |
|
StructureAPersonne personne = new StructureAPersonne("", StructureAPersonne.ROLE_EQUIPE); |
personne.setIdPersonne(personneExistante.getId()); |
personne.setPrenom(personneExistante.getPrenom()); |
personne.setNom(personneExistante.getNom()); |
|
grillePersonnel.stopEditing(); |
int numNouveau = grillePersonnel.getData("nouveau"); |
grillePersonnel.setData("nouveau", ++numNouveau); |
personnelGrilleMagazin.insert(personne, 0); |
grillePersonnel.startEditing(0, 0); |
|
// Activation du bouton supprimer si la grille contient un élément |
if (grillePersonnel.getStore().getCount() > 0) { |
ce.component.enable(); |
} |
} |
}); |
toolBar.add(ajouterPersonneExistanteBtn); |
|
cp.setTopComponent(toolBar); |
|
ColumnModel cm = new ColumnModel(configs); |
1284,8 → 1371,6 |
identificationOnglet.setData("acces", false); |
identificationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() { |
public void handleEvent(ComponentEvent be) { |
// Indique que l'onglet a été rempli et a pu être modifié pour la méthode collecter... |
identificationOnglet.setData("acces", true); |
peuplerStructureIdentification(); |
} |
}); |
1849,16 → 1934,36 |
} else if (info.getType().equals("liste_structure_a_personne")) { |
if (info.getDonnee(0) != null) { |
personnel = (StructureAPersonneListe) info.getDonnee(0); |
|
|
// Création des objets contenant les manipulations de la grille |
personnelModifie = new StructureAPersonneListe(); |
personnelAjoute = new StructureAPersonneListe(); |
personnelSupprime = new StructureAPersonneListe(); |
|
//GWT.log(personnel.toString(), null); |
if (onglets.getSelectedItem().equals(personnelOnglet)) { |
peuplerStructurePersonnel(); |
Info.display("Peuplement", "ok"); |
Info.display("Chargement du Personnel", "ok"); |
} |
} |
if (info.getDonnee(1) != null) { |
Info.display("Debug", info.getDonnee(1).toString()); |
} |
} else if (info.getType().equals("liste_personne")) { |
if (info.getDonnee(0) != null) { |
PersonneListe personnes = (PersonneListe) info.getDonnee(0); |
|
List<Personne> liste = new ArrayList<Personne>(); |
for (Iterator<String> it = personnes.keySet().iterator(); it.hasNext();) { |
liste.add(personnes.get(it.next())); |
} |
|
GWT.log("Nbre de personnes trouvées :"+personnes.size(), null); |
personneExistanteMagazin.removeAll(); |
personneExistanteMagazin.add(liste); |
personneExistanteCombo.setStore(personneExistanteMagazin); |
personneExistanteCombo.expand(); |
} |
} |
} else if (nouvelleDonnees instanceof ValeurListe) { |
ValeurListe listeValeurs = (ValeurListe) nouvelleDonnees; |
1969,5 → 2074,12 |
GWT.log("rafraichir()", e); |
} |
} |
|
|
private void rafraichirPersonnel() { |
mediateur.selectionnerStructureAPersonne(this, identification.getId(), StructureAPersonne.ROLE_EQUIPE); |
} |
|
private void rafraichirPersonneExistante(String nom) { |
mediateur.selectionnerPersonneParNomComplet(this, null, nom); |
} |
} |