Rev 638 | Blame | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues;import java.util.HashMap;import java.util.List;import org.tela_botanica.client.Mediateur;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.Structure;import org.tela_botanica.client.modeles.StructureConservation;import org.tela_botanica.client.modeles.StructureValorisation;import org.tela_botanica.client.modeles.Valeur;import org.tela_botanica.client.modeles.ValeurListe;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.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.form.FieldSet;import com.extjs.gxt.ui.client.widget.form.HiddenField;import com.extjs.gxt.ui.client.widget.form.Radio;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;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, Widget>champs = new HashMap<String, Widget>();private TabItem generalOnglet = null;private TabItem auteurOnglet = null;private TabItem descriptionOnglet = null;private TabItem contenuOnglet = null;private TabItem documentOnglet = null;private TabItem inventaireOnglet = null;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 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 = creerOnglet(i18nC.collectionGeneral(), "general");generalOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletGeneral();generalOnglet.layout();}});//+-----------------------------------------------------------------------------------------------------------+// Champs cachésHiddenField<String> idCollectionChp = new HiddenField<String>();champs.put("idCollectionChp", idCollectionChp);//+-----------------------------------------------------------------------------------------------------------+// Fieldset ADMINISTRATIFFieldSet administratifFieldSet = new FieldSet();administratifFieldSet.setHeading(i18nC.collectionGeneralTitre());administratifFieldSet.setCollapsible(true);administratifFieldSet.setLayout(creerFormLayout(120, LabelAlign.LEFT));TextField<String> nomChp = new TextField<String>();nomChp.setTabIndex(tabIndex++);nomChp.setFieldLabel(i18nC.nomCollection());nomChp.setAllowBlank(false);nomChp.getMessages().setBlankText(i18nC.champObligatoire());administratifFieldSet.add(nomChp, new FormData(450, 0));generalOnglet.add(administratifFieldSet);//+-----------------------------------------------------------------------------------------------------------+// Fieldset DESCRIPTIONFieldSet descriptionFieldSet = new FieldSet();descriptionFieldSet.setHeading(i18nC.collectionDescriptionTitre());descriptionFieldSet.setCollapsible(true);descriptionFieldSet.setLayout(creerFormLayout(120, LabelAlign.LEFT));generalOnglet.add(descriptionFieldSet);//+-----------------------------------------------------------------------------------------------------------+// Retourreturn 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 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.collectionDescription(), "contenu");contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletContenu();contenuOnglet.layout();}});return contenuOnglet;}private TabItem creerOngletDocument() {documentOnglet = creerOnglet(i18nC.collectionDescription(), "document");documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {public void handleEvent(ComponentEvent be) {//peuplerOngletDocument();documentOnglet.layout();}});return documentOnglet;}private TabItem creerOngletInventaire() {inventaireOnglet = creerOnglet(i18nC.collectionDescription(), "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();}public 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();}}public void rafraichirValeurListe(ValeurListe listeValeurs) {List<Valeur> liste = listeValeurs.toList();// Test pour savoir si la liste contient des élémentsif (liste.size() > 0) {}}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}}