Rev 862 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.images.Images;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Collection;import org.tela_botanica.client.modeles.CollectionAPersonne;import org.tela_botanica.client.modeles.CollectionAPersonneListe;import org.tela_botanica.client.modeles.Information;import org.tela_botanica.client.modeles.InterneValeur;import org.tela_botanica.client.modeles.Personne;import org.tela_botanica.client.modeles.PersonneListe;import org.tela_botanica.client.modeles.Publication;import org.tela_botanica.client.modeles.StructureAPersonne;import org.tela_botanica.client.modeles.UniteBase;import org.tela_botanica.client.modeles.UniteRangement;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import org.tela_botanica.client.modeles.aDonnee;import com.extjs.gxt.ui.client.event.BaseEvent;import com.extjs.gxt.ui.client.event.ButtonEvent;import com.extjs.gxt.ui.client.event.ComponentEvent;import com.extjs.gxt.ui.client.event.EventType;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.event.KeyListener;import com.extjs.gxt.ui.client.event.Listener;import com.extjs.gxt.ui.client.event.SelectionListener;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.store.StoreEvent;import com.extjs.gxt.ui.client.widget.ContentPanel;import com.extjs.gxt.ui.client.widget.Info;import com.extjs.gxt.ui.client.widget.Text;import com.extjs.gxt.ui.client.widget.button.Button;import com.extjs.gxt.ui.client.widget.button.ButtonBar;import com.extjs.gxt.ui.client.widget.form.ComboBox;import com.extjs.gxt.ui.client.widget.form.FormPanel;import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;import com.extjs.gxt.ui.client.widget.grid.CellEditor;import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;import com.extjs.gxt.ui.client.widget.grid.ColumnData;import com.extjs.gxt.ui.client.widget.grid.ColumnModel;import com.extjs.gxt.ui.client.widget.grid.EditorGrid;import com.extjs.gxt.ui.client.widget.grid.Grid;import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;import com.extjs.gxt.ui.client.widget.grid.HeaderGroupConfig;import com.extjs.gxt.ui.client.widget.grid.RowNumberer;import com.extjs.gxt.ui.client.widget.layout.FitLayout;import com.extjs.gxt.ui.client.widget.toolbar.SeparatorToolItem;import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.KeyCodes;public class CollectionFormPersonne extends FormulaireOnglet implements Rafraichissable {private Collection collection = null;private Collection collectionCollectee = null;private ContentPanel panneauPrincipal = null;private ToolBar barreOutils = null;private Grid<CollectionAPersonne> grille;private ComboBox<Valeur> typeRelationCombo = null;private CollectionAPersonneListe personnes = null;private CollectionAPersonneListe personnesAjoutees = null;private CollectionAPersonneListe personnesModifiees = null;private CollectionAPersonneListe personnesSupprimees = null;private ComboBox<Personne> personnesSaisisComboBox = null;private Button personnesBoutonSupprimer = null;private Button personnesBoutonModifier = null;private ValeurListe listeIon = null;private FenetreForm fenetreFormulaire = null;private static final String ETAT_AJOUTE = "A";private static final String ETAT_SUPPRIME = "S";public CollectionFormPersonne(Formulaire formulaireCourrant) {initialiserOnglet(formulaireCourrant);setId("personne");setText(Mediateur.i18nC.collectionPersonne());setStyleAttribute("padding", "0");panneauPrincipal = creerPanneauContenantGrille();barreOutils = creerBarreOutilsGrille();panneauPrincipal.setTopComponent(barreOutils);grille = creerGrille();panneauPrincipal.add(grille);mediateur.obtenirListeValeurEtRafraichir(this, "ion");mediateur.obtenirListeValeurEtRafraichir(this, "relationPersonneCollection");add(panneauPrincipal);initialiser();}private void initialiser() {// Remise à zéro des modification dans la liste des auteurspersonnesAjoutees = new CollectionAPersonneListe();personnesModifiees = new CollectionAPersonneListe();personnesSupprimees = new CollectionAPersonneListe();// Actualisation de l'état des boutons de la barre d'outilsactualiserEtatBoutonsBarreOutils();}private void initialiserCollection() {collection = ((CollectionForm) formulaire).collection;collectionCollectee = ((CollectionForm) formulaire).collectionCollectee;}private ContentPanel creerPanneauContenantGrille() {ContentPanel panneau = new ContentPanel();panneau.setHeading(i18nC.collectionPersonneTitre());panneau.setIcon(Images.ICONES.table());panneau.setLayout(new FitLayout());panneau.setFrame(true);return panneau;}private ToolBar creerBarreOutilsGrille() {ToolBar barreOutils = new ToolBar();Button ajouterPersonneBouton = creerBoutonAjouter();barreOutils.add(ajouterPersonneBouton);barreOutils.add(new Text(" ou "));personnesSaisisComboBox = creerComboBoxPersonnesSaisies();barreOutils.add(personnesSaisisComboBox);barreOutils.add(new SeparatorToolItem());personnesBoutonModifier = creerBoutonModifier();barreOutils.add(personnesBoutonModifier);barreOutils.add(new SeparatorToolItem());personnesBoutonSupprimer = creerBoutonSupprimer();barreOutils.add(personnesBoutonSupprimer);barreOutils.add(new SeparatorToolItem());Button rafraichirPersonneBouton = creerBoutonRafraichir();barreOutils.add(rafraichirPersonneBouton);return barreOutils;}private Button creerBoutonAjouter() {Button bouton = new Button(i18nC.ajouter());bouton.setIcon(Images.ICONES.vcardAjouter());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_AJOUTER);fenetreFormulaire.show();}});return bouton;}private Button creerBoutonModifier() {Button bouton = new Button(i18nC.modifier());bouton.setIcon(Images.ICONES.vcardModifier());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {CollectionAPersonne personneSaisiSelectionne = grille.getSelectionModel().getSelectedItem();if (personneSaisiSelectionne == null) {Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPersonne());} else {fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(Formulaire.MODE_MODIFIER);fenetreFormulaire.show();}}});return bouton;}private FenetreForm creerFenetreModaleAvecFormulairePersonne(String mode) {String personneId = null;if (mode.equals(Formulaire.MODE_MODIFIER)) {CollectionAPersonne personneSaisieSelectionnee = grille.getSelectionModel().getSelectedItem();personneId = personneSaisieSelectionnee.getId();}final FenetreForm fenetre = new FenetreForm("");final PersonneForm formulaire = creerFormulairePersonne(fenetre, personneId);fenetre.add(formulaire);return fenetre;}private PersonneForm creerFormulairePersonne(final FenetreForm fenetre, String personneId) {PersonneForm formulaire = new PersonneForm(mediateur, personneId, this);FormPanel panneauFormulaire = formulaire.getFormulaire();fenetre.setHeading(panneauFormulaire.getHeading());panneauFormulaire.setHeaderVisible(false);panneauFormulaire.setTopComponent(null);// TODO : gérer la barre d'outil avec des évènements spécifique au contexte de fenêtre modaleSelectionListener<ButtonEvent> ecouteur = creerEcouteurValidationFormulairePersonne(fenetre, formulaire);final ButtonBar barreValidation = new FormulaireBarreValidation(ecouteur);panneauFormulaire.setBottomComponent(barreValidation);return formulaire;}private SelectionListener<ButtonEvent> creerEcouteurValidationFormulairePersonne(final FenetreForm fenetre, final PersonneForm formulaire) {SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {String code = ((Button) ce.getComponent()).getData("code");if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {if (formulaire.soumettreFormulaire()) {fenetre.hide();}} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {formulaire.soumettreFormulaire();} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {fenetre.hide();} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {fenetreFormulaire.hide();fenetreFormulaire = creerFenetreModaleAvecFormulairePersonne(formulaire.mode);fenetreFormulaire.show();}}};return ecouteur;}private Button creerBoutonSupprimer() {Button bouton = new Button(i18nC.supprimer());bouton.setIcon(Images.ICONES.vcardSupprimer());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {CollectionAPersonne personneSaisiSelectionnee = grille.getSelectionModel().getSelectedItem();if (personneSaisiSelectionnee == null) {Info.display(i18nC.informationTitreGenerique(), i18nC.selectionnerPersonne());} else {supprimerDansGrille(personneSaisiSelectionnee);}}});return bouton;}private Button creerBoutonRafraichir() {Button bouton = new Button(i18nC.rafraichir());bouton.setIcon(Images.ICONES.rafraichir());bouton.addSelectionListener(new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {// TODO : mettre en place le rafraichissement de la liste}});return bouton;}private ComboBox<Personne> creerComboBoxPersonnesSaisies() {ListStore<Personne> personnesSaisiesStore = new ListStore<Personne>();personnesSaisiesStore.add(new ArrayList<Personne>());ComboBox<Personne> comboBox = new ComboBox<Personne>();comboBox.setWidth(200);comboBox.setEmptyText(i18nC.chercherPersonneSaisi());comboBox.setTriggerAction(TriggerAction.ALL);comboBox.setEditable(true);comboBox.setDisplayField("fmt_nom_complet");comboBox.setStore(personnesSaisiesStore);comboBox.addKeyListener(new KeyListener() {public void componentKeyUp(ComponentEvent ce) {if (personnesSaisisComboBox.getRawValue() != null && personnesSaisisComboBox.getRawValue().length() > 0) {if (!ce.isNavKeyPress()) {obtenirPersonnesSaisis(personnesSaisisComboBox.getRawValue());}}}});comboBox.addListener(Events.Select, new Listener<BaseEvent>() {@Overridepublic void handleEvent(BaseEvent be) {if (personnesSaisisComboBox.getValue() instanceof Personne) {Personne personneSaisiSelectionnee = personnesSaisisComboBox.getValue();ajouterDansGrille(personneSaisiSelectionnee);personnesSaisisComboBox.setValue(null);}}});return comboBox;}private void ajouterDansGrille(Personne personne) {if (personne != null) {CollectionAPersonne relationCollectionPersonne = new CollectionAPersonne();relationCollectionPersonne.setPersonne(personne);// Ajout de la personne ajoutée à la listeif (relationCollectionPersonne.getId() != null && !relationCollectionPersonne.getId().equals("")) {personnesAjoutees.put(relationCollectionPersonne.getId(), relationCollectionPersonne);}// Définition de l'étatrelationCollectionPersonne.set("etat", ETAT_AJOUTE);// Ajout à la grillegrille.getStore().insert(relationCollectionPersonne, 0);grille.getSelectionModel().select(0, false);}}private void supprimerDansGrille(CollectionAPersonne relationCollectionPersonne) {if (relationCollectionPersonne != null) {// Ajout de la personne supprimée à la listeif ((relationCollectionPersonne.get("etat") == null || !relationCollectionPersonne.get("etat").equals(ETAT_AJOUTE))&& relationCollectionPersonne.getId() != null&& !relationCollectionPersonne.getId().equals("")) {personnesSupprimees.put(relationCollectionPersonne.getId(), relationCollectionPersonne);}// Suppression de l'enregistrement de la grillegrille.getStore().remove(relationCollectionPersonne);}}private Grid<CollectionAPersonne> creerGrille() {ListStore<Personne> storeGrille = new ListStore<Personne>();storeGrille.addListener(Store.Add, new Listener<StoreEvent<Personne>>() {public void handleEvent(StoreEvent<Personne> ce) {actualiserEtatBoutonsBarreOutils();}});storeGrille.addListener(Store.Remove, new Listener<StoreEvent<Personne>>() {public void handleEvent(StoreEvent<Personne> ce) {actualiserEtatBoutonsBarreOutils();}});RowNumberer pluginLigneNumero = new RowNumberer();List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();colonnes.add(pluginLigneNumero);typeRelationCombo = new ComboBox<Valeur>();typeRelationCombo.setForceSelection(true);typeRelationCombo.setTriggerAction(TriggerAction.ALL);typeRelationCombo.setDisplayField("nom");typeRelationCombo.setStore(new ListStore<Valeur>());typeRelationCombo.setEditable(false);CellEditor editeurRelation = new CellEditor(typeRelationCombo) {@Overridepublic Object preProcessValue(Object valeur) {Valeur retour = null;if (valeur != null ) {if (typeRelationCombo.getStore().findModel("nom", valeur.toString()) != null) {retour = typeRelationCombo.getStore().findModel("nom", valeur.toString());} else if (typeRelationCombo.getStore().findModel("abr", valeur.toString()) != null) {retour = typeRelationCombo.getStore().findModel("abr", valeur.toString());}}return retour;}@Overridepublic Object postProcessValue(Object valeur) {String retour = null;if (valeur != null ) {if (valeur instanceof Valeur) {Valeur valeurOntologie = (Valeur) valeur;retour = valeurOntologie.getNom();}}return retour;}};ColumnConfig typeRelationColonne = new ColumnConfig("id_role", i18nC.typeRelationPersonneCollection(), 75);typeRelationColonne.setEditor(editeurRelation);colonnes.add(typeRelationColonne);colonnes.add(new ColumnConfig("fmt_nom_complet", i18nC.personneNomComplet(), 150));colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 75));colonnes.add(new ColumnConfig("prenom", i18nC.personnePrenom(), 75));colonnes.add(new ColumnConfig("naissance_date", i18nC.date(), 75));colonnes.add(new ColumnConfig("naissance_lieu", i18nC.lieu(), 100));colonnes.add(creerColonneDeces());colonnes.add(new ColumnConfig("deces_date", i18nC.date(), 75));colonnes.add(new ColumnConfig("deces_lieu", i18nC.lieu(), 100));GridSelectionModel<CollectionAPersonne> modeleDeSelection = new GridSelectionModel<CollectionAPersonne>();ColumnModel modeleDeColonnes = new ColumnModel(colonnes);modeleDeColonnes.addHeaderGroup(0, 1, new HeaderGroupConfig(i18nC.personneIdentite(), 1, 4));modeleDeColonnes.addHeaderGroup(0, 5, new HeaderGroupConfig(i18nC.personneNaissance(), 1, 2));modeleDeColonnes.addHeaderGroup(0, 7, new HeaderGroupConfig(i18nC.personneDeces(), 1, 3));EditorGrid<CollectionAPersonne> grillePersonne = new EditorGrid<CollectionAPersonne>(storeGrille, modeleDeColonnes);grillePersonne.setHeight("100%");grillePersonne.setBorders(true);grillePersonne.setSelectionModel(modeleDeSelection);grillePersonne.addPlugin(pluginLigneNumero);grillePersonne.getView().setForceFit(true);grillePersonne.setAutoExpandColumn("fmt_nom_complet");grillePersonne.setStripeRows(true);grillePersonne.setTrackMouseOver(true);return grillePersonne;}public ColumnConfig creerColonneDeces() {GridCellRenderer<CollectionAPersonne> decesRendu = new GridCellRenderer<CollectionAPersonne>() {@Overridepublic String render(CollectionAPersonne modele, String property, ColumnData config, int rowIndex, int colIndex, ListStore<CollectionAPersonne> store, Grid<CollectionAPersonne> grid) {String deces = modele.getPersonne().getDeces();if (listeIon != null && modele.getPersonne().getDeces().matches("[0-9]+")) {deces = listeIon.get(modele.getPersonne().getDeces()).getNom();}modele.set("_deces_", deces);return deces;}};ColumnConfig decesColonne = new ColumnConfig("_deces_", Mediateur.i18nC.personneDecedeeInterogation(), 50);decesColonne.setRenderer(decesRendu);return decesColonne;}public void actualiserEtatBoutonsBarreOutils() {// Activation des boutons si la grille contient un élémentif (grille.getStore().getCount() > 0) {personnesBoutonSupprimer.enable();personnesBoutonModifier.enable();}// Désactivation des boutons si la grille ne contient plus d'élémentif (grille.getStore().getCount() == 0) {personnesBoutonSupprimer.disable();personnesBoutonModifier.disable();}}public void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof ValeurListe) {ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;rafraichirValeurListe(listeValeurs);} else if (nouvellesDonnees instanceof Information) {Information info = (Information) nouvellesDonnees;rafraichirInformation(info);} else {GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);}}private void rafraichirValeurListe(ValeurListe listeValeurs) {if (listeValeurs.getId().equals(config.getListeId("ion"))) {listeIon = listeValeurs;} else if (listeValeurs.getId().equals(config.getListeId("relationPersonneCollection"))) {Formulaire.rafraichirComboBox(listeValeurs, typeRelationCombo);} else {GWT.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!", null);}}public void rafraichirInformation(Information info) {if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);}String type = info.getType();if (type.equals("liste_personne")) {if (info.getDonnee(0) != null) {PersonneListe personnes = (PersonneListe) info.getDonnee(0);List<Personne> liste = personnes.toList();personnesSaisisComboBox.getStore().removeAll();personnesSaisisComboBox.getStore().add(liste);personnesSaisisComboBox.expand();}} else if (type.equals("liste_collection_a_personne")) {if (info.getDonnee(0) != null) {initialiser();// TODO : passer à la méthode peupler un objet CollectionAPersonneListe et modifier le type de auteurs//auteurs = (CollectionAPersonneListe) info.getDonnee(0);peupler();}} else if (info.getType().equals("ajout_collection")) {if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {String collectionId = (String) info.getDonnee(0);// Suite à la récupération de l'id de la collection nouvellement ajoutée nous ajoutons les personnes liées// En mode AJOUT, il ne peut que y avoir des personnes liées ajoutéesmediateur.ajouterCollectionAPersonne(this, collectionId, personnesAjoutees);} else {Info.display("Ajout d'une Institution", info.toString());}} else if (info.getType().equals("modif_collection_a_personne")) {Info.display("Modification des personnes liées à la collection", info.toString());} else if (info.getType().equals("suppression_collection_a_personne")) {Info.display("Suppression des personnes liées à la collection", info.toString());} else if (info.getType().equals("ajout_collection_a_personne")) {Info.display("Ajout des personnes liées à la collection", info.toString());}}public void peupler() {initialiserCollection();layout();Info.display(i18nC.chargementPersonne(), i18nC.ok());}public ArrayList<String> verifier() {ArrayList<String> messages = new ArrayList<String>();String personneNumero = "";int nbrePersonne = grille.getStore().getCount();if (nbrePersonne > 0) {for (int i = 0; i < nbrePersonne; i++) {CollectionAPersonne personne = grille.getStore().getAt(i);if (personne.getIdRole().equals("")) {personneNumero += (i != 0 ? ", " : "")+(i+1);}}if (!personneNumero.equals("")) {messages.add("Veuillez indiquez le type de relation existant entre la collection et les personnes numéros : "+personneNumero);}}return messages;}public void collecter() {initialiserCollection();if (etreAccede()) {int nbrePersonne = grille.getStore().getCount();for (int i = 0; i < nbrePersonne; i++) {CollectionAPersonne personne = grille.getStore().getAt(i);// Seules les lignes ajoutées ou modifiées sont prises en compte.Record enregistrement = grille.getStore().getRecord(personne);if (grille.getStore().getModifiedRecords().contains(enregistrement) == true|| (personne.get("etat") != null && personne.get("etat").equals(aDonnee.ETAT_AJOUTE) )) {// Gestion de l'id de la structureif (mode.equals(Formulaire.MODE_MODIFIER)) {personne.setIdCollection(collection.getId());}// Ajout de la personne dans la liste correspondant à son état (ajouté ou modifié)if (personne.get("etat") != null && personne.get("etat").equals(aDonnee.ETAT_AJOUTE)) {// Une personne ajoutéepersonnesAjoutees.put(""+i, personne);} else {// Une personne modifiéepersonnesModifiees.put(personne.getId(), personne);}} else {GWT.log("Personne non modifiées : "+personne.getPersonne().getPrenom()+" "+personne.getPersonne().getNom(), null);}}}}public void soumettre() {if (mode.equals(Formulaire.MODE_MODIFIER)) {if (personnesModifiees.size() == 0 && personnesAjoutees.size() == 0 && personnesSupprimees.size() == 0) {Info.display("Modification des personnes liées", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");} else {if (personnesModifiees.size() != 0) {mediateur.modifierCollectionAPersonne(this, personnesModifiees);}// Ajout des relations CollectionAPersonneif (personnesAjoutees.size() != 0) {mediateur.ajouterCollectionAPersonne(this, collection.getId(), personnesAjoutees);}// Suppression des relations StructureAPersonneif (personnesSupprimees.size() != 0) {mediateur.supprimerCollectionAPersonne(this, personnesSupprimees);}}}}private void obtenirPersonnesSaisis(String nom) {mediateur.selectionnerPersonneParNomComplet(this, null, nom+"%");}}