New file |
0,0 → 1,326 |
package org.tela_botanica.client.vues.commentaire; |
|
import java.util.ArrayList; |
|
import org.tela_botanica.client.ComposantClass; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.composants.ChampComboBoxRechercheTempsReelPaginable; |
import org.tela_botanica.client.composants.ChampSliderPourcentage; |
import org.tela_botanica.client.composants.InfoLogger; |
import org.tela_botanica.client.composants.pagination.ProxyProjets; |
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.commentaire.Commentaire; |
import org.tela_botanica.client.modeles.projet.Projet; |
import org.tela_botanica.client.modeles.projet.ProjetListe; |
import org.tela_botanica.client.synchronisation.Sequenceur; |
import org.tela_botanica.client.util.Debug; |
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.data.ModelData; |
import com.extjs.gxt.ui.client.data.ModelType; |
import com.extjs.gxt.ui.client.event.Events; |
import com.extjs.gxt.ui.client.store.ListStore; |
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.ComboBox; |
import com.extjs.gxt.ui.client.widget.form.Field; |
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.layout.FormData; |
import com.extjs.gxt.ui.client.widget.layout.FormLayout; |
|
|
public class CommentaireForm extends Formulaire implements Rafraichissable { |
|
private Commentaire commentaire; |
|
private ChampComboBoxRechercheTempsReelPaginable projetsCombo = null; |
private TextField<String> titreChp; |
private TextArea texteChp; |
private ChampSliderPourcentage ponderationChp; |
private CheckBox publicChp; |
|
private static boolean formulaireValideOk = false; |
private static boolean commentaireValideOk = false; |
|
private Sequenceur sequenceur = new Sequenceur(); |
|
public CommentaireForm(Mediateur mediateurCourrant, String commentaireId) { |
initialiserCommentaireForm(mediateurCourrant, commentaireId); |
} |
|
public CommentaireForm(Mediateur mediateurCourrant, String commentaireId, Rafraichissable vueARafraichirApresValidation) { |
vueExterneARafraichirApresValidation = vueARafraichirApresValidation; |
initialiserCommentaireForm(mediateurCourrant, commentaireId); |
} |
|
private void initialiserCommentaireForm(Mediateur mediateurCourrant, String commentaireId) { |
initialiserValidation(); |
|
commentaire = new Commentaire(); |
commentaire.setId(commentaireId); |
|
String modeDeCreation = (UtilString.isEmpty(commentaire.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER); |
initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COMMENTAIRE); |
|
panneauFormulaire.setLayout(new FormLayout()); |
genererTitreFormulaire(); |
creerChamps(); |
|
if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) { |
mediateur.selectionnerCommentaire(this, commentaireId, null); |
} |
} |
|
private void genererTitreFormulaire() { |
String titre = i18nC.commentaireTitreFormAjout(); |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
titre = i18nC.commentaireTitreFormModif(); |
if (commentaire != null) { |
titre += " - "+i18nC.id()+": "+commentaire.getId(); |
} |
} |
panneauFormulaire.setHeading(titre); |
} |
|
private void creerChamps() { |
|
ModelType modelTypeProjets = new ModelType(); |
modelTypeProjets.setRoot("projets"); |
modelTypeProjets.setTotalName("nbElements"); |
modelTypeProjets.addField("cpr_nom"); |
modelTypeProjets.addField("cpr_id_projet"); |
|
String displayNameProjets = "cpr_nom"; |
ProxyProjets<ModelData> proxyProjets = new ProxyProjets<ModelData>(sequenceur); |
|
projetsCombo = new ChampComboBoxRechercheTempsReelPaginable(proxyProjets, modelTypeProjets, displayNameProjets); |
projetsCombo.setWidth(100, 550); |
projetsCombo.getCombo().setTabIndex(tabIndex++); |
projetsCombo.getCombo().setFieldLabel(i18nC.projetChamp()); |
projetsCombo.getCombo().setEmptyText(i18nC.txtListeProjetDefaut()); |
projetsCombo.getCombo().setForceSelection(true); |
projetsCombo.getCombo().setEditable(false); |
projetsCombo.getCombo().setAllowBlank(false); |
projetsCombo.getCombo().setValidator(new Validator() { |
public String validate(Field<?> champ, String valeurAValider) { |
String retour = null; |
if (UtilString.isEmpty(valeurAValider) |
|| projetsCombo.getStore().findModel("cpr_nom", valeurAValider) == null) { |
champ.setValue(null); |
retour = i18nC.selectionnerValeur(); |
} |
return retour; |
} |
}); |
|
panneauFormulaire.add(projetsCombo, new FormData(450, 0)); |
|
titreChp = new TextField<String>(); |
titreChp.setFieldLabel(i18nC.commentaireTitre()); |
titreChp.setAllowBlank(false); |
titreChp.addStyleName(ComposantClass.OBLIGATOIRE); |
titreChp.addListener(Events.Valid, creerEcouteurChampObligatoire()); |
titreChp.addListener(Events.Invalid, creerEcouteurChampObligatoire()); |
panneauFormulaire.add(titreChp, new FormData(450, 0)); |
|
texteChp = new TextArea(); |
texteChp.setFieldLabel(i18nC.commentaireTexte()); |
panneauFormulaire.add(texteChp, new FormData(450, 250)); |
|
ponderationChp = new ChampSliderPourcentage(i18nC.commentairePonderation()); |
panneauFormulaire.add(ponderationChp, new FormData(450, 0)); |
|
publicChp = new CheckBox(); |
publicChp.setFieldLabel(i18nC.donneePublic()); |
panneauFormulaire.add(publicChp, new FormData(50, 0)); |
} |
|
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof Commentaire) { |
// Si on a reçu les details d'une publication |
rafraichirCommentaire((Commentaire) nouvellesDonnees); |
} else if (nouvellesDonnees instanceof Information) { |
rafraichirInformation((Information) nouvellesDonnees); |
} else { |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass())); |
} |
|
if (etreValide()) { |
initialiserValidation(); |
repandreRafraichissement(); |
controlerFermeture(); |
} |
} |
|
private void rafraichirCommentaire(Commentaire commentaireRecu) { |
commentaire = commentaireRecu; |
peuplerFormulaire(); |
genererTitreFormulaire(); |
} |
|
private String getValeurComboProjets() { |
String valeur = ""; |
if (projetsCombo.getCombo().getValue() != null && projetsCombo.getCombo().isValid()) { |
Projet projet = new Projet (projetsCombo.getValeur()); |
valeur = projet.getId(); |
} |
return valeur; |
} |
private void setValeurComboProjets() { |
if (projetsCombo.getStore() != null ) { |
if (mode.equals(Formulaire.MODE_MODIFIER) && commentaire != null) { |
projetsCombo.getCombo().setValue(projetsCombo.getStore().findModel("cpr_id_projet", commentaire.getIdProjet())); |
} else if (mode.equals(Formulaire.MODE_AJOUTER)) { |
projetsCombo.getCombo().setValue(projetsCombo.getStore().findModel("cpr_id_projet", mediateur.getProjetId())); |
} |
} |
} |
|
private void rafraichirInformation(Information info) { |
// Gestion des messages d'erreur |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) { |
Debug.log("MESSAGES:\n"+info.getMessages().toString()); |
} |
|
// Gestion des actions |
String type = info.getType(); |
if (type.equals("ajout_commentaire") || type.equals("modif_commentaire")) { |
commentaireValideOk = true; |
} |
if (info.getType().equals("ajout_commentaire")) { |
if (vueExterneARafraichirApresValidation != null) { |
String noteId = (String) info.getDonnee(0); |
commentaire.setId(noteId); |
} |
} |
|
// Gestion des messages |
if (info.getType().equals("modif_commentaire")) { |
InfoLogger.display("Modification d'une note", info.toString()); |
} else if (info.getType().equals("ajout_commentaire")) { |
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) { |
String noteId = (String) info.getDonnee(0); |
InfoLogger.display("Ajout d'une note", "La note '"+noteId+"' a bien été ajoutée"); |
} else { |
InfoLogger.display("Ajout d'une note", info.toString()); |
} |
} |
} |
|
private Boolean etreValide() { |
Boolean valide = false; |
if (formulaireValideOk && commentaireValideOk) { |
valide = true; |
} |
return valide; |
} |
|
private void initialiserValidation() { |
formulaireValideOk = false; |
commentaireValideOk = false; |
} |
|
private void repandreRafraichissement() { |
if (vueExterneARafraichirApresValidation != null) { |
String type = "commentaire_modifiee"; |
if (mode.equals(Formulaire.MODE_AJOUTER)) { |
type = "commentaire_ajoutee"; |
} |
Information info = new Information(type); |
info.setDonnee(0, commentaire); |
vueExterneARafraichirApresValidation.rafraichir(info); |
} |
} |
|
public boolean soumettreFormulaire() { |
formulaireValideOk = verifierFormulaire(); |
if (formulaireValideOk) { |
soumettreCommentaire(); |
} |
return formulaireValideOk; |
} |
|
private void soumettreCommentaire() { |
Commentaire commentaireCollectee = collecterCommentaire(); |
if (commentaireCollectee != null) { |
if (mode.equals(Formulaire.MODE_AJOUTER)) { |
mediateur.ajouterCommentaire(this, commentaireCollectee); |
} else if (mode.equals(Formulaire.MODE_MODIFIER)) { |
mediateur.modifierCommentaire(this, commentaireCollectee); |
} |
} |
} |
|
public boolean verifierFormulaire() { |
boolean valide = true; |
ArrayList<String> messages = new ArrayList<String>(); |
|
String titre = titreChp.getValue(); |
if (titre == null || titre.equals("")) { |
messages.add(i18nC.commentaireMessageTitre()); |
} |
|
if (UtilString.isEmpty(getValeurComboProjets())) { |
String selectionDe = i18nC.articleUn()+" "+i18nC.projetSingulier(); |
String pour = i18nC.articleLa()+" "+i18nC.commentaireSingulier(); |
messages.add(i18nM.selectionObligatoire(selectionDe, pour)); |
} |
|
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() { |
setValeurComboProjets(); |
titreChp.setValue(commentaire.getTitre()); |
texteChp.setValue(commentaire.getTexte()); |
ponderationChp.peupler(commentaire.getPonderation()); |
boolean acces = (commentaire.etrePublic() ? true : false); |
publicChp.setValue(acces); |
} |
|
private Commentaire collecterCommentaire() { |
Commentaire commentaireCollectee = (Commentaire) commentaire.cloner(new Commentaire()); |
|
commentaireCollectee.setIdProjet(getValeurComboProjets()); |
|
String titre = titreChp.getValue(); |
commentaireCollectee.setTitre(titre); |
|
String texte = texteChp.getValue(); |
commentaireCollectee.setTexte(texte); |
|
String ponderation = ponderationChp.getValeur(); |
commentaireCollectee.setPonderation(ponderation); |
|
String acces = (publicChp.getValue() ? "1" : "0"); |
commentaireCollectee.setPublic(acces); |
|
Commentaire commentaireARetourner = null; |
if (!commentaireCollectee.comparer(commentaire)) { |
commentaireARetourner = commentaire = commentaireCollectee; |
} |
return commentaireARetourner; |
} |
|
public void reinitialiserFormulaire() { |
if (mode.equals(Formulaire.MODE_MODIFIER)) { |
mediateur.afficherFormPublication(commentaire.getId()); |
} else { |
mediateur.afficherFormPublication(null); |
} |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/commentaire/CommentaireForm.java:r1136-1368 |
Added: svn:executable |
+* |
\ No newline at end of property |