Subversion Repositories eFlore/Applications.coel

Rev

Rev 490 | Rev 551 | 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
 
69 jpm 6
import org.tela_botanica.client.ComposantClass;
60 jpm 7
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.RegistreId;
422 jp_milcent 9
import org.tela_botanica.client.i18n.Constantes;
521 gduche 10
import org.tela_botanica.client.images.Images;
60 jpm 11
import org.tela_botanica.client.interfaces.Rafraichissable;
133 jpm 12
import org.tela_botanica.client.modeles.Information;
60 jpm 13
import org.tela_botanica.client.modeles.Structure;
69 jpm 14
import org.tela_botanica.client.modeles.StructureListe;
156 jp_milcent 15
import org.tela_botanica.client.modeles.Utilisateur;
60 jpm 16
 
17
import com.extjs.gxt.ui.client.Registry;
18
import com.extjs.gxt.ui.client.Style.SelectionMode;
210 jp_milcent 19
import com.extjs.gxt.ui.client.Style.SortDir;
490 gduche 20
import com.extjs.gxt.ui.client.event.ButtonEvent;
69 jpm 21
import com.extjs.gxt.ui.client.event.ComponentEvent;
60 jpm 22
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
23
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 24
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 25
import com.extjs.gxt.ui.client.store.ListStore;
26
import com.extjs.gxt.ui.client.widget.ContentPanel;
133 jpm 27
import com.extjs.gxt.ui.client.widget.Info;
490 gduche 28
import com.extjs.gxt.ui.client.widget.button.Button;
521 gduche 29
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
30
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
31
import com.extjs.gxt.ui.client.widget.grid.Grid;
32
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
60 jpm 33
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
34
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
133 jpm 35
import com.google.gwt.core.client.GWT;
60 jpm 36
 
442 jp_milcent 37
public class StructureListeVue extends ContentPanel implements Rafraichissable {
60 jpm 38
 
373 jp_milcent 39
	private Mediateur mediateur = null ;
422 jp_milcent 40
	private Constantes i18nC = null ;
448 jp_milcent 41
 
521 gduche 42
	//private Table table = null;
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
 
277 jp_milcent 54
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT);
60 jpm 55
 
56
		ToolBar toolBar = new ToolBar();
490 gduche 57
		ajouter = new Button(i18nC.ajouter());
521 gduche 58
		ajouter.setIcon(Images.ICONES.ajouter());
490 gduche 59
		ajouter.addSelectionListener(new SelectionListener<ButtonEvent>() {
60
			public void componentSelected(ButtonEvent ce) {
156 jp_milcent 61
				mediateur.clicAjouterStructure();
133 jpm 62
			}
69 jpm 63
		});
60 jpm 64
		toolBar.add(ajouter);
65
 
490 gduche 66
		modifier = new Button(i18nC.modifier());
521 gduche 67
		modifier.setIcon(Images.ICONES.formModifier());
490 gduche 68
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
69
			public void componentSelected(ButtonEvent ce) {
521 gduche 70
				mediateur.clicModifierStructure(grille.getSelectionModel().getSelectedItems());
156 jp_milcent 71
			}
72
		});
521 gduche 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
		});
156 jp_milcent 83
		if (!utilisateur.isIdentifie()) {
84
			supprimer.disable();
85
		}
60 jpm 86
		toolBar.add(supprimer);
87
 
88
		setTopComponent(toolBar);
89
 
521 gduche 90
		List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
60 jpm 91
 
521 gduche 92
		ColumnConfig ccVille = new ColumnConfig();
93
		ccVille.setId("ville");
94
		ccVille.setHeader("Ville");
95
		ccVille.setWidth(300);
96
		lstColumns.add(ccVille);
210 jp_milcent 97
 
521 gduche 98
		ColumnConfig ccNom = new ColumnConfig();
99
		ccNom.setId("nom");
100
		ccNom.setHeader("Nom");
101
		ccNom.setWidth(300);
102
		lstColumns.add(ccNom);
103
 
104
		ColumnModel cmStructure = new ColumnModel(lstColumns);
105
 
60 jpm 106
		store = new ListStore<Structure>();
210 jp_milcent 107
		store.sort("ville", SortDir.ASC);
521 gduche 108
		grille = new Grid<Structure>(store, cmStructure);
109
 
110
		GridSelectionModel<Structure> gsmSelectionStructure = new GridSelectionModel<Structure>();
111
		gsmSelectionStructure.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
60 jpm 112
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
113
				Structure m = (Structure) event.getSelectedItem();
114
				clicListe(m);
115
			}
116
		});
521 gduche 117
 
118
		grille.setAutoExpandColumn("ville");
119
		grille.setSelectionModel(gsmSelectionStructure);
120
		add(grille);
60 jpm 121
		setLayout(new FitLayout());
122
	}
123
 
379 jp_milcent 124
	private void clicListe(Structure structure) {
125
		if (store.getCount() > 0) {
126
			mediateur.clicListeStructure(structure);
127
		}
60 jpm 128
	}
448 jp_milcent 129
 
130
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
131
		if (store.getCount() > 0) {
132
			mediateur.clicSupprimerStructure(this, structuresASupprimer);
133
		}
134
	}
60 jpm 135
 
136
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 137
		if (nouvelleDonnees instanceof StructureListe) {
379 jp_milcent 138
			StructureListe structures = (StructureListe) nouvelleDonnees;
422 jp_milcent 139
			setHeading(i18nC.titreStructureListe());
60 jpm 140
 
379 jp_milcent 141
			List<Structure> liste = (List<Structure>) structures.toList();
60 jpm 142
			store.removeAll();
368 jp_milcent 143
			store.add(liste);
278 jp_milcent 144
 
379 jp_milcent 145
			mediateur.actualiserPanneauCentral();
146
 
147
			if (store.getCount() > 0) {
490 gduche 148
				//TODO : check below:
521 gduche 149
				//table.getSelectionModel().select(0, 1, true);
150
				grille.getSelectionModel().select(0, true);
60 jpm 151
			}
133 jpm 152
		} else if (nouvelleDonnees instanceof Information) {
153
			Information info = (Information) nouvelleDonnees;
154
			if (info.getType().equals("suppression_structure")) {
155 jpm 155
				// Affichage d'un message d'information
156
				//GWT.log(info.toString(), null);
422 jp_milcent 157
				Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
155 jpm 158
 
159
				// Suppression des structures sélectionnées
521 gduche 160
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();//table.getSelectedItems();
155 jpm 161
				final int taille = selectionStructure.size();
162
				for (int i = 0; i < taille; i++) {
163
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
521 gduche 164
					//table.remove(selectionStructure.get(i));
165
					store.remove(selectionStructure.get(i));
155 jpm 166
				}
167
 
168
				// Désactivation des boutons si la liste est vide
521 gduche 169
 
170
				//TODO : taille de la grille??
171
				/*if (  == 0) {
155 jpm 172
					supprimer.disable();
173
					modifier.disable();
521 gduche 174
				}*/
156 jp_milcent 175
			} else if (info.getType().equals("maj_utilisateur")) {
521 gduche 176
				/*if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
177
					//TODO : taille de la grille??
156 jp_milcent 178
					if (table.getItemCount() != 0) {
179
						supprimer.enable();
180
					}
181
				} else {
182
					supprimer.disable();
521 gduche 183
				}*/
133 jpm 184
			}
156 jp_milcent 185
		} else {
278 jp_milcent 186
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
60 jpm 187
		}
156 jp_milcent 188
		layout();
60 jpm 189
	}
190
}