Rev 1249 | Rev 1308 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.vues.projet;import java.util.ArrayList;import org.tela_botanica.client.ComposantClass;import org.tela_botanica.client.Mediateur;import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;import org.tela_botanica.client.composants.InfoLogger;import org.tela_botanica.client.interfaces.Rafraichissable;import org.tela_botanica.client.modeles.Information;import org.tela_botanica.client.modeles.MenuApplicationId;import org.tela_botanica.client.modeles.projet.Projet;import org.tela_botanica.client.util.Debug;import org.tela_botanica.client.util.Pattern;import org.tela_botanica.client.util.UtilArray;import org.tela_botanica.client.util.UtilString;import org.tela_botanica.client.vues.Formulaire;import com.extjs.gxt.ui.client.Style.Scroll;import com.extjs.gxt.ui.client.event.BaseEvent;import com.extjs.gxt.ui.client.event.Events;import com.extjs.gxt.ui.client.event.Listener;import com.extjs.gxt.ui.client.widget.Info;import com.extjs.gxt.ui.client.widget.MessageBox;import com.extjs.gxt.ui.client.widget.form.CheckBox;import com.extjs.gxt.ui.client.widget.form.FieldSet;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.layout.FlowLayout;import com.extjs.gxt.ui.client.widget.layout.FormData;import com.extjs.gxt.ui.client.widget.layout.FormLayout;public class ProjetForm extends Formulaire implements Rafraichissable {private Projet projet;private String listeValeurIndexationDureeId = "dureesIndexation";private String listeValeurIndexationFrequenceId = "frequencesIndexation";private String listeLanguesId = "langues";private FieldSet generalitesFieldset = null;private TextField<String> nomChp = null;private TextField<String> abreviationChp = null;private TextArea descriptionChp = null;private TextArea resumeChp = null;private TextField<String> urlChp = null;private FieldSet complementFieldset = null;private TextField<String> motsClesChp = null;private TextField<String> citationChp = null;private TextField<String> licenceChp = null;private ChampComboBoxListeValeurs langueChp = null;private CheckBox markPublicChp = null;private FieldSet indexationFieldset = null;private TextField<String> indexationHeureChp = null;private ChampComboBoxListeValeurs indexationDureeChp = null;private ChampComboBoxListeValeurs indexationFrequenceChp = null;private boolean formulaireValideOk = false;private boolean projetValideOk = false;private Rafraichissable vueExterneARafraichirApresValidation = null;public ProjetForm(Mediateur mediateurCourrant, String projetId) {initialiserProjetForm(mediateurCourrant, projetId);}public ProjetForm(Mediateur mediateurCourrant, String projetId, Rafraichissable vueARafraichirApresValidation) {vueExterneARafraichirApresValidation = vueARafraichirApresValidation;initialiserProjetForm(mediateurCourrant, projetId);}private void initialiserProjetForm(Mediateur mediateurCourant, String projetId) {projet = new Projet();projet.setId(projetId);String modeDeCreation = (projet.getId().isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);initialiserFormulaire(mediateurCourant, modeDeCreation, MenuApplicationId.PROJET);panneauFormulaire.setLayout(new FlowLayout());panneauFormulaire.setScrollMode(Scroll.AUTO);genererTitreFormulaire();creerZoneGeneralites();panneauFormulaire.add(generalitesFieldset);creerZoneComplement();panneauFormulaire.add(complementFieldset);creerZoneIndexation();panneauFormulaire.add(indexationFieldset);creerTabIndex();if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {mediateur.selectionnerProjet(this, projetId);}}private void genererTitreFormulaire() {String titre = i18nC.projetTitreFormAjout();if (mode.equals(Formulaire.MODE_MODIFIER)) {titre = i18nC.projetTitreFormModif();if (projet != null) {titre += " - "+i18nC.id()+": "+projet.getId();}}panneauFormulaire.setHeading(titre);}private void creerZoneGeneralites() {FormLayout layout = new FormLayout();layout.setLabelWidth(100);// Fieldset Infos GénéralesgeneralitesFieldset = new FieldSet();generalitesFieldset.setHeading(i18nC.projetTitreInfoGenerale());generalitesFieldset.setCollapsible(true);generalitesFieldset.setLayout(layout);nomChp = new TextField<String>();nomChp.setName("cpu");nomChp.setFieldLabel(i18nC.projetNom());nomChp.addStyleName(ComposantClass.OBLIGATOIRE);nomChp.addListener(Events.Valid, creerEcouteurChampObligatoire());generalitesFieldset.add(nomChp, new FormData(450, 0));abreviationChp = new TextField<String>();abreviationChp.setFieldLabel(i18nC.projetAbreviation());abreviationChp.addStyleName(ComposantClass.OBLIGATOIRE);abreviationChp.addListener(Events.Valid, creerEcouteurChampObligatoire());generalitesFieldset.add(abreviationChp, new FormData(450, 0));descriptionChp = new TextArea();descriptionChp.setFieldLabel(i18nC.projetDescription());descriptionChp.addStyleName(ComposantClass.OBLIGATOIRE);descriptionChp.addListener(Events.Valid, creerEcouteurChampObligatoire());generalitesFieldset.add(descriptionChp, new FormData(450, 0));resumeChp = new TextArea();resumeChp.setFieldLabel(i18nC.projetResume());resumeChp.addStyleName(ComposantClass.OBLIGATOIRE);resumeChp.addListener(Events.Valid, creerEcouteurChampObligatoire());generalitesFieldset.add(resumeChp, new FormData(450, 0));urlChp = new TextField<String>();urlChp.setFieldLabel(i18nC.projetUrl());generalitesFieldset.add(urlChp, new FormData(450, 0));}private void creerZoneComplement() {FormLayout layout = new FormLayout();layout.setLabelWidth(100);// Fieldset ComplémentcomplementFieldset = new FieldSet();complementFieldset.setHeading(i18nC.projetTitreComplement());complementFieldset.setCollapsible(true);complementFieldset.setLayout(layout);motsClesChp = new TextField<String>();motsClesChp.setFieldLabel(i18nC.projetMotsCles());complementFieldset.add(motsClesChp, new FormData(450, 0));citationChp = new TextField<String>();citationChp.setFieldLabel(i18nC.projetCitation());complementFieldset.add(citationChp, new FormData(450, 0));licenceChp = new TextField<String>();licenceChp.setFieldLabel(i18nC.projetLicence());complementFieldset.add(licenceChp, new FormData(450, 0));langueChp = new ChampComboBoxListeValeurs(i18nC.projetLangue(), listeLanguesId);complementFieldset.add(langueChp, new FormData(200, 0));markPublicChp = new CheckBox();markPublicChp.setFieldLabel(i18nC.projetMarkPublic());markPublicChp.addListener(Events.Change, new Listener<BaseEvent>() {public void handleEvent(BaseEvent be) {if (markPublicChp.getValue()) {indexationFieldset.show();} else {indexationFieldset.hide();}}});complementFieldset.add(markPublicChp);}private void creerZoneIndexation() {FormLayout layout = new FormLayout();layout.setLabelWidth(100);// Fieldset IndexationindexationFieldset = new FieldSet();indexationFieldset.setHeading(i18nC.projetTitreIndexation());indexationFieldset.setCollapsible(true);indexationFieldset.setLayout(layout);indexationFieldset.hide();indexationFieldset.addListener(Events.Hide, new Listener<BaseEvent>() {public void handleEvent(BaseEvent be) {indexationHeureChp.clear();indexationFrequenceChp.clear();indexationDureeChp.clear();}});indexationHeureChp = new TextField<String>();indexationHeureChp.setFieldLabel(i18nC.projetIndexationHeure());indexationHeureChp.setToolTip(i18nC.projetMessageHeureMinute());indexationFieldset.add(indexationHeureChp, new FormData(80, 0));indexationFrequenceChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationFrequence(), listeValeurIndexationFrequenceId);indexationFieldset.add(indexationFrequenceChp, new FormData(120, 0));indexationDureeChp = new ChampComboBoxListeValeurs(i18nC.projetIndexationDuree(), listeValeurIndexationDureeId);indexationFieldset.add(indexationDureeChp, new FormData(80, 0));}private void creerTabIndex() {nomChp.setTabIndex(1);abreviationChp.setTabIndex(2);descriptionChp.setTabIndex(3);resumeChp.setTabIndex(4);urlChp.setTabIndex(5);motsClesChp.setTabIndex(6);citationChp.setTabIndex(7);licenceChp.setTabIndex(8);langueChp.setTabIndex(9);markPublicChp.setTabIndex(10);indexationHeureChp.setTabIndex(11);indexationFrequenceChp.setTabIndex(12);indexationDureeChp.setTabIndex(13);nomChp.focus();}public void rafraichir(Object nouvellesDonnees) {if (nouvellesDonnees instanceof Information) {Information info = (Information) nouvellesDonnees;rafraichirInformation(info);} else {Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));}if (etreValide()) {initialiserValidation();repandreRafraichissement();controlerFermeture();}}private void rafraichirInformation(Information info) {final String type = info.getType();// Gestion des problèmesif (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {Debug.log("MESSAGES:\n"+info.getMessages().toString());}// Gestion des actionsif (type.equals("selection_projet")) {if (info.getDonnee(0) != null) {projet = (Projet) info.getDonnee(0);}peuplerFormulaire();genererTitreFormulaire();}if (type.equals("ajout_projet") || type.equals("modif_projet")) {if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {projetValideOk = true;String projetId = (String) info.getDonnee(0);if (vueExterneARafraichirApresValidation != null) {projet.setId(projetId);}}}// Gestion des messagesif (type.equals("selection_projet")) {InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());} else if (type.equals("modif_projet")) {InfoLogger.display(i18nC.projetTitreFormModif(), info.toString());} else if (type.equals("ajout_projet")) {if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {String projetId = (String) info.getDonnee(0);InfoLogger.display(i18nC.projetTitreFormAjout(), "Le projet '"+projetId+"' a bien été ajouté");} else {InfoLogger.display(i18nC.projetTitreFormAjout(), info.toString(), true);}}}private Boolean etreValide() {Boolean valide = false;if (formulaireValideOk && projetValideOk) {valide = true;}return valide;}private void initialiserValidation() {formulaireValideOk = false;projetValideOk = false;}private void repandreRafraichissement() {if (vueExterneARafraichirApresValidation != null) {String type = "projet_modifie";if (mode.equals(Formulaire.MODE_AJOUTER)) {type = "projet_ajoute";}Information info = new Information(type);info.setDonnee(0, projet);vueExterneARafraichirApresValidation.rafraichir(info);}}public boolean soumettreFormulaire() {formulaireValideOk = verifierFormulaire();if (formulaireValideOk) {Projet projetCollecte = collecterProjet();if (projetCollecte != null) {if (mode.equals(Formulaire.MODE_AJOUTER)) {mediateur.ajouterProjet(this, projetCollecte);} else if (mode.equals(Formulaire.MODE_MODIFIER)) {mediateur.modifierProjet(this, projetCollecte);}}}return formulaireValideOk;}public boolean verifierFormulaire() {boolean valide = true;ArrayList<String> messages = new ArrayList<String>();String titre = nomChp.getValue();if (titre == null || titre.equals("")) {messages.add(i18nC.projetMessageNom());}String abr = abreviationChp.getValue();if (abr == null || abr.equals(i18nC.projetMessageAbreviation())) {messages.add(i18nC.projetMessageAbreviation());}String desc = descriptionChp.getValue();if (desc == null || desc.equals(i18nC.projetMessageDescription())) {messages.add(i18nC.projetDescription());}String resume = resumeChp.getValue();if (resume == null || resume.equals(i18nC.projetMessageResume())) {messages.add(i18nC.projetMessageResume());}String uri = urlChp.getValue();if (uri != null && ! uri.trim().isEmpty() && ! uri.matches(Pattern.url)) {messages.add(i18nC.messageUrlNonValide());}if (markPublicChp.getValue()) {String heure = indexationHeureChp.getValue();if (!UtilString.isEmpty(heure) && !heure.matches(Pattern.heureMinute)) {messages.add(i18nC.projetMessageHeureMinute());}}if (messages.size() != 0) {String[] tableauDeMessages = {};tableauDeMessages = messages.toArray(tableauDeMessages);MessageBox.alert(i18nC.erreurSaisieTitre(), UtilArray.implode(tableauDeMessages, "<br />"), null);valide = false;}return valide;}private void peuplerFormulaire() {nomChp.setValue(projet.getNom());abreviationChp.setValue(projet.getAbreviation());descriptionChp.setValue(projet.getDescription());resumeChp.setValue(projet.getResume());urlChp.setValue(projet.getUrl());motsClesChp.setValue(projet.getMotsCles());citationChp.setValue(projet.getCitation());licenceChp.setValue(projet.getLicence());langueChp.peupler(projet.getLangue());if (projet.getMarkPublic().equals("1")) {markPublicChp.setValue(true);String[] heureTab = projet.getIndexationHeure().split(":");if (heureTab.length > 1) {String heure = heureTab[0]+":"+heureTab[1];if (heure.matches(Pattern.heureMinute)) {indexationHeureChp.setValue(heure);}}indexationFrequenceChp.peupler(projet.getIndexationFreq());indexationDureeChp.peupler(projet.getIndexationDuree());} else {markPublicChp.setValue(false);}doLayout(true);}private Projet collecterProjet() {Projet projetCollecte = (Projet) projet.cloner(new Projet());projetCollecte.setNom(nomChp.getValue());projetCollecte.setAbreviation(abreviationChp.getValue());projetCollecte.setDescription(descriptionChp.getValue());projetCollecte.setResume(resumeChp.getValue());projetCollecte.setUrl(urlChp.getValue());projetCollecte.setMotsCles(motsClesChp.getValue());projetCollecte.setCitation(citationChp.getValue());projetCollecte.setLicence(licenceChp.getValue());projetCollecte.setLangue(langueChp.getValeur());String markPublic = (markPublicChp.getValue()) ? "1" : "0";projetCollecte.setMarkPublic(markPublic);projetCollecte.setIndexationHeure(indexationHeureChp.getValue());projetCollecte.setIndexationFreq(indexationFrequenceChp.getValeur());projetCollecte.setIndexationDuree(indexationDureeChp.getValeur());Projet projetARetourner = null;if (!projetCollecte.comparer(projet)) {projetARetourner = projet = projetCollecte;Debug.log(projetARetourner.toString());}return projetARetourner;}public void reinitialiserFormulaire() {if (mode.equals(Formulaire.MODE_MODIFIER)) {mediateur.afficherFormProjet(projet.getId());} else {mediateur.afficherFormProjet(null);}}}