Subversion Repositories eFlore/Applications.coel

Rev

Rev 60 | Rev 133 | 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.Iterator;
5
import java.util.List;
6
 
69 jpm 7
import org.tela_botanica.client.ComposantClass;
60 jpm 8
import org.tela_botanica.client.Mediateur;
9
import org.tela_botanica.client.RegistreId;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.modeles.Structure;
69 jpm 12
import org.tela_botanica.client.modeles.StructureListe;
60 jpm 13
 
14
import com.extjs.gxt.ui.client.Registry;
15
import com.extjs.gxt.ui.client.Style.SelectionMode;
16
import com.extjs.gxt.ui.client.binder.TableBinder;
69 jpm 17
import com.extjs.gxt.ui.client.event.ComponentEvent;
60 jpm 18
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
19
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
69 jpm 20
import com.extjs.gxt.ui.client.event.SelectionListener;
60 jpm 21
import com.extjs.gxt.ui.client.store.ListStore;
22
import com.extjs.gxt.ui.client.widget.ContentPanel;
23
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
24
import com.extjs.gxt.ui.client.widget.table.Table;
25
import com.extjs.gxt.ui.client.widget.table.TableColumn;
26
import com.extjs.gxt.ui.client.widget.table.TableColumnModel;
27
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
28
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
29
import com.google.gwt.user.client.Window;
30
 
31
public class StructureListePanneauVue extends ContentPanel implements Rafraichissable {
32
 
33
	private Mediateur coelMediateur = null ;
34
	private Table table = null;
35
	private ListStore<Structure> store = null;
36
	private TableBinder<Structure> binder = null;
37
 
38
	public StructureListePanneauVue() {
39
		coelMediateur = Registry.get(RegistreId.MEDIATEUR);
40
 
41
		ToolBar toolBar = new ToolBar();
42
		TextToolItem ajouter = new TextToolItem("Ajouter");
69 jpm 43
		ajouter.setIconStyle(ComposantClass.ICONE_AJOUTER);
44
		ajouter.addSelectionListener(new SelectionListener<ComponentEvent>() {
45
			public void componentSelected(ComponentEvent ce) {
46
				coelMediateur.clicAjouterStructure();
47
			}
48
		});
60 jpm 49
		toolBar.add(ajouter);
50
 
51
		TextToolItem modifier = new TextToolItem("Modifier");
69 jpm 52
		modifier.setIconStyle(ComposantClass.ICONE_MODIFIER);
60 jpm 53
		toolBar.add(modifier);
54
 
55
		TextToolItem supprimer = new TextToolItem("Supprimer");
69 jpm 56
		supprimer.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
60 jpm 57
		toolBar.add(supprimer);
58
 
59
		setTopComponent(toolBar);
60
 
61
		List<TableColumn> columns = new ArrayList<TableColumn>();
62
		// ATTENTION : les noms des colonnes doivent correspondrent aux noms variables de la classe utilisée dans la liste
63
		columns.add(new TableColumn("ville", "Ville", .3f));
64
		columns.add(new TableColumn("nom", "Nom", .7f));
65
 
66
		TableColumnModel cm = new TableColumnModel(columns);
67
 
68
		table = new Table(cm);
69
		table.setSelectionMode(SelectionMode.MULTI);
70
		table.setBorders(false);
71
 
72
		add(table);
73
 
74
		store = new ListStore<Structure>();
75
 
76
		binder = new TableBinder<Structure>(table, store);
77
		binder.setAutoSelect(true);
78
		binder.addSelectionChangedListener(new SelectionChangedListener<Structure>() {
79
			public void selectionChanged(SelectionChangedEvent<Structure> event) {
80
				Structure m = (Structure) event.getSelectedItem();
81
				clicListe(m);
82
			}
83
		});
84
 
85
		setLayout(new FitLayout());
86
	}
87
 
88
	public ListStore<Structure> getStore() {
89
		return store;
90
	}
91
 
92
	public TableBinder<Structure> getBinder() {
93
		return binder;
94
	}
95
 
96
	private void clicListe(Structure institution) {
97
		coelMediateur.clicListeInstitution(institution);
98
	}
99
 
100
	public void rafraichir(Object nouvelleDonnees) {
69 jpm 101
		if (nouvelleDonnees instanceof StructureListe) {
102
			StructureListe listeInstitutions = (StructureListe) nouvelleDonnees;
60 jpm 103
			setHeading("Institutions");
104
 
105
			List<Structure> liste = new ArrayList<Structure>();
106
			for (Iterator<String> it = listeInstitutions.keySet().iterator(); it.hasNext();) {
107
				liste.add(listeInstitutions.get(it.next()));
108
			}
109
 
110
			store.removeAll();
111
			store.add((List<Structure>) liste);
112
 
113
			// Test pour savoir si la liste contient des éléments
114
			if (listeInstitutions.size() > 0) {
115
				binder.setSelection((Structure) listeInstitutions.get(0));
116
			}
117
		}
118
 
119
	}
120
}