Rev 648 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.List;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.RegistreId;import org.tela_botanica.client.composants.ChampMultiValeurs;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.CollectionListe;import org.tela_botanica.client.modeles.Configuration;import org.tela_botanica.client.modeles.Information;import org.tela_botanica.client.modeles.MenuApplicationId;import org.tela_botanica.client.modeles.Projet;import org.tela_botanica.client.modeles.ProjetListe;import org.tela_botanica.client.modeles.Structure;import org.tela_botanica.client.modeles.StructureListe;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;import com.extjs.gxt.ui.client.Registry;import com.extjs.gxt.ui.client.Style.SortDir;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.Listener;import com.extjs.gxt.ui.client.event.SelectionChangedEvent;import com.extjs.gxt.ui.client.event.SelectionChangedListener;import com.extjs.gxt.ui.client.event.SelectionListener;import com.extjs.gxt.ui.client.event.WidgetListener;import com.extjs.gxt.ui.client.store.ListStore;import com.extjs.gxt.ui.client.store.Store;import com.extjs.gxt.ui.client.store.StoreEvent;import com.extjs.gxt.ui.client.store.StoreListener;import com.extjs.gxt.ui.client.widget.Component;import com.extjs.gxt.ui.client.widget.Info;import com.extjs.gxt.ui.client.widget.LayoutContainer;import com.extjs.gxt.ui.client.widget.MessageBox;import com.extjs.gxt.ui.client.widget.TabItem;import com.extjs.gxt.ui.client.widget.TabPanel;import com.extjs.gxt.ui.client.widget.Text;import com.extjs.gxt.ui.client.widget.button.Button;import com.extjs.gxt.ui.client.widget.form.ComboBox;import com.extjs.gxt.ui.client.widget.form.Field;import com.extjs.gxt.ui.client.widget.form.FieldSet;import com.extjs.gxt.ui.client.widget.form.HiddenField;import com.extjs.gxt.ui.client.widget.form.LabelField;import com.extjs.gxt.ui.client.widget.form.NumberField;import com.extjs.gxt.ui.client.widget.form.Radio;import com.extjs.gxt.ui.client.widget.form.TextArea;import com.extjs.gxt.ui.client.widget.form.TextField;import com.extjs.gxt.ui.client.widget.form.Validator;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.layout.ColumnData;import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;import com.extjs.gxt.ui.client.widget.layout.FormData;import com.extjs.gxt.ui.client.widget.layout.RowLayout;import com.google.gwt.core.client.GWT;import com.google.gwt.i18n.client.NumberFormat;import com.google.gwt.user.client.ui.Widget;public class CollectionForm extends Formulaire implements Rafraichissable {private Collection collection = null;private Collection collectionCollectee = null;private HashMap<String,FieldSet> champsFs = new HashMap<String,FieldSet>();private HashMap<String,LayoutContainer> champsLc = new HashMap<String,LayoutContainer>();private HashMap<String,HiddenField<String>> champsHfs = new HashMap<String,HiddenField<String>>();private HashMap<String,TextField<String>> champsTfs = new HashMap<String,TextField<String>>();private HashMap<String,TextArea> champsTa = new HashMap<String,TextArea>();private HashMap<String,ChampMultiValeurs> champsCmv = new HashMap<String,ChampMultiValeurs>();private HashMap<String,Text> champsT = new HashMap<String,Text>();private HashMap<String,ComboBox<Valeur>> champsCbv = new HashMap<String,ComboBox<Valeur>>();private HashMap<String,ListStore<Valeur>> champsLsv = new HashMap<String,ListStore<Valeur>>();private TabItem generalOnglet = null;private TabItem auteurOnglet = null;private TabItem publicationOnglet = null;private TabItem descriptionOnglet = null;private TabItem contenuOnglet = null;private TabItem documentOnglet = null;private TabItem inventaireOnglet = null;private ListStore<Projet> projetsStore;private ComboBox<Projet> projetsCombo;private ListStore<Structure> structuresStore;private ComboBox<Structure> structuresCombo;private ListStore<Collection> collectionsStore;private ComboBox<Collection> collectionsCombo;public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);}protected void creerOnglets() {onglets = new TabPanel();// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)onglets.setHeight("100%");// Onlget formulaire GENERALonglets.add(creerOngletGeneral());// Onlget formulaire AUTEURonglets.add(creerOngletAuteur());// Onlget formulaire PUBLICATIONonglets.add(creerOngletPublication());// Onlget formulaire DESCRIPTIONonglets.add(creerOngletDescription());// Onlget formulaire CONTENUonglets.add(creerOngletContenu());// Onlget formulaire DOCUMENTonglets.add(creerOngletDocument());// Onlget formulaire INVENTAIREonglets.add(creerOngletInventaire());// Sélection de l'onglet par défaut//onglets.setSelection(personnelOnglet);// Ajout des onglets au formulaire généralpanneauFormulaire.add(onglets);}private TabItem creerOngletGeneral() {generalOnglet = new CollectionFormGeneral(this);return generalOnglet;}private TabItem creerOngletAuteur() {auteurOnglet = creerOnglet(i18nC.collectionAuteur(), "auteur");auteurOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletAuteur();auteurOnglet.layout();}});return auteurOnglet;}private TabItem creerOngletPublication() {publicationOnglet = creerOnglet(i18nC.collectionPublication(), "publication");publicationOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletAuteur();publicationOnglet.layout();}});return publicationOnglet;}private TabItem creerOngletDescription() {descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletDescription();descriptionOnglet.layout();}});return descriptionOnglet;}private TabItem creerOngletContenu() {contenuOnglet = creerOnglet(i18nC.collectionContenu(), "contenu");contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletContenu();contenuOnglet.layout();}});return contenuOnglet;}private TabItem creerOngletDocument() {documentOnglet = creerOnglet(i18nC.collectionDocument(), "document");documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletDocument();documentOnglet.layout();}});return documentOnglet;}private TabItem creerOngletInventaire() {inventaireOnglet = creerOnglet(i18nC.collectionInventaire(), "inventaire");inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletInventaire();inventaireOnglet.layout();}});return inventaireOnglet;}public void rafraichir(Object nouvellesDonnees) {try {if (nouvellesDonnees instanceof Information) {Information info = (Information) nouvellesDonnees;rafraichirInformation(info);} else if (nouvellesDonnees instanceof ValeurListe) {ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;rafraichirValeurListe(listeValeurs);} else {GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);}} catch (Exception e) {GWT.log("rafraichir()", e);}verifierApresRafraichissement();}private void rafraichirInformation(Information info) {if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);}if (info.getType().equals("modif_structure")) {Info.display("Modification d'une collection", info.toString());} else if (info.getType().equals("selection_collection")) {Info.display("Modification d'une collection", info.toString());if (info.getDonnee(0) != null) {collection = (Collection) info.getDonnee(0);}actualiserPeuplementOnglet();actualiserTitrePanneau();}}private void rafraichirValeurListe(ValeurListe listeValeurs) {List<Valeur> liste = listeValeurs.toList();// Test pour savoir si la liste contient des élémentsif (liste.size() > 0) {String[] listesTraitables = {};Boolean implemente = false;for (int i = 0; i < listesTraitables.length; i++) {String id = listesTraitables[i];GWT.log(id, null);if (listeValeurs.getId().equals(config.getListeId(id))) {champsLsv.get(id).removeAll();champsLsv.get(id).add(liste);champsCbv.get(id).setStore(champsLsv.get(id));implemente = true;break;}}if (implemente == false) {GWT.log("Gestion de la liste "+listeValeurs.getId()+" non implémenté!", null);}}}private void actualiserPeuplementOnglet() {onglets.setSelection(onglets.getSelectedItem());}private void actualiserTitrePanneau() {String titre = i18nC.titreModifFormCollection();// Composition du titretitre += " - ID : "+collection.getId();panneauFormulaire.setHeading(titre);}@Overrideprotected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {@Overridepublic void componentSelected(ButtonEvent ce) {if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {soumettreFormulaire();clicBoutonvalidation = true;} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {soumettreFormulaire();} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {mediateur.clicMenu(menuIdCourant);} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {if (mode.equals(StructureForm.MODE_MODIFIER)) {mediateur.afficherFormCollection(collection.getId());} else {mediateur.afficherFormCollection(null);}}}};return ecouteur;}protected void soumettreFormulaire() {// Vérification de la validité des champs du formulaireif (verifierFormulaire()) {// Collecte des données du formulaireCollection collection = collecterCollection();if (mode.equals(MODE_AJOUTER)) {mediateur.ajouterCollection(this, collection);} else if (mode.equals(MODE_MODIFIER)) {if (collection == null) {Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");} else {mediateur.modifierCollection(this, collection);}}}}private Collection collecterCollection() {collectionCollectee = (Collection) collection.cloner(new Collection());collecterOngletGeneral();Collection collectionARetourner = null;if (!collectionCollectee.comparer(collection)) {collectionARetourner = collection = collectionCollectee;}return collectionARetourner;}private void collecterOngletGeneral() {if (generalOnglet.getData("acces").equals(true)) {}}private Boolean verifierFormulaire() {return true;}@Overrideprotected void afficherChampSupplementaire(Radio radioBtn) {// TODO Auto-generated method stub}}