/branches/v1.1-aramon/src/org/tela_botanica/client/vues/commentaire/CommentaireVue.java |
---|
New file |
0,0 → 1,51 |
package org.tela_botanica.client.vues.commentaire; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.Information; |
import org.tela_botanica.client.modeles.commentaire.Commentaire; |
import org.tela_botanica.client.modeles.commentaire.CommentaireListe; |
import com.extjs.gxt.ui.client.Style.LayoutRegion; |
import com.extjs.gxt.ui.client.util.Margins; |
import com.extjs.gxt.ui.client.widget.LayoutContainer; |
import com.extjs.gxt.ui.client.widget.layout.BorderLayout; |
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData; |
import com.google.gwt.core.client.GWT; |
public class CommentaireVue extends LayoutContainer implements Rafraichissable { |
private Mediateur mediateur = null; |
private CommentaireListeVue panneauListe; |
private CommentaireDetailVue panneauDetail; |
public CommentaireVue(Mediateur mediateurCourant) { |
mediateur = mediateurCourant; |
BorderLayout layout = new BorderLayout(); |
layout.setEnableState(false); |
setLayout(layout); |
panneauListe = new CommentaireListeVue(mediateur); |
add(panneauListe, new BorderLayoutData(LayoutRegion.CENTER)); |
panneauDetail = new CommentaireDetailVue(mediateur); |
BorderLayoutData southData = new BorderLayoutData(LayoutRegion.SOUTH, .5f, 200, 1000); |
southData.setSplit(true); |
southData.setMargins(new Margins(5, 0, 0, 0)); |
add(panneauDetail, southData); |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof Commentaire) { |
panneauDetail.rafraichir(nouvellesDonnees); |
} else if (nouvellesDonnees instanceof CommentaireListe) { |
panneauListe.rafraichir(nouvellesDonnees); |
mediateur.desactiverChargement(); |
} else if (nouvellesDonnees instanceof Information) { |
panneauListe.rafraichir(nouvellesDonnees); |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/commentaire/CommentaireVue.java:r1136-1368 |
/branches/v1.1-aramon/src/org/tela_botanica/client/vues/commentaire/CommentaireListeVue.java |
---|
New file |
0,0 → 1,325 |
package org.tela_botanica.client.vues.commentaire; |
import java.util.ArrayList; |
import java.util.HashMap; |
import java.util.Iterator; |
import java.util.List; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.composants.InfoLogger; |
import org.tela_botanica.client.i18n.Constantes; |
import org.tela_botanica.client.images.Images; |
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.Utilisateur; |
import org.tela_botanica.client.modeles.Valeur; |
import org.tela_botanica.client.modeles.ValeurListe; |
import org.tela_botanica.client.modeles.aDonnee; |
import org.tela_botanica.client.modeles.commentaire.Commentaire; |
import org.tela_botanica.client.modeles.commentaire.CommentaireListe; |
import org.tela_botanica.client.modeles.structure.StructureListe; |
import org.tela_botanica.client.util.Debug; |
import org.tela_botanica.client.vues.BarrePaginationVue; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.SortDir; |
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.SelectionChangedEvent; |
import com.extjs.gxt.ui.client.event.SelectionChangedListener; |
import com.extjs.gxt.ui.client.event.SelectionListener; |
import com.extjs.gxt.ui.client.store.GroupingStore; |
import com.extjs.gxt.ui.client.store.ListStore; |
import com.extjs.gxt.ui.client.util.Util; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Info; |
import com.extjs.gxt.ui.client.widget.button.Button; |
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig; |
import com.extjs.gxt.ui.client.widget.grid.ColumnData; |
import com.extjs.gxt.ui.client.widget.grid.ColumnModel; |
import com.extjs.gxt.ui.client.widget.grid.Grid; |
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer; |
import com.extjs.gxt.ui.client.widget.grid.GridGroupRenderer; |
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel; |
import com.extjs.gxt.ui.client.widget.grid.GroupColumnData; |
import com.extjs.gxt.ui.client.widget.grid.GroupingView; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.extjs.gxt.ui.client.widget.menu.Menu; |
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar; |
import com.google.gwt.core.client.GWT; |
public class CommentaireListeVue extends ContentPanel implements Rafraichissable { |
private Mediateur mediateur = null; |
private Constantes i18nC = null; |
private Grid<Commentaire> grille = null; |
private GroupingStore<Commentaire> store = null; |
private ColumnModel modeleDesColonnes = null; |
private Button ajouter; |
private Button modifier; |
private Button supprimer; |
private BarrePaginationVue pagination = null; |
private CommentaireListe commentaires = null; |
protected boolean commentairesChargementOk = false; |
protected HashMap<String, Valeur> ontologie = null; |
protected boolean ontologieChargementOk = false; |
public CommentaireListeVue(Mediateur mediateurCourant) { |
mediateur = mediateurCourant; |
i18nC = Mediateur.i18nC; |
setLayout(new FitLayout()); |
setHeading(i18nC.menuCommentaire()); |
// Gestion de l'ontologie |
ontologie = new HashMap<String, Valeur>(); |
mediateur.obtenirListeValeurEtRafraichir(this, "typeCommentaireCollection", null); |
// Gestion de la barre d'outil |
ToolBar toolBar = new ToolBar(); |
ajouter = new Button(i18nC.ajouter()); |
ajouter.setIcon(Images.ICONES.ajouter()); |
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent be) { |
mediateur.clicAjouterCommentaire(); |
} |
}); |
toolBar.add(ajouter); |
modifier = new Button(i18nC.modifier()); |
modifier.setIcon(Images.ICONES.formModifier()); |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent be) { |
mediateur.clicModifierCommentaire(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
toolBar.add(modifier); |
supprimer = new Button(i18nC.supprimer()); |
supprimer.setIcon(Images.ICONES.supprimer()); |
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent be) { |
mediateur.clicSupprimerCommentaire(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
toolBar.add(supprimer); |
setTopComponent(toolBar); |
// Gestion de la grille |
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>(); |
// ATTENTION : les noms des colonnes doivent correspondre aux noms variables de la classe utilisée dans la liste |
colonnes.add(new ColumnConfig("_collection_nom_", i18nC.commentaireCollection(), 150)); |
colonnes.add(creerColonneType()); |
colonnes.add(new ColumnConfig("_titre_", i18nC.commentaireTitre(), 150)); |
colonnes.add(new ColumnConfig("_ponderation_", i18nC.commentairePonderation(), 30)); |
colonnes.add(creerColonneAcces()); |
modeleDesColonnes = new ColumnModel(colonnes); |
GridSelectionModel<Commentaire> modeleDeSelection = new GridSelectionModel<Commentaire>(); |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Commentaire>() { |
public void selectionChanged(SelectionChangedEvent<Commentaire> event) { |
Commentaire commentaire = (Commentaire) event.getSelectedItem(); |
clicListe(commentaire); |
} |
}); |
store = new GroupingStore<Commentaire>(); |
//store.sort("cmhl_date_modification", SortDir.ASC); |
store.groupBy("_collection_nom_"); |
store.setRemoteGroup(false); |
GroupingView vueDeGroupe = new GroupingView(); |
vueDeGroupe.setShowGroupedColumn(false); |
vueDeGroupe.setForceFit(true); |
vueDeGroupe.setAutoFill(true); |
vueDeGroupe.setGroupRenderer(new GridGroupRenderer() { |
public String render(GroupColumnData data) { |
String f = modeleDesColonnes.getColumnById(data.field).getHeader(); |
String l = data.models.size() == 1 ? i18nC.commentaireSingulier() : i18nC.commentairePluriel(); |
if (Util.isEmptyString(data.group)) return f + ": aucune (" + data.models.size() + " " + l + ")"; |
else return f + ": " + data.group + " (" + data.models.size() + " " + l + ")"; |
} |
}); |
grille = new Grid<Commentaire>(store, modeleDesColonnes); |
grille.setView(vueDeGroupe); |
grille.setWidth("100%"); |
grille.setAutoExpandColumn("_titre_"); |
grille.setSelectionModel(modeleDeSelection); |
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() { |
public void handleEvent(BaseEvent be) { |
grille.getSelectionModel().select(0, false); |
} |
}); |
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){ |
public void handleEvent(BaseEvent be) { |
modifier.fireEvent(Events.Select); |
} |
}); |
add(grille); |
// Définition de la barre de pagination |
pagination = new BarrePaginationVue(new StructureListe(), mediateur); |
setBottomComponent(pagination); |
} |
private ColumnConfig creerColonneType() { |
GridCellRenderer<Commentaire> typeRendu = new GridCellRenderer<Commentaire>() { |
public String render(Commentaire model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<Commentaire> store, Grid<Commentaire> grid) { |
// FIXME : créer une classe Ontologie qui mixe le code ci-dessous et tout ce qui concerne l'ontologie dans DetailVue |
String type = ""; |
String[] valeurs = model.getCollectionACommentaire().getType().split(aDonnee.SEPARATEUR_VALEURS); |
int nbreValeurs = valeurs.length; |
int indexAvtDernier = nbreValeurs - 1; |
if (nbreValeurs > 0) { |
for (int i = 0; i < nbreValeurs; i++) { |
String valeur = valeurs[i]; |
if (valeur.matches("^[0-9]+$")) { |
if (valeur.equals("0")) { |
valeur = ""; |
} else if (ontologie != null) { |
Valeur valeurOntologie = ontologie.get(valeur); |
if (valeurOntologie != null) { |
valeur = valeurOntologie.getNom(); |
} |
} |
} |
if (i != indexAvtDernier) { |
type += valeur+", "; |
} else { |
type += valeur; |
} |
} |
} |
model.set("_type_", type); |
return type; |
} |
}; |
ColumnConfig typeColonne = new ColumnConfig("_type_", i18nC.commentaireType(), 100); |
typeColonne.setRenderer(typeRendu); |
return typeColonne; |
} |
private ColumnConfig creerColonneAcces() { |
GridCellRenderer<Commentaire> accesRendu = new GridCellRenderer<Commentaire>() { |
public String render(Commentaire model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<Commentaire> store, Grid<Commentaire> grid) { |
String acces = (model.etrePublic() ? i18nC.donneePublic() : i18nC.donneePrivee()); |
model.set("_public_", acces); |
return acces; |
} |
}; |
ColumnConfig accesColonne = new ColumnConfig("_public_", i18nC.commentairePublic(), 30); |
accesColonne.setRenderer(accesRendu); |
return accesColonne; |
} |
private void clicListe(Commentaire commentaire) { |
if (commentaire != null && store.getCount() > 0) { |
mediateur.clicListeCommentaire(commentaire); |
} |
} |
private void gererEtatActivationBouton() { |
int nbreElementDuMagazin = store.getCount(); |
ajouter.enable(); |
if (nbreElementDuMagazin <= 0) { |
supprimer.disable(); |
modifier.disable(); |
} else if (nbreElementDuMagazin > 0) { |
modifier.enable(); |
if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) { |
supprimer.enable(); |
} |
} |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof CommentaireListe) { |
commentaires = (CommentaireListe) nouvellesDonnees; |
pagination.setlistePaginable(commentaires); |
pagination.rafraichir(commentaires.getPageTable()); |
commentairesChargementOk = true; |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe listeValeursReceptionnee = (ValeurListe) nouvellesDonnees; |
Iterator<String> it = listeValeursReceptionnee.keySet().iterator(); |
while (it.hasNext()) { |
String cle = it.next(); |
Valeur valeur = listeValeursReceptionnee.get(cle); |
if (valeur != null) { |
ontologie.put(cle, valeur); |
} |
} |
ontologieChargementOk = true; |
} else if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
if (info.getType().equals("maj_utilisateur")) { |
gererEtatActivationBouton(); |
} else if (info.getType().equals("suppression_commentaire")) { |
String message = info.toString(); |
if (info.getDonnee(0) != null) { |
message = (String) info.getDonnee(0); |
} |
InfoLogger.display(i18nC.commentaireTitreSuppression(), message); |
supprimerCommentairesSelectionnees(); |
gererEtatActivationBouton(); |
} |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
if (etrePretAAfficherListe()) { |
chargerListe(); |
} |
layout(); |
} |
private boolean etrePretAAfficherListe() { |
boolean ok = false; |
if (commentairesChargementOk && ontologieChargementOk) { |
ok = true; |
} |
return ok; |
} |
private void chargerListe() { |
if (commentaires != null) { |
List<Commentaire> liste = commentaires.toList(); |
store.removeAll(); |
store.add(liste); |
mediateur.actualiserPanneauCentral(); |
} |
} |
private void supprimerCommentairesSelectionnees() { |
// FIXME : le code ci-dessous ne marche pas avec la GroupingView, nous utilisons le rechargement du menu à la place |
/* |
List<Commentaire> commentairesSelectionnees = grille.getSelectionModel().getSelectedItems(); |
Iterator<Commentaire> it = commentairesSelectionnees.iterator(); |
while (it.hasNext()) { |
Commentaire commentaireASupprimer = it.next(); |
Debug.log(commentaireASupprimer.getId()); |
grille.getStore().remove(commentaireASupprimer); |
} |
layout(true); |
*/ |
mediateur.clicMenu(MenuApplicationId.COMMENTAIRE); |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/commentaire/CommentaireListeVue.java:r1136-1368 |
/branches/v1.1-aramon/src/org/tela_botanica/client/vues/commentaire/CommentaireDetailVue.java |
---|
New file |
0,0 → 1,160 |
package org.tela_botanica.client.vues.commentaire; |
import org.tela_botanica.client.ComposantClass; |
import org.tela_botanica.client.ComposantId; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.ValeurListe; |
import org.tela_botanica.client.modeles.commentaire.Commentaire; |
import org.tela_botanica.client.modeles.projet.ProjetListe; |
import org.tela_botanica.client.vues.DetailVue; |
import com.extjs.gxt.ui.client.Style.Scroll; |
import com.extjs.gxt.ui.client.util.Format; |
import com.extjs.gxt.ui.client.util.Params; |
import com.extjs.gxt.ui.client.widget.ContentPanel; |
import com.extjs.gxt.ui.client.widget.Html; |
import com.extjs.gxt.ui.client.widget.layout.FitLayout; |
import com.google.gwt.core.client.GWT; |
public class CommentaireDetailVue extends DetailVue implements Rafraichissable { |
private String enteteTpl = null; |
private String contenuTpl = null; |
private ContentPanel panneauPrincipal = null; |
private Html entete = null; |
private Html contenu = null; |
private Commentaire commentaire = null; |
private boolean commentaireChargementOk = false; |
public CommentaireDetailVue(Mediateur mediateurCourant) { |
super(mediateurCourant); |
initialiserTousLesTpl(); |
chargerOntologie(); |
panneauPrincipal = new ContentPanel(); |
panneauPrincipal.setLayout(new FitLayout()); |
panneauPrincipal.setHeaderVisible(false); |
panneauPrincipal.setBodyBorder(false); |
panneauPrincipal.setScrollMode(Scroll.AUTO); |
entete = new Html(); |
entete.setId(ComposantId.ZONE_DETAIL_ENTETE); |
panneauPrincipal.setTopComponent(entete); |
contenu = new Html(); |
panneauPrincipal.add(contenu); |
add(panneauPrincipal); |
} |
private void initialiserTousLesTpl() { |
initialiserEnteteHtmlTpl(); |
initialiserGeneralTpl(); |
} |
private void initialiserEnteteHtmlTpl() { |
enteteTpl = |
"<div id='{css_id}'>"+ |
" <h1>{titre}</h1>"+ |
" <h2>{collection}<span class='{css_meta}'>{projet} <br /> {i18n_id}:{id} - {guid}</span></h2>" + |
"</div>"; |
} |
private void initialiserGeneralTpl() { |
contenuTpl = |
"<div class='{css_corps}'>"+ |
" <span class='{css_label}'>{i18n_type} :</span> {type}<br />"+ |
" <span class='{css_label}'>{i18n_public} :</span> {public}<br />"+ |
" <span class='{css_label}'>{i18n_ponderation} :</span> {ponderation}<br />"+ |
" <span class='{css_label}'>{i18n_texte} :</span>"+ |
" {texte}"+ |
"</div>"; |
} |
private void chargerOntologie() { |
String[] listesCodes = {"typeCommentaireCollection"}; |
lancerChargementListesValeurs(listesCodes); |
} |
public void afficherDetail() { |
if (commentaire != null) { |
afficherEntete(); |
afficherDetailCommentaire(); |
} |
layout(); |
} |
private void afficherEntete() { |
Params enteteParams = new Params(); |
enteteParams.set("css_id", ComposantId.ZONE_DETAIL_ENTETE); |
enteteParams.set("css_meta", ComposantClass.META); |
enteteParams.set("i18n_id", i18nC.id()); |
enteteParams.set("collection", commentaire.getCollection().getNom()); |
enteteParams.set("titre", commentaire.getTitre()); |
enteteParams.set("id", commentaire.getId()); |
enteteParams.set("guid", getGuid()); |
enteteParams.set("projet", construireTxtProjet(commentaire.getIdProjet())); |
String eHtml = Format.substitute(enteteTpl, enteteParams); |
entete.getElement().setInnerHTML(eHtml); |
} |
public String getGuid() { |
String guid = "URN:tela-botanica.org:"; |
guid += "coel"+commentaire.getIdProjet()+":"; |
guid += "com"+commentaire.getId(); |
return guid; |
} |
public void afficherDetailCommentaire() { |
Params contenuParams = new Params(); |
contenuParams.set("i18n_type", i18nC.commentaireType()); |
contenuParams.set("i18n_public", i18nC.commentairePublic()); |
contenuParams.set("i18n_ponderation", i18nC.commentairePonderation()); |
contenuParams.set("i18n_texte", i18nC.commentaireTexte()); |
String type = construireTxtListeOntologie(commentaire.getCollectionACommentaire().getType()); |
contenuParams.set("type", type); |
contenuParams.set("ponderation", commentaire.getPonderation()); |
contenuParams.set("public", (commentaire.etrePublic() ? "public" : "privé")); |
contenuParams.set("texte", commentaire.getTexte()); |
String gHtml = formaterContenu(contenuTpl, contenuParams); |
contenu.getElement().setInnerHTML(gHtml); |
} |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof Commentaire) { |
commentaire = (Commentaire) nouvellesDonnees; |
commentaireChargementOk = true; |
} else if (nouvellesDonnees instanceof ProjetListe) { |
projets = (ProjetListe) nouvellesDonnees; |
projetsChargementOk = true; |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe listeValeursReceptionnee = (ValeurListe) nouvellesDonnees; |
receptionerListeValeurs(listeValeursReceptionnee); |
} else { |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null); |
} |
if (avoirDonneesChargees()) { |
afficherDetail(); |
} |
} |
private boolean avoirDonneesChargees() { |
boolean ok = false; |
if (projetsChargementOk && commentaireChargementOk) { |
ok = true; |
} |
return ok; |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/commentaire/CommentaireDetailVue.java:r1136-1368 |
/branches/v1.1-aramon/src/org/tela_botanica/client/vues/commentaire/CommentaireForm.java |
---|
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 |
/branches/v1.1-aramon/src/org/tela_botanica/client/vues/commentaire/. |
---|
New file |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/commentaire:r1136-1291 |