Subversion Repositories eFlore/Applications.coel

Rev

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

Rev 155 Rev 156
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.Iterator;
4
import java.util.Iterator;
5
import java.util.List;
5
import java.util.List;
6
 
6
 
7
import org.tela_botanica.client.ComposantClass;
7
import org.tela_botanica.client.ComposantClass;
8
import org.tela_botanica.client.Mediateur;
8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
9
import org.tela_botanica.client.RegistreId;
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
 
15
 
15
import com.extjs.gxt.ui.client.Registry;
16
import com.extjs.gxt.ui.client.Registry;
16
import com.extjs.gxt.ui.client.Style.SelectionMode;
17
import com.extjs.gxt.ui.client.Style.SelectionMode;
17
import com.extjs.gxt.ui.client.binder.TableBinder;
18
import com.extjs.gxt.ui.client.binder.TableBinder;
18
import com.extjs.gxt.ui.client.event.ComponentEvent;
19
import com.extjs.gxt.ui.client.event.ComponentEvent;
19
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
20
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
20
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
21
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
21
import com.extjs.gxt.ui.client.event.SelectionListener;
22
import com.extjs.gxt.ui.client.event.SelectionListener;
22
import com.extjs.gxt.ui.client.store.ListStore;
23
import com.extjs.gxt.ui.client.store.ListStore;
23
import com.extjs.gxt.ui.client.widget.ContentPanel;
24
import com.extjs.gxt.ui.client.widget.ContentPanel;
24
import com.extjs.gxt.ui.client.widget.Info;
25
import com.extjs.gxt.ui.client.widget.Info;
25
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
26
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
26
import com.extjs.gxt.ui.client.widget.table.Table;
27
import com.extjs.gxt.ui.client.widget.table.Table;
27
import com.extjs.gxt.ui.client.widget.table.TableColumn;
28
import com.extjs.gxt.ui.client.widget.table.TableColumn;
28
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
29
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
29
import com.extjs.gxt.ui.client.widget.table.TableItem;
30
import com.extjs.gxt.ui.client.widget.table.TableItem;
30
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
31
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
31
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
32
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
32
import com.google.gwt.core.client.GWT;
33
import com.google.gwt.core.client.GWT;
33
import com.google.gwt.user.client.Window;
34
import com.google.gwt.user.client.Window;
34
 
35
 
35
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
36
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
36
	
37
	
37
	private Rafraichissable structureListePanneauVue = null ;
38
	private Rafraichissable structureListePanneauVue = null ;
38
	private Mediateur coelMediateur = null ;
39
	private Mediateur mediateur = null ;
39
	private Table table = null;
40
	private Table table = null;
40
	private ListStore<Structure> store = null;
41
	private ListStore<Structure> store = null;
41
	private TableBinder<Structure> binder = null;
42
	private TableBinder<Structure> binder = null;
42
	private TextToolItem modifier;
43
	private TextToolItem modifier;
43
	private TextToolItem supprimer;
44
	private TextToolItem supprimer;
44
	private TextToolItem ajouter;
45
	private TextToolItem ajouter;
45
 
46
 
46
	public StructureListePanneauVue() {
47
	public StructureListePanneauVue() {
-
 
48
		Utilisateur utilisateur = (Utilisateur) Registry.get(RegistreId.UTILISATEUR);
47
		coelMediateur = Registry.get(RegistreId.MEDIATEUR);
49
		mediateur = Registry.get(RegistreId.MEDIATEUR);
48
		structureListePanneauVue = this;
50
		structureListePanneauVue = this;
49
		
51
		
50
		ToolBar toolBar = new ToolBar();
52
		ToolBar toolBar = new ToolBar();
51
		ajouter = new TextToolItem("Ajouter");
53
		ajouter = new TextToolItem("Ajouter");
52
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
54
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
53
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
55
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {  
54
			public void componentSelected(ComponentEvent ce) {  
56
			public void componentSelected(ComponentEvent ce) {  
55
				coelMediateur.clicAjouterStructure();
57
				mediateur.clicAjouterStructure();
56
			}
58
			}
57
		});
59
		});
58
		toolBar.add(ajouter);
60
		toolBar.add(ajouter);
59
 
61
 
60
		modifier = new TextToolItem("Modifier");
62
		modifier = new TextToolItem("Modifier");
61
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
63
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
-
 
64
		modifier.addSelectionListener(new SelectionListener<ComponentEvent>() {
-
 
65
			public void componentSelected(ComponentEvent ce) {
-
 
66
				mediateur.clicModifierStructure(binder.getSelection());
-
 
67
			}
-
 
68
		});
62
		toolBar.add(modifier);
69
		toolBar.add(modifier);
63
		
70
		
64
		supprimer = new TextToolItem("Supprimer");
71
		supprimer = new TextToolItem("Supprimer");
65
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
72
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
66
		supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
73
		supprimer.addSelectionListener(new SelectionListener<ComponentEvent>() {
67
			public void componentSelected(ComponentEvent ce) {
74
			public void componentSelected(ComponentEvent ce) {
68
				coelMediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
75
				mediateur.clicSupprimerStructure(structureListePanneauVue, binder.getSelection());
69
			}
76
			}
70
		});
77
		});
-
 
78
		if (!utilisateur.isIdentifie()) {
-
 
79
			supprimer.disable();
-
 
80
		}
71
		toolBar.add(supprimer);
81
		toolBar.add(supprimer);
72
 
82
 
73
		setTopComponent(toolBar);
83
		setTopComponent(toolBar);
74
 
84
 
75
		List<TableColumn> columns = new ArrayList<TableColumn>();
85
		List<TableColumn> columns = new ArrayList<TableColumn>();
76
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
86
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
77
		columns.add(new TableColumn("ville", "Ville", .3f));
87
		columns.add(new TableColumn("ville", "Ville", .3f));
78
		columns.add(new TableColumn("nom", "Nom", .7f));
88
		columns.add(new TableColumn("nom", "Nom", .7f));
79
		
89
		
80
		TableColumnModel cm = new TableColumnModel(columns);
90
		TableColumnModel cm = new TableColumnModel(columns);
81
 
91
 
82
		table = new Table(cm);
92
		table = new Table(cm);
83
		table.setSelectionMode(SelectionMode.MULTI);
93
		table.setSelectionMode(SelectionMode.MULTI);
84
		table.setBorders(false);
94
		table.setBorders(false);
85
 
95
 
86
		add(table);
96
		add(table);
87
 
97
 
88
		store = new ListStore<Structure>();
98
		store = new ListStore<Structure>();
89
 
99
 
90
		binder = new TableBinder<Structure>(table, store);
100
		binder = new TableBinder<Structure>(table, store);
91
		binder.setAutoSelect(true);
101
		binder.setAutoSelect(true);
92
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
102
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
93
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
103
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
94
				Structure m = (Structure) event.getSelectedItem();
104
				Structure m = (Structure) event.getSelectedItem();
95
				clicListe(m);
105
				clicListe(m);
96
			}
106
			}
97
		});
107
		});
98
 
108
 
99
		setLayout(new FitLayout());
109
		setLayout(new FitLayout());
100
	}
110
	}
101
 
111
 
102
	public ListStore<Structure> getStore() {
112
	public ListStore<Structure> getStore() {
103
		return store;
113
		return store;
104
	}
114
	}
105
 
115
 
106
	public TableBinder<Structure> getBinder() {
116
	public TableBinder<Structure> getBinder() {
107
		return binder;
117
		return binder;
108
	}
118
	}
109
 
119
 
110
	private void clicListe(Structure institution) {
120
	private void clicListe(Structure institution) {
111
		coelMediateur.clicListeInstitution(institution);
121
		mediateur.clicListeInstitution(institution);
112
	}
122
	}
113
 
123
 
114
	public void rafraichir(Object nouvelleDonnees) {
124
	public void rafraichir(Object nouvelleDonnees) {
115
		if (nouvelleDonnees instanceof StructureListe) {
125
		if (nouvelleDonnees instanceof StructureListe) {
116
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
126
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
117
			setHeading("Institutions");
127
			setHeading("Institutions");
118
 
128
 
119
			List<Structure> liste = new ArrayList<Structure>();
129
			List<Structure> liste = new ArrayList<Structure>();
120
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
130
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
121
				liste.add(listeInstitutions.get(it.next()));
131
				liste.add(listeInstitutions.get(it.next()));
122
			}
132
			}
123
			
133
			
124
			store.removeAll();
134
			store.removeAll();
125
			store.add((List<Structure>) liste);
135
			store.add((List<Structure>) liste);
126
			
136
			
127
			// Test pour savoir si la liste contient des éléments
137
			// Test pour savoir si la liste contient des éléments
128
			if (listeInstitutions.size() > 0) {
138
			if (listeInstitutions.size() > 0) {
129
				binder.setSelection((Structure) listeInstitutions.get(0));
139
				binder.setSelection((Structure) listeInstitutions.get(0));
130
			}
140
			}
131
		} else if (nouvelleDonnees instanceof Information) {
141
		} else if (nouvelleDonnees instanceof Information) {
132
			Information info = (Information) nouvelleDonnees;
142
			Information info = (Information) nouvelleDonnees;
133
			if (info.getType().equals("suppression_structure")) {
143
			if (info.getType().equals("suppression_structure")) {
134
				// Affichage d'un message d'information 
144
				// Affichage d'un message d'information 
135
				//GWT.log(info.toString(), null);
145
				//GWT.log(info.toString(), null);
136
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
146
				Info.display("Suppression d'une Institution", info.toString().replaceAll("\n", "<br />"));
137
 
147
 
138
				// Suppression des structures sélectionnées
148
				// Suppression des structures sélectionnées
139
				List<TableItem> selectionStructure = table.getSelectedItems();
149
				List<TableItem> selectionStructure = table.getSelectedItems();
140
				final int taille = selectionStructure.size();
150
				final int taille = selectionStructure.size();
141
				for (int i = 0; i < taille; i++) {
151
				for (int i = 0; i < taille; i++) {
142
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
152
					//GWT.log("INDEX :"+table.indexOf(selectionStructure.get(i)), null);
143
					table.remove(selectionStructure.get(i));
153
					table.remove(selectionStructure.get(i));
144
				}
154
				}
145
				
155
				
146
				// Désactivation des boutons si la liste est vide
156
				// Désactivation des boutons si la liste est vide
147
				if (table.getItemCount() == 0) {  
157
				if (table.getItemCount() == 0) {  
148
					supprimer.disable();
158
					supprimer.disable();
149
					modifier.disable();
159
					modifier.disable();
150
				}
160
				}
-
 
161
			} else if (info.getType().equals("maj_utilisateur")) {
-
 
162
				if (((Utilisateur) Registry.get(RegistreId.UTILISATEUR)).isIdentifie()) {
-
 
163
					if (table.getItemCount() != 0) {
-
 
164
						supprimer.enable();
-
 
165
					}
-
 
166
				} else {
-
 
167
					supprimer.disable();
-
 
168
				}
151
			}
169
			}
-
 
170
		} else {
-
 
171
			GWT.log("Ce type d'objet n'est pas pris en compte par la méthode rafraichir de la classe EntetePanneauVue", null);
152
		}
172
		}
-
 
173
		layout();
153
	}
174
	}
154
}
175
}