Subversion Repositories eFlore/Applications.coel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1942 → Rev 1943

/branches/v1.11-okuzgozu/src/org/tela_botanica/client/vues/structure/StructureListeVue.java
New file
0,0 → 1,247
package org.tela_botanica.client.vues.structure;
 
import java.util.ArrayList;
import java.util.List;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.composants.ChampFiltreRecherche;
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.Utilisateur;
import org.tela_botanica.client.modeles.personne.Personne;
import org.tela_botanica.client.modeles.personne.PersonneAsyncDao;
import org.tela_botanica.client.modeles.publication.Publication;
import org.tela_botanica.client.modeles.publication.PublicationListe;
import org.tela_botanica.client.modeles.structure.Structure;
import org.tela_botanica.client.modeles.structure.StructureAsyncDao;
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.GridEvent;
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.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;
import com.google.gwt.user.client.Window;
 
public class StructureListeVue extends ContentPanel implements Rafraichissable {
private Mediateur mediateur = null;
private Constantes i18nC = null;
 
private Grid<Structure> grille = null;
private ListStore<Structure> store = null;
private Button modifier;
private Button supprimer;
private Button ajouter;
private ChampFiltreRecherche champFiltreRecherche = null;
private BarrePaginationVue pagination = null;
private int indexElementSelectionne = 0;
private Structure structureSelectionnee = null;
 
public StructureListeVue(Mediateur mediateurCourant) {
mediateur = mediateurCourant;
i18nC = mediateur.i18nC;
setHeaderVisible(false);
setLayout(new FitLayout());
ToolBar toolBar = new ToolBar();
ajouter = new Button(i18nC.ajouter());
ajouter.setIcon(Images.ICONES.ajouter());
ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
mediateur.clicAjouterStructure();
}
});
ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.structureSingulier());
toolBar.add(ajouter);
 
modifier = new Button(i18nC.modifier());
modifier.setIcon(Images.ICONES.formModifier());
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
}
});
modifier.setToolTip(i18nC.indicationModifierUneFiche());
toolBar.add(modifier);
supprimer = new Button(i18nC.supprimer());
supprimer.setIcon(Images.ICONES.supprimer());
supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
public void componentSelected(ButtonEvent ce) {
clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
}
});
supprimer.setToolTip(i18nC.indicationSupprimerUneFiche());
toolBar.add(supprimer);
 
setTopComponent(toolBar);
 
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
colonnes.add(new ColumnConfig("ville", "Ville", 150));
colonnes.add(new ColumnConfig("nom", "Nom", 450));
ColumnModel modeleDeColonne = new ColumnModel(colonnes);
GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
public void selectionChanged(SelectionChangedEvent<Structure> event) {
if((Structure) event.getSelectedItem() != null) {
structureSelectionnee = (Structure) event.getSelectedItem();
indexElementSelectionne = store.indexOf(structureSelectionnee);
clicListe(structureSelectionnee);
}
}
});
store = new ListStore<Structure>();
 
grille = new Grid<Structure>(store, modeleDeColonne);
grille.setWidth("100%");
grille.setAutoExpandColumn("nom");
grille.getView().setAutoFill(true);
grille.getView().setForceFit(true);
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);
}
});
grille.addListener(Events.SortChange, new Listener<BaseEvent>() {
 
@Override
public void handleEvent(BaseEvent be) {
GridEvent ge = (GridEvent<Structure>) be;
// TODO rajouter un test sur le sort state pour trier par nom par défaut
String tri = ge.getSortInfo().getSortField();
StructureAsyncDao.tri = Structure.PREFIXE+"_"+tri+" "+ge.getSortInfo().getSortDir().toString();
pagination.changePage();
}
});
add(grille);
StructureListe structureListe = new StructureListe();
champFiltreRecherche = new ChampFiltreRecherche(mediateurCourant, toolBar, structureListe);
// Définition de la barre de pagination
pagination = new BarrePaginationVue(structureListe, mediateur, champFiltreRecherche);
setBottomComponent(pagination);
}
 
private void clicListe(Structure structure) {
if (structure != null && store.getCount() > 0) {
mediateur.clicListeStructure(structure);
}
}
private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
mediateur.clicSupprimerStructure(this, structuresASupprimer);
}
 
private void gererEtatActivationBouton() {
int nbreElementDuMagazin = store.getCount();
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 StructureListe) {
StructureListe structures = (StructureListe) nouvellesDonnees;
champFiltreRecherche.setListePaginable(structures);
pagination.setlistePaginable(structures);
pagination.rafraichir(structures.getPageTable());
if (structures != null) {
List<Structure> liste = structures.toList();
store.removeAll();
store.add(liste);
 
gererEtatActivationBouton();
mediateur.actualiserPanneauCentral();
grille.fireEvent(Events.ViewReady);
}
} else if (nouvellesDonnees instanceof Information) {
Information info = (Information) nouvellesDonnees;
if (info.getType().equals("suppression_structure")) {
// Affichage d'un message d'information
InfoLogger.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
if (info.toString().replaceAll("\n", "").equals("OK")) {
mediateur.supprimerStructureAPersonne(this, selectionStructure);
}
// Suppression des structures sélectionnées de la grille
final int taille = selectionStructure.size();
for (int i = 0; i < taille; i++) {
store.remove(selectionStructure.get(i));
}
gererEtatActivationBouton();
} else if(info.getType().equals("structure_modifiee")) {
Structure structureModifiee = (Structure)info.getDonnee(0);
if(structureSelectionnee != null && structureModifiee != null) {
if(structureSelectionnee.getId().equals(structureModifiee.getId())) {
store.remove(indexElementSelectionne);
} else {
structureSelectionnee = null;
}
// au cas ou le bouton appliquer aurait été cliqué avant de valider
store.remove(structureModifiee);
store.insert(structureModifiee, indexElementSelectionne);
structureSelectionnee = structureModifiee;
int indexElementSelectionne = store.indexOf(structureSelectionnee);
grille.getSelectionModel().select(indexElementSelectionne, false);
grille.getView().focusRow(indexElementSelectionne);
clicListe(structureSelectionnee);
}
} else if (info.getType().equals("maj_utilisateur")) {
gererEtatActivationBouton();
} else if (info.getType().equals("suppression_structure_a_personne")) {
// Affichage d'un message d'information
InfoLogger.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
}
} else {
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
}
layout();
}
}
Property changes:
Added: svn:mergeinfo
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/structure/StructureListeVue.java:r1136-1368
Merged /trunk/src/org/tela_botanica/client/vues/structure/StructureListeVue.java:r11-934,1209-1382
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/vues/structure/StructureListeVue.java:r1383-1511