Subversion Repositories eFlore/Applications.coel

Rev

Rev 919 | Rev 935 | 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;
923 jpm 15
import org.tela_botanica.client.util.Debug;
60 jpm 16
 
17
import com.extjs.gxt.ui.client.Registry;
210 jp_milcent 18
import com.extjs.gxt.ui.client.Style.SortDir;
566 jp_milcent 19
import com.extjs.gxt.ui.client.event.BaseEvent;
490 gduche 20
import com.extjs.gxt.ui.client.event.ButtonEvent;
566 jp_milcent 21
import com.extjs.gxt.ui.client.event.Events;
22
import com.extjs.gxt.ui.client.event.Listener;
60 jpm 23
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
24
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 25
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 26
import com.extjs.gxt.ui.client.store.ListStore;
27
import com.extjs.gxt.ui.client.widget.ContentPanel;
133 jpm 28
import com.extjs.gxt.ui.client.widget.Info;
490 gduche 29
import com.extjs.gxt.ui.client.widget.button.Button;
521 gduche 30
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
31
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
32
import com.extjs.gxt.ui.client.widget.grid.Grid;
33
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
60 jpm 34
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
35
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 36
import com.google.gwt.core.client.GWT;
60 jpm 37
 
442 jp_milcent 38
public class StructureListeVue extends ContentPanel implements Rafraichissable {
60 jpm 39
 
553 jp_milcent 40
	private Mediateur mediateur = null;
41
	private Constantes i18nC = null;
448 jp_milcent 42
 
521 gduche 43
	private Grid<Structure> grille = null;
60 jpm 44
	private ListStore<Structure> store = null;
521 gduche 45
 
490 gduche 46
	private Button modifier;
47
	private Button supprimer;
48
	private Button ajouter;
60 jpm 49
 
442 jp_milcent 50
	public StructureListeVue(Mediateur mediateurCourant) {
373 jp_milcent 51
		mediateur = mediateurCourant;
422 jp_milcent 52
		i18nC = mediateur.i18nC;
373 jp_milcent 53
 
553 jp_milcent 54
		setHeading(i18nC.titreStructureListe());
551 jp_milcent 55
		setLayout(new FitLayout());
60 jpm 56
 
57
		ToolBar toolBar = new ToolBar();
490 gduche 58
		ajouter = new Button(i18nC.ajouter());
521 gduche 59
		ajouter.setIcon(Images.ICONES.ajouter());
490 gduche 60
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
61
			public void componentSelected(ButtonEvent ce) {
156 jp_milcent 62
				mediateur.clicAjouterStructure();
133 jpm 63
			}
69 jpm 64
		});
60 jpm 65
		toolBar.add(ajouter);
66
 
490 gduche 67
		modifier = new Button(i18nC.modifier());
521 gduche 68
		modifier.setIcon(Images.ICONES.formModifier());
490 gduche 69
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
70
			public void componentSelected(ButtonEvent ce) {
521 gduche 71
				mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
156 jp_milcent 72
			}
73
		});
60 jpm 74
		toolBar.add(modifier);
75
 
490 gduche 76
		supprimer = new Button(i18nC.supprimer());
521 gduche 77
		supprimer.setIcon(Images.ICONES.supprimer());
490 gduche 78
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
79
			public void componentSelected(ButtonEvent ce) {
521 gduche 80
				clicSupprimerStructure(grille.getSelectionModel().getSelectedItems());
133 jpm 81
			}
82
		});
60 jpm 83
		toolBar.add(supprimer);
84
 
85
		setTopComponent(toolBar);
86
 
559 jp_milcent 87
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
88
		colonnes.add(new ColumnConfig("ville", "Ville", 150));
89
		colonnes.add(new ColumnConfig("nom", "Nom", 450));
90
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
521 gduche 91
 
559 jp_milcent 92
		GridSelectionModel<Structure> modeleDeSelection = new GridSelectionModel<Structure>();
93
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
60 jpm 94
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
559 jp_milcent 95
				Structure structureSelectionnee = (Structure) event.getSelectedItem();
96
				clicListe(structureSelectionnee);
60 jpm 97
			}
98
		});
521 gduche 99
 
551 jp_milcent 100
		store = new ListStore<Structure>();
101
		store.sort("ville", SortDir.ASC);
102
 
559 jp_milcent 103
		grille = new Grid<Structure>(store, modeleDeColonne);
551 jp_milcent 104
		grille.setWidth("100%");
105
		grille.setAutoExpandColumn("nom");
565 jp_milcent 106
		grille.getView().setAutoFill(true);
107
		grille.getView().setForceFit(true);
559 jp_milcent 108
		grille.setSelectionModel(modeleDeSelection);
566 jp_milcent 109
		grille.addListener(Events.ViewReady, new Listener<BaseEvent>() {
110
			@Override
111
			public void handleEvent(BaseEvent be) {
112
				grille.getSelectionModel().select(0, false);
113
			}
114
		});
671 jp_milcent 115
		grille.addListener(Events.OnDoubleClick, new Listener<BaseEvent>() {
116
			@Override
117
			public void handleEvent(BaseEvent be) {
118
				modifier.fireEvent(Events.Select);
119
			}
120
		});
521 gduche 121
		add(grille);
60 jpm 122
	}
123
 
379 jp_milcent 124
	private void clicListe(Structure structure) {
865 jpm 125
		if (structure != null && store.getCount() > 0) {
126
			mediateur.clicListeStructure(structure);
127
		}
60 jpm 128
	}
448 jp_milcent 129
 
130
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
609 jp_milcent 131
		mediateur.clicSupprimerStructure(this, structuresASupprimer);
448 jp_milcent 132
	}
60 jpm 133
 
551 jp_milcent 134
	private void gererEtatActivationBouton() {
135
		int nbreElementDuMagazin = store.getCount();
136
		if (nbreElementDuMagazin == 0) {
137
			supprimer.disable();
138
			modifier.disable();
139
		} else if (nbreElementDuMagazin > 0) {
140
			modifier.enable();
141
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
142
				supprimer.enable();
143
			}
144
		}
145
	}
146
 
635 jp_milcent 147
	public void rafraichir(Object nouvellesDonnees) {
148
		if (nouvellesDonnees instanceof StructureListe) {
149
			StructureListe structures = (StructureListe) nouvellesDonnees;
60 jpm 150
 
556 jp_milcent 151
			if (structures != null) {
685 jp_milcent 152
				List<Structure> liste = structures.toList();
556 jp_milcent 153
				store.removeAll();
154
				store.add(liste);
609 jp_milcent 155
 
556 jp_milcent 156
				gererEtatActivationBouton();
157
 
158
				mediateur.actualiserPanneauCentral();
60 jpm 159
			}
635 jp_milcent 160
		} else if (nouvellesDonnees instanceof Information) {
161
			Information info = (Information) nouvellesDonnees;
133 jpm 162
			if (info.getType().equals("suppression_structure")) {
155 jpm 163
				// Affichage d'un message d'information
422 jp_milcent 164
				Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
923 jpm 165
 
166
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();
167
 
168
				if (info.toString().replaceAll("\n", "").equals("OK")) {
169
					mediateur.supprimerStructureAPersonne(this, selectionStructure);
170
				}
171
 
609 jp_milcent 172
				// Suppression des structures sélectionnées de la grille
155 jpm 173
				final int taille = selectionStructure.size();
174
				for (int i = 0; i < taille; i++) {
521 gduche 175
					store.remove(selectionStructure.get(i));
155 jpm 176
				}
177
 
551 jp_milcent 178
				gererEtatActivationBouton();
156 jp_milcent 179
			} else if (info.getType().equals("maj_utilisateur")) {
551 jp_milcent 180
				gererEtatActivationBouton();
923 jpm 181
			} else if (info.getType().equals("suppression_structure_a_personne")) {
182
				// Affichage d'un message d'information
183
				Info.display(i18nC.suppressionStructureAPersonne(), info.toString().replaceAll("\n", "<br />"));
133 jpm 184
			}
156 jp_milcent 185
		} else {
635 jp_milcent 186
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
60 jpm 187
		}
156 jp_milcent 188
		layout();
60 jpm 189
	}
190
}