Subversion Repositories eFlore/Applications.coel

Rev

Rev 685 | Rev 865 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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