New file |
0,0 → 1,252 |
package org.tela_botanica.client.vues.collection; |
|
import java.util.ArrayList; |
import java.util.Iterator; |
import java.util.List; |
|
import org.tela_botanica.client.Coel; |
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.collection.Collection; |
import org.tela_botanica.client.modeles.collection.CollectionAsyncDao; |
import org.tela_botanica.client.modeles.collection.CollectionListe; |
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.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.user.client.Window; |
|
public class CollectionListeVue extends ContentPanel implements Rafraichissable { |
|
private Mediateur mediateur = null; |
private Constantes i18nC = null; |
|
private Grid<Collection> grille = null; |
private ListStore<Collection> store = null; |
|
private Button modifier; |
private Button supprimer; |
private Button ajouter; |
private BarrePaginationVue pagination = null; |
private ChampFiltreRecherche champFiltreRecherche = null; |
|
private int indexElementSelectionne = 0; |
private Collection collectionSelectionnee = null; |
|
public CollectionListeVue(Mediateur mediateurCourant) { |
mediateur = mediateurCourant; |
i18nC = Mediateur.i18nC; |
|
setLayout(new FitLayout()); |
setHeaderVisible(false); |
|
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.clicAjouterCollection(); |
} |
}); |
ajouter.setToolTip(i18nC.indicationCreerUneFiche()+" "+i18nC.collectionSingulier()); |
toolBar.add(ajouter); |
|
modifier = new Button(i18nC.modifier()); |
modifier.setIcon(Images.ICONES.formModifier()); |
modifier.addSelectionListener(new SelectionListener<ButtonEvent>() { |
public void componentSelected(ButtonEvent ce) { |
mediateur.clicModifierCollection(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) { |
clicSupprimerCollection(grille.getSelectionModel().getSelectedItems()); |
} |
}); |
supprimer.setToolTip(i18nC.indicationSupprimerUneFiche()); |
toolBar.add(supprimer); |
|
setTopComponent(toolBar); |
|
List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>(); |
colonnes.add(new ColumnConfig("nom", i18nC.personneNom(), 300)); |
colonnes.add(new ColumnConfig("_structure_nom_", i18nC.structure(), 200)); |
colonnes.add(new ColumnConfig("_structure_ville_", i18nC.ville(), 150)); |
colonnes.get(1).setHidden(true); |
ColumnModel modeleDeColonne = new ColumnModel(colonnes); |
|
GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>(); |
modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() { |
public void selectionChanged(SelectionChangedEvent<Collection> event) { |
collectionSelectionnee = (Collection) event.getSelectedItem(); |
indexElementSelectionne = store.indexOf(collectionSelectionnee); |
clicListe(collectionSelectionnee); |
} |
}); |
|
store = new ListStore<Collection>(); |
|
grille = new Grid<Collection>(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<Collection>) be; |
// TODO rajouter un test sur le sort state pour trier par nom par défaut |
String tri = ge.getSortInfo().getSortField(); |
if(tri.equals("_structure_ville_")) { |
tri = "cs_ville"; |
} else { |
tri = Collection.PREFIXE+"_"+tri; |
} |
CollectionAsyncDao.tri = tri+" "+ge.getSortInfo().getSortDir().toString(); |
pagination.changePage(); |
} |
}); |
add(grille); |
|
CollectionListe collectionListe = new CollectionListe(); |
champFiltreRecherche = new ChampFiltreRecherche(mediateur, toolBar, collectionListe); |
// Définition de la barre de pagination |
pagination = new BarrePaginationVue(collectionListe, mediateur, champFiltreRecherche); |
setBottomComponent(pagination); |
} |
|
private void clicListe(Collection collection) { |
if (collection != null && store.getCount() > 0) { |
mediateur.clicListeCollection(collection); |
} |
} |
|
private void clicSupprimerCollection(List<Collection> collectionsASupprimer) { |
if (store.getCount() > 0) { |
mediateur.clicSupprimerCollection(this, collectionsASupprimer); |
} |
} |
|
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 CollectionListe) { |
CollectionListe collections = (CollectionListe) nouvellesDonnees; |
|
pagination.setlistePaginable(collections); |
int[] pt = collections.getPageTable(); |
pagination.rafraichir(collections.getPageTable()); |
champFiltreRecherche.setListePaginable(collections); |
|
if (collections != null) { |
List<Collection> liste = collections.toList(); |
store.removeAll(); |
store.add(liste); |
|
mediateur.actualiserPanneauCentral(); |
} |
} else if (nouvellesDonnees instanceof Information) { |
Information info = (Information) nouvellesDonnees; |
if (info.getType().equals("maj_utilisateur")) { |
gererEtatActivationBouton(); |
} else if (info.getType().equals("modif_collection")) { |
// curieusement la suppression efface aussi l'index de l'élément |
// car elle redéclenche l'évenement de selection (on le stocke donc temporairement) |
int temporaire = indexElementSelectionne; |
if(collectionSelectionnee != null) { |
store.remove(collectionSelectionnee); |
collectionSelectionnee = null; |
} |
Collection collecModifiee = (Collection)info.getDonnee(0); |
// au cas ou le bouton appliquer aurait été cliqué avant de valider |
store.remove(collecModifiee); |
indexElementSelectionne = temporaire; |
store.insert(collecModifiee, temporaire); |
collectionSelectionnee = collecModifiee; |
int indexElementSelectionne = store.indexOf(collectionSelectionnee); |
grille.getSelectionModel().select(indexElementSelectionne, false); |
grille.getView().focusRow(indexElementSelectionne); |
clicListe(collectionSelectionnee); |
} else if (info.getType().equals("suppression_collection")) { |
// Affichage d'un message d'information |
InfoLogger.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />")); |
|
supprimerCollectionsSelectionnees(); |
|
gererEtatActivationBouton(); |
} |
} else { |
Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass())); |
} |
layout(); |
} |
|
private void supprimerCollectionsSelectionnees() { |
List<Collection> collectionsSelectionnees = grille.getSelectionModel().getSelectedItems(); |
Iterator<Collection> it = collectionsSelectionnees.iterator(); |
while (it.hasNext()) { |
grille.getStore().remove(it.next()); |
} |
layout(true); |
} |
} |
Property changes: |
Added: svn:mergeinfo |
Merged /branches/v1.0-syrah/src/org/tela_botanica/client/vues/collection/CollectionListeVue.java:r1136-1368 |
Merged /trunk/src/org/tela_botanica/client/vues/collection/CollectionListeVue.java:r11-933,1209-1382 |
Merged /branches/v1.1-aramon/src/org/tela_botanica/client/vues/collection/CollectionListeVue.java:r1383-1511 |