Rev 867 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.ArrayList;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Collection;import org.tela_botanica.client.modeles.Information;import org.tela_botanica.client.modeles.MenuApplicationId;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.util.UtilArray;import com.extjs.gxt.ui.client.event.BaseEvent;import com.extjs.gxt.ui.client.event.ButtonEvent;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.event.Listener;import com.extjs.gxt.ui.client.event.SelectionListener;import com.extjs.gxt.ui.client.widget.Info;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.button.Button;import com.extjs.gxt.ui.client.widget.form.FieldSet;import com.extjs.gxt.ui.client.widget.form.TextField;import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;import com.extjs.gxt.ui.client.widget.layout.FormData;import com.google.gwt.core.client.GWT;public class CollectionForm extends Formulaire implements Rafraichissable {protected Collection collection = null;protected Collection collectionCollectee = null;private ChampComboBoxListeValeurs typesCollectionCombo = null;private TabPanel onglets = null;private CollectionFormGeneral generalOnglet = null;private CollectionFormPersonne personneOnglet = null;private CollectionFormPublication publicationOnglet = null;private CollectionFormDescription descriptionOnglet = null;private CollectionFormContenu contenuOnglet = null;private CollectionFormInventaire inventaireOnglet = null;private TextField<String> nomChp = null;public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);creerFieldsetPrincipal();}private void creerFieldsetPrincipal() {FieldSet principalFieldSet = new FieldSet();principalFieldSet.setHeading("Info");principalFieldSet.setCollapsible(true);principalFieldSet.setLayout(Formulaire.creerFormLayout(150, LabelAlign.LEFT));nomChp = new TextField<String>();nomChp.setTabIndex(tabIndex++);nomChp.setFieldLabel(i18nC.nomCollection());nomChp.setAllowBlank(false);nomChp.getMessages().setBlankText(i18nC.champObligatoire());principalFieldSet.add(nomChp, new FormData(450, 0));typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);typesCollectionCombo.peupler(Valeur.COLLECTION_NCD_HERBIER);typesCollectionCombo.addListener(Events.Select, new Listener<BaseEvent>() {@Overridepublic void handleEvent(BaseEvent be) {Valeur valeur = typesCollectionCombo.getValue();panneauFormulaire.remove(onglets);mediateur.activerChargement("");if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {onglets = creerOngletsHerbier();panneauFormulaire.add(onglets);} else {onglets = creerOngletsDefaut();panneauFormulaire.add(onglets);}mediateur.desactiverChargement();panneauFormulaire.layout();}});principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));typesCollectionCombo.fireEvent(Events.Select);panneauFormulaire.setTopComponent(principalFieldSet);}protected TabPanel creerOngletsDefaut() {TabPanel ongletsCollectionDefaut = new TabPanel();// Onlget formulaire GENERALongletsCollectionDefaut.add(creerOngletGeneral());// Onlget formulaire AUTEURongletsCollectionDefaut.add(creerOngletPersonne());return ongletsCollectionDefaut;}protected TabPanel creerOngletsHerbier() {TabPanel ongletsCollectionHerbier = 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)ongletsCollectionHerbier.setHeight("100%");// Onlget formulaire GENERALongletsCollectionHerbier.add(creerOngletGeneral());// Onlget formulaire AUTEURongletsCollectionHerbier.add(creerOngletPersonne());// Onlget formulaire PUBLICATIONongletsCollectionHerbier.add(creerOngletPublication());// Onlget formulaire DESCRIPTIONongletsCollectionHerbier.add(creerOngletDescription());// Onlget formulaire CONTENUongletsCollectionHerbier.add(creerOngletContenu());// Onlget formulaire INVENTAIREongletsCollectionHerbier.add(creerOngletInventaire());// Sélection de l'onglet par défautongletsCollectionHerbier.setSelection(generalOnglet);return ongletsCollectionHerbier;}private TabItem creerOngletGeneral() {generalOnglet = new CollectionFormGeneral(this);return generalOnglet;}private TabItem creerOngletPersonne() {personneOnglet = new CollectionFormPersonne(this);return personneOnglet;}private TabItem creerOngletPublication() {publicationOnglet = new CollectionFormPublication(this);return publicationOnglet;}private TabItem creerOngletDescription() {descriptionOnglet = new CollectionFormDescription(this);return descriptionOnglet;}private TabItem creerOngletContenu() {contenuOnglet = new CollectionFormContenu(this);return contenuOnglet;}private TabItem creerOngletInventaire() {inventaireOnglet = new CollectionFormInventaire(this);return inventaireOnglet;}public void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof Information) {Information info = (Information) nouvellesDonnees;rafraichirInformation(info);} else {GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);}controlerFermetureApresRafraichissement();}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_collection")) {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);}peupler();actualiserTitrePanneau();} else if (info.getType().equals("ajout_collection")) {if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {String collectionId = (String) info.getDonnee(0);Info.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liéespersonneOnglet.rafraichir(info);publicationOnglet.rafraichir(info);} else {Info.display("Ajout d'une Institution", info.toString());}}}private void peupler() {if (collection != null) {nomChp.setValue(collection.getNom());typesCollectionCombo.peupler(collection.getTypeNcd());peuplerOnglets();}}private void peuplerOnglets() {generalOnglet.peupler();personneOnglet.peupler();}private void actualiserTitrePanneau() {String titre = i18nC.titreModifFormCollection();// Composition du titretitre += " - ID : "+collection.getId();panneauFormulaire.setHeading(titre);}@Overrideprotected SelectionListener<ButtonEvent> creerEcouteurValidation() {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)) {soumettreFormulaire();clicBoutonvalidation = true;} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {soumettreFormulaire();} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {mediateur.clicMenu(menuIdCourant);} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {reinitialiserFormulaire();}}};return ecouteur;}protected boolean soumettreFormulaire() {// Vérification de la validité des champs du formulaireboolean fomulaireValide = verifierFormulaire();if (fomulaireValide) {// 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);}}soumettreOnglets();}return fomulaireValide;}private void soumettreOnglets() {personneOnglet.soumettre();}protected void reinitialiserFormulaire() {if (mode.equals(StructureForm.MODE_MODIFIER)) {mediateur.afficherFormCollection(collection.getId());} else {mediateur.afficherFormCollection(null);}}private Collection collecterCollection() {collectionCollectee = (Collection) collection.cloner(new Collection());this.collecter();collecterOnglets();Collection collectionARetourner = null;if (!collectionCollectee.comparer(collection)) {collectionARetourner = collection = collectionCollectee;}return collectionARetourner;}private void collecter() {collectionCollectee.setNom(nomChp.getValue());collectionCollectee.setTypeNcd(typesCollectionCombo.getValue().getId());}private void collecterOnglets() {generalOnglet.collecter();}protected boolean verifierFormulaire() {ArrayList<String> messages = new ArrayList<String>();// Vérification des infos sur le nom de la collectionif (nomChp.getValue() == null || nomChp.getValue().equals("") || collection.getNom().equals("")) {messages.add("Veuillez donner un nom à la collection.");}// Vérification des infos sur le type de collectionif (typesCollectionCombo.getValue() == null || typesCollectionCombo.getValue().equals("") || collection.getIdProjet().equals("")) {messages.add("Veuillez sélectionner un type pour la collection.");}messages.addAll(verifierOnglets());// Affichage des messages d'alerteif (messages.size() != 0) {String[] tableauDesMessages = {};tableauDesMessages = messages.toArray(tableauDesMessages);MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);return false;}return true;}private ArrayList<String> verifierOnglets() {ArrayList<String> messages = new ArrayList<String>();messages.addAll(generalOnglet.verifier());messages.addAll(personneOnglet.verifier());return messages;}}