Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 934 → Rev 935

/trunk/src/org/tela_botanica/client/vues/projet/ProjetListeVue.java
New file
0,0 → 1,207
package org.tela_botanica.client.vues.projet;
 
import java.util.ArrayList;
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.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.Utilisateur;
import org.tela_botanica.client.modeles.projet.Projet;
import org.tela_botanica.client.modeles.projet.ProjetListe;
import org.tela_botanica.client.util.Debug;
 
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.ListStore;
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.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
import com.google.gwt.core.client.GWT;
 
public class ProjetListeVue extends ContentPanel implements Rafraichissable {
 
private Mediateur mediateur = null;
private Constantes i18nC = null;
 
private Grid<Projet> grille = null;
private ListStore<Projet> store = null;
private ColumnModel modeleDesColonnes = null;
 
private Button ajouter;
private Button modifier;
private Button supprimer;
public ProjetListeVue(Mediateur mediateurCourant) {
super();
mediateur = mediateurCourant;
i18nC = Mediateur.i18nC;
setLayout(new FitLayout());
setHeading("Projets");
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.clicAjouterProjet();
}
});
toolBar.add(ajouter);
 
modifier = new Button(i18nC.modifier());
modifier.setIcon(Images.ICONES.formModifier());
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent be) {
mediateur.clicModifierProjet(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.clicSupprimerProjet(grille.getSelectionModel().getSelectedItems());
}
});
toolBar.add(supprimer);
 
setTopComponent(toolBar);
 
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("id_projet", i18nC.id(), 20));
colonnes.add(new ColumnConfig("nom", i18nC.nom(), 200));
colonnes.add(new ColumnConfig("abreviation", i18nC.projetAbreviation(), 200));
colonnes.add(new ColumnConfig("resume", i18nC.projetResume(), 300));
colonnes.add(new ColumnConfig("url", i18nC.projetUrl(), 200));
colonnes.add(new ColumnConfig("mot_cles", i18nC.projetMotsCles(), 280));
 
modeleDesColonnes = new ColumnModel(colonnes);
 
GridSelectionModel<Projet> modeleDeSelection = new GridSelectionModel<Projet>();
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Projet>() {
public void selectionChanged(SelectionChangedEvent<Projet> event) {
Projet projet = (Projet) event.getSelectedItem();
clicListe(projet);
}
});
store = new ListStore<Projet>();
store.sort("id_projet", SortDir.ASC);
grille = new Grid<Projet>(store, modeleDesColonnes);
grille.setWidth("100%");
grille.setAutoExpandColumn("nom");
grille.getView().setAutoFill(true);
grille.getView().setForceFit(true);
grille.setSelectionModel(modeleDeSelection);
grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
grille.getSelectionModel().select(0, false);
}
});
grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>(){
@Override
public void handleEvent(BaseEvent be) {
modifier.fireEvent(Events.Select);
}
});
add(grille);
}
public ListStore<Projet> getStore() {
return store;
}
 
private void clicListe(Projet projet) {
mediateur.clicListeProjet(projet);
}
 
private void gererEtatActivationBouton() {
int nbreElementDuMagazin = store.getCount();
ajouter.enable();
if(!((Utilisateur)Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
supprimer.disable();
modifier.disable();
} else {
if (nbreElementDuMagazin <= 0) {
supprimer.disable();
modifier.disable();
} else {
supprimer.enable();
modifier.enable();
}
}
}
public void rafraichir(Object nouvellesDonnees) {
if (nouvellesDonnees instanceof ProjetListe) {
ProjetListe projets = (ProjetListe) nouvellesDonnees;
if (projets != null) {
List<Projet> projetsListe = projets.toList();
store.removeAll();
if (mediateur.getProjetId() != null) {
String projetIdSelectionne = mediateur.getProjetId();
Iterator<Projet> it = projetsListe.iterator();
while (it.hasNext()) {
Projet projetCourant = it.next();
if (projetCourant.getId().equals(projetIdSelectionne)) {
store.add(projetCourant);
}
}
} else {
store.add(projetsListe);
}
mediateur.actualiserPanneauCentral();
}
} else if (nouvellesDonnees instanceof Information) {
Information info = (Information) nouvellesDonnees;
if (info.getType().equals("maj_utilisateur")) {
gererEtatActivationBouton();
} else if (info.getType().equals("suppression_projet")) {
String message = info.toString();
if (info.getDonnee(0) != null) {
message = (String) info.getDonnee(0);
}
Info.display(i18nC.projetTitreSuppression(), message);
supprimerProjetsSelectionnees();
gererEtatActivationBouton();
}
} else {
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
}
}
 
public void supprimerProjetsSelectionnees() {
List<Projet> selPub = grille.getSelectionModel().getSelectedItems();
GWT.log("Le résultat dans supprimer est : "+grille.getSelectionModel().getSelection().size()+" ", null);
for(Iterator<Projet> it = selPub.iterator(); it.hasNext();) {
GWT.log("Le résultat dans rafraichir est : "+grille.getSelectionModel().getSelection().size()+" ", null);
grille.getStore().remove(it.next());
}
layout(true);
}
 
}