Subversion Repositories eFlore/Applications.coel

Rev

Rev 556 | Rev 565 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
60 jpm 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.ArrayList;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.RegistreId;
422 jp_milcent 8
import org.tela_botanica.client.i18n.Constantes;
521 gduche 9
import org.tela_botanica.client.images.Images;
60 jpm 10
import org.tela_botanica.client.interfaces.Rafraichissable;
133 jpm 11
import org.tela_botanica.client.modeles.Information;
60 jpm 12
import org.tela_botanica.client.modeles.Structure;
69 jpm 13
import org.tela_botanica.client.modeles.StructureListe;
156 jp_milcent 14
import org.tela_botanica.client.modeles.Utilisateur;
60 jpm 15
 
16
import com.extjs.gxt.ui.client.Registry;
210 jp_milcent 17
import com.extjs.gxt.ui.client.Style.SortDir;
490 gduche 18
import com.extjs.gxt.ui.client.event.ButtonEvent;
60 jpm 19
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
20
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 21
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 22
import com.extjs.gxt.ui.client.store.ListStore;
23
import com.extjs.gxt.ui.client.widget.ContentPanel;
133 jpm 24
import com.extjs.gxt.ui.client.widget.Info;
490 gduche 25
import com.extjs.gxt.ui.client.widget.button.Button;
521 gduche 26
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
27
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
28
import com.extjs.gxt.ui.client.widget.grid.Grid;
29
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
60 jpm 30
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
31
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 32
import com.google.gwt.core.client.GWT;
60 jpm 33
 
442 jp_milcent 34
public class StructureListeVue extends ContentPanel implements Rafraichissable {
60 jpm 35
 
553 jp_milcent 36
	private Mediateur mediateur = null;
37
	private Constantes i18nC = null;
448 jp_milcent 38
 
521 gduche 39
	private Grid<Structure> grille = null;
60 jpm 40
	private ListStore<Structure> store = null;
521 gduche 41
 
490 gduche 42
	private Button modifier;
43
	private Button supprimer;
44
	private Button ajouter;
60 jpm 45
 
442 jp_milcent 46
	public StructureListeVue(Mediateur mediateurCourant) {
373 jp_milcent 47
		mediateur = mediateurCourant;
422 jp_milcent 48
		i18nC = mediateur.i18nC;
373 jp_milcent 49
 
553 jp_milcent 50
		setHeading(i18nC.titreStructureListe());
551 jp_milcent 51
		setLayout(new FitLayout());
60 jpm 52
 
53
		ToolBar toolBar = new ToolBar();
490 gduche 54
		ajouter = new Button(i18nC.ajouter());
521 gduche 55
		ajouter.setIcon(Images.ICONES.ajouter());
490 gduche 56
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
57
			public void componentSelected(ButtonEvent ce) {
156 jp_milcent 58
				mediateur.clicAjouterStructure();
133 jpm 59
			}
69 jpm 60
		});
60 jpm 61
		toolBar.add(ajouter);
62
 
490 gduche 63
		modifier = new Button(i18nC.modifier());
521 gduche 64
		modifier.setIcon(Images.ICONES.formModifier());
490 gduche 65
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
66
			public void componentSelected(ButtonEvent ce) {
521 gduche 67
				mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
156 jp_milcent 68
			}
69
		});
60 jpm 70
		toolBar.add(modifier);
71
 
490 gduche 72
		supprimer = new Button(i18nC.supprimer());
521 gduche 73
		supprimer.setIcon(Images.ICONES.supprimer());
490 gduche 74
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
75
			public void componentSelected(ButtonEvent ce) {
521 gduche 76
				clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
133 jpm 77
			}
78
		});
60 jpm 79
		toolBar.add(supprimer);
80
 
81
		setTopComponent(toolBar);
82
 
559 jp_milcent 83
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
84
		colonnes.add(new ColumnConfig("ville", "Ville", 150));
85
		colonnes.add(new ColumnConfig("nom", "Nom", 450));
86
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
521 gduche 87
 
559 jp_milcent 88
		GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
89
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
60 jpm 90
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
559 jp_milcent 91
				Structure structureSelectionnee = (Structure) event.getSelectedItem();
92
				clicListe(structureSelectionnee);
60 jpm 93
			}
94
		});
521 gduche 95
 
551 jp_milcent 96
		store = new ListStore<Structure>();
97
		store.sort("ville", SortDir.ASC);
98
 
559 jp_milcent 99
		grille = new Grid<Structure>(store, modeleDeColonne);
551 jp_milcent 100
		grille.setWidth("100%");
101
		grille.setAutoExpandColumn("nom");
559 jp_milcent 102
		grille.setSelectionModel(modeleDeSelection);
521 gduche 103
		add(grille);
60 jpm 104
	}
105
 
379 jp_milcent 106
	private void clicListe(Structure structure) {
107
		if (store.getCount() > 0) {
108
			mediateur.clicListeStructure(structure);
109
		}
60 jpm 110
	}
448 jp_milcent 111
 
112
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
113
		if (store.getCount() > 0) {
114
			mediateur.clicSupprimerStructure(this, structuresASupprimer);
115
		}
116
	}
60 jpm 117
 
551 jp_milcent 118
	private void gererEtatActivationBouton() {
119
		int nbreElementDuMagazin = store.getCount();
120
		if (nbreElementDuMagazin == 0) {
121
			supprimer.disable();
122
			modifier.disable();
123
		} else if (nbreElementDuMagazin > 0) {
124
			modifier.enable();
125
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
126
				supprimer.enable();
127
			}
128
		}
129
	}
130
 
60 jpm 131
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 132
		if (nouvelleDonnees instanceof StructureListe) {
379 jp_milcent 133
			StructureListe structures = (StructureListe) nouvelleDonnees;
60 jpm 134
 
556 jp_milcent 135
			if (structures != null) {
136
				List<Structure> liste = (List<Structure>) structures.toList();
137
				store.removeAll();
138
				store.add(liste);
139
 
140
				gererEtatActivationBouton();
141
 
142
				if (store.getCount() > 0) {
143
					grille.getSelectionModel().select(0, false);
144
				}
145
				mediateur.actualiserPanneauCentral();
60 jpm 146
			}
133 jpm 147
		} else if (nouvelleDonnees instanceof Information) {
148
			Information info = (Information) nouvelleDonnees;
149
			if (info.getType().equals("suppression_structure")) {
155 jpm 150
				// Affichage d'un message d'information
151
				//GWT.log(info.toString(), null);
422 jp_milcent 152
				Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
155 jpm 153
 
154
				// Suppression des structures sélectionnées
559 jp_milcent 155
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
155 jpm 156
				final int taille = selectionStructure.size();
157
				for (int i = 0; i < taille; i++) {
158
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
521 gduche 159
					store.remove(selectionStructure.get(i));
155 jpm 160
				}
161
 
551 jp_milcent 162
				gererEtatActivationBouton();
156 jp_milcent 163
			} else if (info.getType().equals("maj_utilisateur")) {
551 jp_milcent 164
				gererEtatActivationBouton();
133 jpm 165
			}
156 jp_milcent 166
		} else {
278 jp_milcent 167
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
60 jpm 168
		}
156 jp_milcent 169
		layout();
60 jpm 170
	}
171
}