Rev 851 | Rev 860 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;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 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.Events;import com.extjs.gxt.ui.client.event.Listener;import com.extjs.gxt.ui.client.event.SelectionListener;import com.extjs.gxt.ui.client.store.StoreEvent;import com.extjs.gxt.ui.client.store.StoreListener;import com.extjs.gxt.ui.client.widget.Info;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 {private Collection collection = null;private Collection collectionCollectee = null;private ChampComboBoxListeValeurs typesCollectionCombo = null;private TabPanel onglets = null;private TabItem generalOnglet = null;private TabItem auteurOnglet = null;private TabItem publicationOnglet = null;private TabItem descriptionOnglet = null;private TabItem contenuOnglet = null;private TabItem 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.setValeurDefaut(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(creerOngletAuteur());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(creerOngletAuteur());// 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(contenuOnglet);return ongletsCollectionHerbier;}private TabItem creerOngletGeneral() {generalOnglet = new CollectionFormGeneral(this);return generalOnglet;}private TabItem creerOngletAuteur() {auteurOnglet = new CollectionFormAuteur(this);return auteurOnglet;}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 = 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) {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_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 actualiserPeuplementOnglet() {// TODO : déclencher le peuplement de l'onglet courant}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);}}}return fomulaireValide;}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());collecterOngletGeneral();Collection collectionARetourner = null;if (!collectionCollectee.comparer(collection)) {collectionARetourner = collection = collectionCollectee;}return collectionARetourner;}private void collecterOngletGeneral() {if (generalOnglet.getData("acces").equals(true)) {}}protected boolean verifierFormulaire() {return true;}}