Subversion Repositories eFlore/Applications.coel

Rev

Rev 516 | Rev 565 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 516 Rev 558
Line 1... Line 1...
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
Line 2... Line 2...
2
 
2
 
3
import java.util.ArrayList;
3
import java.util.ArrayList;
Line 4... Line -...
4
import java.util.List;
-
 
5
 
4
import java.util.List;
6
import org.tela_botanica.client.ComposantClass;
5
 
7
import org.tela_botanica.client.Mediateur;
6
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.RegistreId;
7
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.i18n.Constantes;
8
import org.tela_botanica.client.i18n.Constantes;
Line 13... Line 12...
13
import org.tela_botanica.client.modeles.CollectionListe;
12
import org.tela_botanica.client.modeles.CollectionListe;
14
import org.tela_botanica.client.modeles.Information;
13
import org.tela_botanica.client.modeles.Information;
15
import org.tela_botanica.client.modeles.Utilisateur;
14
import org.tela_botanica.client.modeles.Utilisateur;
Line 16... Line 15...
16
 
15
 
17
import com.extjs.gxt.ui.client.Registry;
-
 
18
import com.extjs.gxt.ui.client.Style.SelectionMode;
16
import com.extjs.gxt.ui.client.Registry;
19
import com.extjs.gxt.ui.client.Style.SortDir;
-
 
20
import com.extjs.gxt.ui.client.binder.TableBinder;
17
import com.extjs.gxt.ui.client.Style.SortDir;
21
import com.extjs.gxt.ui.client.event.ButtonEvent;
-
 
22
import com.extjs.gxt.ui.client.event.ComponentEvent;
18
import com.extjs.gxt.ui.client.event.ButtonEvent;
23
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
19
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
24
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
20
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
25
import com.extjs.gxt.ui.client.event.SelectionListener;
21
import com.extjs.gxt.ui.client.event.SelectionListener;
26
import com.extjs.gxt.ui.client.store.ListStore;
22
import com.extjs.gxt.ui.client.store.ListStore;
27
import com.extjs.gxt.ui.client.widget.ContentPanel;
23
import com.extjs.gxt.ui.client.widget.ContentPanel;
28
import com.extjs.gxt.ui.client.widget.Info;
24
import com.extjs.gxt.ui.client.widget.Info;
-
 
25
import com.extjs.gxt.ui.client.widget.button.Button;
-
 
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.button.Button;
29
import com.extjs.gxt.ui.client.widget.grid.GridSelectionModel;
30
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
-
 
31
import com.extjs.gxt.ui.client.widget.table.Table;
-
 
32
import com.extjs.gxt.ui.client.widget.table.TableColumn;
-
 
33
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
-
 
34
import com.extjs.gxt.ui.client.widget.table.TableItem;
30
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
35
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
31
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
Line 36... Line 32...
36
import com.google.gwt.core.client.GWT;
32
import com.google.gwt.core.client.GWT;
Line 37... Line 33...
37
 
33
 
38
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
34
public class CollectionListeVue extends ContentPanel implements Rafraichissable {
Line 39... Line 35...
39
	
35
	
40
	private Mediateur mediateur = null ;
36
	private Mediateur mediateur = null;
41
	private Constantes i18nC = null ;
-
 
Line 42... Line 37...
42
 
37
	private Constantes i18nC = null;
43
	private Table table = null;
38
 
44
	private ListStore<Collection> store = null;
39
	private Grid<Collection> grille = null;
Line 45... Line 40...
45
	private TableBinder<Collection> binder = null;
40
	private ListStore<Collection> store = null;
46
 
41
 
47
	private Button modifier;
42
	private Button modifier;
Line -... Line 43...
-
 
43
	private Button supprimer;
48
	private Button supprimer;
44
	private Button ajouter;
Line 49... Line 45...
49
	private Button ajouter;
45
 
50
 
46
	public CollectionListeVue(Mediateur mediateurCourant) {
51
	public CollectionListeVue(Mediateur mediateurCourant) {
47
		mediateur = mediateurCourant;
52
		mediateur = mediateurCourant;
48
		i18nC = mediateur.i18nC;
Line 66... Line 62...
66
 
62
 
67
		modifier = new Button(i18nC.modifier());
63
		modifier = new Button(i18nC.modifier());
68
		modifier.setIcon(Images.ICONES.formModifier());
64
		modifier.setIcon(Images.ICONES.formModifier());
69
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
65
		modifier.addSelectionListener(new SelectionListener<ButtonEvent>() {
70
			public void componentSelected(ButtonEvent ce) {
66
			public void componentSelected(ButtonEvent ce) {
71
				mediateur.clicModifierCollection(binder.getSelection());
67
				mediateur.clicModifierCollection(grille.getSelectionModel().getSelectedItems());
72
			}
68
			}
73
		});
69
		});
Line 74... Line 70...
74
		toolBar.add(modifier);
70
		toolBar.add(modifier);
75
		
71
		
76
		supprimer = new Button(i18nC.supprimer());
72
		supprimer = new Button(i18nC.supprimer());
77
		supprimer.setIcon(Images.ICONES.supprimer());
73
		supprimer.setIcon(Images.ICONES.supprimer());
78
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
74
		supprimer.addSelectionListener(new SelectionListener<ButtonEvent>() {
79
			public void componentSelected(ButtonEvent ce) {
75
			public void componentSelected(ButtonEvent ce) {
80
				clicSupprimerCollection(binder.getSelection());
76
				clicSupprimerCollection(grille.getSelectionModel().getSelectedItems());
81
			}
-
 
82
		});
-
 
83
		if (!utilisateur.isIdentifie()) {
-
 
84
			supprimer.disable();
77
			}
Line 85... Line 78...
85
		}
78
		});
Line 86... Line 79...
86
		toolBar.add(supprimer);
79
		toolBar.add(supprimer);
87
 
-
 
88
		setTopComponent(toolBar);
80
 
89
 
81
		setTopComponent(toolBar);
90
		List<TableColumn> columns = new ArrayList<TableColumn>();
82
 
91
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
-
 
92
		columns.add(new TableColumn("nom", i18nC.nom(), .5f));
83
		List<ColumnConfig> colonnes = new ArrayList<ColumnConfig>();
93
		columns.add(new TableColumn("structure_nom", i18nC.structure(), .3f));
-
 
94
		columns.add(new TableColumn("structure_ville", i18nC.ville(), .2f));
84
		colonnes.add(new ColumnConfig("nom", i18nC.nom(), 300));
95
		
-
 
96
		columns.get(1).setHidden(true);
-
 
97
		
-
 
98
		TableColumnModel cm = new TableColumnModel(columns);
-
 
99
		table = new Table(cm);
-
 
Line -... Line 85...
-
 
85
		colonnes.add(new ColumnConfig("structure_nom", i18nC.structure(), 200));
-
 
86
		colonnes.add(new ColumnConfig("structure_ville", i18nC.ville(), 150));
-
 
87
		colonnes.get(1).setHidden(true);
-
 
88
		ColumnModel modeleDeColonne = new ColumnModel(colonnes);
-
 
89
		
-
 
90
		GridSelectionModel<Collection> modeleDeSelection = new GridSelectionModel<Collection>();
-
 
91
		modeleDeSelection.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
Line 100... Line 92...
100
		table.setSelectionMode(SelectionMode.MULTI);
92
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
101
		table.setBorders(false);
93
				Collection collectionSelectionnee = (Collection) event.getSelectedItem();
Line 102... Line 94...
102
		table.setStripeRows(true);
94
				clicListe(collectionSelectionnee);
103
		add(table);
95
			}
104
		
96
		});
105
		
97
		
106
		store = new ListStore<Collection>();
98
		store = new ListStore<Collection>();
107
		store.sort("nom", SortDir.ASC);
-
 
108
		
-
 
109
		binder = new TableBinder<Collection>(table, store);
-
 
110
		binder.addSelectionChangedListener(new SelectionChangedListener<Collection>() {
-
 
111
			public void selectionChanged(SelectionChangedEvent<Collection> event) {
99
		store.sort("nom", SortDir.ASC);
Line 112... Line 100...
112
				Collection m = (Collection) event.getSelectedItem();
100
		
113
				clicListe(m);
101
		grille = new Grid<Collection>(store, modeleDeColonne);
114
			}
102
		grille.setWidth("100%");
Line 126... Line 114...
126
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
114
	private void clicSupprimerCollection(List<Collection> collectionsASupprimer) {
127
		if (store.getCount() > 0) {
115
		if (store.getCount() > 0) {
128
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
116
			mediateur.clicSupprimerCollection(this, collectionsASupprimer);
129
		}
117
		}
130
	}
118
	}
-
 
119
	
-
 
120
	private void gererEtatActivationBouton() {
-
 
121
		int nbreElementDuMagazin = store.getCount();
-
 
122
		if (nbreElementDuMagazin == 0) {
-
 
123
			supprimer.disable();
-
 
124
			modifier.disable();
-
 
125
		} else if (nbreElementDuMagazin > 0) {
-
 
126
			modifier.enable();
-
 
127
			if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
-
 
128
				supprimer.enable();
-
 
129
			}
-
 
130
		}
-
 
131
	}
Line 131... Line 132...
131
 
132
 
132
	public void rafraichir(Object nouvelleDonnees) {
133
	public void rafraichir(Object nouvelleDonnees) {
133
		if (nouvelleDonnees instanceof CollectionListe) {
134
		if (nouvelleDonnees instanceof CollectionListe) {
134
			CollectionListe collections = (CollectionListe) nouvelleDonnees;
-
 
135
			setHeading(i18nC.collectionListeTitre());
135
			CollectionListe collections = (CollectionListe) nouvelleDonnees;
-
 
136
 
136
			
137
			if (collections != null) {			
137
			List<Collection> liste = (List<Collection>) collections.toList();
138
				List<Collection> liste = (List<Collection>) collections.toList();
138
			store.removeAll();
139
				store.removeAll();
139
			store.add(liste);
140
				store.add(liste);
140
 
141
	
141
			mediateur.actualiserPanneauCentral();
142
				mediateur.actualiserPanneauCentral();
142
			
143
				
143
			if (store.getCount() > 0) {
144
				if (store.getCount() > 0) {
-
 
145
					grille.getSelectionModel().select(0, false);
144
				table.getSelectionModel().select(0, 0, true);
146
				}
145
			}
147
			}
146
		} else if (nouvelleDonnees instanceof Information) {
148
		} else if (nouvelleDonnees instanceof Information) {
147
			Information info = (Information) nouvelleDonnees;
149
			Information info = (Information) nouvelleDonnees;
148
			if (info.getType().equals("suppression_collection")) {
150
			if (info.getType().equals("suppression_collection")) {
149
				// Affichage d'un message d'information 
-
 
150
				//GWT.log(info.toString(), null);
151
				// Affichage d'un message d'information 
Line 151... Line 152...
151
				Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
152
				Info.display(i18nC.suppressionCollection(), info.toString().replaceAll("\n", "<br />"));
152
 
153
 
153
				// Suppression des structures sélectionnées
154
				// Suppression des structures sélectionnées
154
				List<TableItem> selectionCollection = table.getSelectedItems();
155
				List<Collection> selectionCollection = grille.getSelectionModel().getSelectedItems();
155
				final int taille = selectionCollection.size();
156
				final int taille = selectionCollection.size();
156
				for (int i = 0; i < taille; i++) {
157
				for (int i = 0; i < taille; i++) {
157
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
158
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
Line 158... Line -...
158
					table.remove(selectionCollection.get(i));
-
 
159
				}
-
 
160
				
159
					store.remove(selectionCollection.get(i));
161
				// Désactivation des boutons si la liste est vide
-
 
162
				if (table.getItemCount() == 0) {  
-
 
163
					supprimer.disable();
160
				}
164
					modifier.disable();
-
 
165
				}
-
 
166
			} else if (info.getType().equals("maj_utilisateur")) {
-
 
167
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR_COURANT)).isIdentifie()) {
-
 
168
					if (table.getItemCount() != 0) {
-
 
169
						supprimer.enable();
161
				
170
					}
-
 
171
				} else {
162
				gererEtatActivationBouton();
172
					supprimer.disable();
163
			} else if (info.getType().equals("maj_utilisateur")) {
173
				}
164
				gererEtatActivationBouton();
174
			}
165
			}
175
		} else {
166
		} else {