Subversion Repositories eFlore/Applications.coel

Rev

Rev 521 | Rev 553 | 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
 
373 jp_milcent 36
	private Mediateur mediateur = null ;
422 jp_milcent 37
	private Constantes i18nC = null ;
448 jp_milcent 38
 
521 gduche 39
	//private Table table = null;
40
	private Grid<Structure> grille = null;
60 jpm 41
	private ListStore<Structure> store = null;
521 gduche 42
 
490 gduche 43
	private Button modifier;
44
	private Button supprimer;
45
	private Button ajouter;
60 jpm 46
 
442 jp_milcent 47
	public StructureListeVue(Mediateur mediateurCourant) {
373 jp_milcent 48
		mediateur = mediateurCourant;
422 jp_milcent 49
		i18nC = mediateur.i18nC;
373 jp_milcent 50
 
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
 
521 gduche 83
		List<ColumnConfig> lstColumns = new ArrayList<ColumnConfig>();
60 jpm 84
 
521 gduche 85
		ColumnConfig ccVille = new ColumnConfig();
86
		ccVille.setId("ville");
87
		ccVille.setHeader("Ville");
551 jp_milcent 88
		ccVille.setWidth(150);
521 gduche 89
		lstColumns.add(ccVille);
210 jp_milcent 90
 
521 gduche 91
		ColumnConfig ccNom = new ColumnConfig();
92
		ccNom.setId("nom");
93
		ccNom.setHeader("Nom");
551 jp_milcent 94
		ccNom.setWidth(450);
521 gduche 95
		lstColumns.add(ccNom);
96
 
97
		ColumnModel cmStructure = new ColumnModel(lstColumns);
98
 
99
		GridSelectionModel<Structure> gsmSelectionStructure = new GridSelectionModel<Structure>();
100
		gsmSelectionStructure.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
60 jpm 101
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
102
				Structure m = (Structure) event.getSelectedItem();
103
				clicListe(m);
104
			}
105
		});
521 gduche 106
 
551 jp_milcent 107
		store = new ListStore<Structure>();
108
		store.sort("ville", SortDir.ASC);
109
 
110
		grille = new Grid<Structure>(store, cmStructure);
111
		grille.setWidth("100%");
112
		grille.setAutoExpandColumn("nom");
521 gduche 113
		grille.setSelectionModel(gsmSelectionStructure);
114
		add(grille);
60 jpm 115
	}
116
 
379 jp_milcent 117
	private void clicListe(Structure structure) {
118
		if (store.getCount() > 0) {
119
			mediateur.clicListeStructure(structure);
120
		}
60 jpm 121
	}
448 jp_milcent 122
 
123
	private void clicSupprimerStructure(List<Structure> structuresASupprimer) {
124
		if (store.getCount() > 0) {
125
			mediateur.clicSupprimerStructure(this, structuresASupprimer);
126
		}
127
	}
60 jpm 128
 
551 jp_milcent 129
	private void gererEtatActivationBouton() {
130
		int nbreElementDuMagazin = store.getCount();
131
		if (nbreElementDuMagazin == 0) {
132
			supprimer.disable();
133
			modifier.disable();
134
		} else if (nbreElementDuMagazin > 0) {
135
			modifier.enable();
136
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
137
				supprimer.enable();
138
			}
139
		}
140
	}
141
 
60 jpm 142
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 143
		if (nouvelleDonnees instanceof StructureListe) {
379 jp_milcent 144
			StructureListe structures = (StructureListe) nouvelleDonnees;
422 jp_milcent 145
			setHeading(i18nC.titreStructureListe());
60 jpm 146
 
379 jp_milcent 147
			List<Structure> liste = (List<Structure>) structures.toList();
60 jpm 148
			store.removeAll();
368 jp_milcent 149
			store.add(liste);
278 jp_milcent 150
 
551 jp_milcent 151
			gererEtatActivationBouton();
379 jp_milcent 152
 
153
			if (store.getCount() > 0) {
551 jp_milcent 154
				grille.getSelectionModel().select(0, false);
60 jpm 155
			}
551 jp_milcent 156
			mediateur.actualiserPanneauCentral();
157
 
133 jpm 158
		} else if (nouvelleDonnees instanceof Information) {
159
			Information info = (Information) nouvelleDonnees;
160
			if (info.getType().equals("suppression_structure")) {
155 jpm 161
				// Affichage d'un message d'information
162
				//GWT.log(info.toString(), null);
422 jp_milcent 163
				Info.display(i18nC.suppressionStructure(), info.toString().replaceAll("\n", "<br />"));
155 jpm 164
 
165
				// Suppression des structures sélectionnées
521 gduche 166
				List<Structure> selectionStructure = grille.getSelectionModel().getSelectedItems();//table.getSelectedItems();
155 jpm 167
				final int taille = selectionStructure.size();
168
				for (int i = 0; i < taille; i++) {
169
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
521 gduche 170
					store.remove(selectionStructure.get(i));
155 jpm 171
				}
172
 
551 jp_milcent 173
				gererEtatActivationBouton();
156 jp_milcent 174
			} else if (info.getType().equals("maj_utilisateur")) {
551 jp_milcent 175
				gererEtatActivationBouton();
133 jpm 176
			}
156 jp_milcent 177
		} else {
278 jp_milcent 178
			GWT.log("Pas de correspondance dans la méthode rafraichir() de la classe "+this.getClass(), null);
60 jpm 179
		}
156 jp_milcent 180
		layout();
60 jpm 181
	}
182
}